PHP code example of temperbit / larahog

1. Go to this page and download the library: Download temperbit/larahog library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

temperbit / larahog example snippets


// config/larahog.php
'connections' => [
    'default' => [
        'project_token' => env('POSTHOG_PROJECT_TOKEN'),
        // ...
    ],
    'marketing' => [
        'project_token' => env('POSTHOG_MARKETING_TOKEN'),
        // ...
    ],
],

LaraHog::connection('marketing')->capture('user-123', 'campaign_clicked');

use TemperBit\LaraHog\Facades\LaraHog;

// Basic event
LaraHog::capture('user-123', 'page_viewed');

// With properties
LaraHog::capture('user-123', 'purchase_completed', [
    'amount' => 49.99,
    'currency' => 'USD',
]);

// With group association
LaraHog::capture('user-123', 'report_exported', [], [
    'company' => 'company-456',
]);

// Anonymous event
LaraHog::capture(null, 'landing_page_viewed');

// Historical event time (DateTimeInterface, Unix timestamp, or ISO 8601 string)
LaraHog::capture(
    'user-123',
    'package_downloaded',
    timestamp: $downloadedAt,
);


LaraHog::captureBatch([
    [
        'distinctId' => 'user-123',
        'event' => 'package_downloaded',
        'properties' => ['package' => 'agent'],
        'timestamp' => $firstDownloadAt,
    ],
    [
        'distinctId' => 'user-456',
        'event' => 'package_downloaded',
        'properties' => ['package' => 'sensor'],
        'timestamp' => $secondDownloadAt,
    ],
], historicalMigration: true);

LaraHog::identify('user-123', [
    'name' => 'Jane Doe',
    'email' => '[email protected]',
    'plan' => 'enterprise',
]);

LaraHog::identifyBatch([
    ['distinctId' => 'user-123', 'properties' => ['name' => 'Jane Doe']],
    ['distinctId' => 'user-456', 'properties' => ['name' => 'John Doe']],
]);

LaraHog::alias('user-123', 'anonymous-session-abc');

LaraHog::groupIdentify('company', 'company-456', [
    'name' => 'Acme Corp',
    'industry' => 'SaaS',
]);

LaraHog::groupIdentifyBatch([
    ['groupType' => 'company', 'groupKey' => 'company-456', 'properties' => ['name' => 'Acme Corp']],
    ['groupType' => 'company', 'groupKey' => 'company-789', 'properties' => ['name' => 'Globex Corp']],
]);

LaraHog::flush();    // Flush the default connection
LaraHog::flushAll(); // Flush all connections

if (LaraHog::isEnabled()) {
    // ...
}
bash
php artisan vendor:publish --tag="larahog-config"
bash
php artisan larahog:status
php artisan larahog:status --connection=marketing