PHP code example of qodenl / laravel-posthog

1. Go to this page and download the library: Download qodenl/laravel-posthog 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/ */

    

qodenl / laravel-posthog example snippets


use QodeNL\LaravelPosthog\Facades\Posthog;

Posthog::capture('event name', ['property' => 'value']);

public $posthogAttributes = [
    'first_name',
    'last_name',
];

use QodeNL\LaravelPosthog\Facades\Posthog;

Posthog::identify('[email protected]', ['first_name' => 'John', 'last_name' => 'Doe']);

Posthog::alias('Session ID here');

use QodeNL\LaravelPosthog\Facades\Posthog;

Posthog::setGroup('company', 'company_id_5');

Posthog::capture('page_view', ['url' => '/dashboard']); // 

Posthog::setGroup('company', 'company_id_5')->setGroup('project', 'project_id_8');

Posthog::updateOrCreateGroup('company', 'company_id_5', ['name' => 'Acme Inc', 'plan' => 'enterprise']);

Posthog::setGroup('company', 'company_id_5', ['name' => 'Acme Inc', 'plan' => 'enterprise']);

use QodeNL\LaravelPosthog\Facades\Posthog;

try {
    // ...
} catch (Throwable $e) {
    Posthog::captureException($e, ['order_id' => $order->id]);
}

    'stores' => [
        'posthog' => [
            'driver' => 'posthog',
        ],
    ],

Laravel\Pennant\Feature::active('myFeatureFlagKey'); // true

use QodeNL\LaravelPosthog\Facades\Posthog;

Posthog::getAllFlags();

use QodeNL\LaravelPosthog\Facades\Posthog;

Posthog::isFeatureEnabled('myFeatureFlagKey');

use QodeNL\LaravelPosthog\Facades\Posthog;

Posthog::getFeatureFlag('myFeatureFlagKey');

use QodeNL\LaravelPosthog\Facades\Posthog;

Posthog::getFeatureFlagPayload('myFeatureFlagKey'); // ['color' => 'blue']

'options' => [
    'verify_batch_events_request' => false,
],

use QodeNL\LaravelPosthog\Facades\Posthog;

public function boot(): void
{
    Posthog::resolveDistinctIdUsing(function () {
        return auth()->id() ?? session()->getId();
    });
}

use QodeNL\LaravelPosthog\Facades\Posthog;

public function boot(): void
{
    Posthog::resolveIpUsing(function () {
        return request()->header('CF-Connecting-IP') ?? request()->ip();
    });
}
bash
php artisan vendor:publish --provider="QodeNL\LaravelPosthog\PosthogServiceProvider"  
bash
POSTHOG_ERROR_TRACKING_ENABLED=true
text
PENNANT_STORE=posthog