PHP code example of jeffersongoncalves / laravel-posthog
1. Go to this page and download the library: Download jeffersongoncalves/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/ */
jeffersongoncalves / laravel-posthog example snippets
PostHog::identify('user_123', [
'email' => '[email protected]',
'plan' => 'pro',
]);
// Merge an anonymous session into an identified person
PostHog::alias('user_123', 'anon_abc');
// Every flag evaluated for this person
$flags = PostHog::featureFlags('user_123');
// A single flag: false when off, true when on, the variant key when multivariate
$variant = PostHog::featureFlag('new-pricing', 'user_123');
// Simple boolean check (a variant counts as enabled)
if (PostHog::isFeatureEnabled('new-pricing', 'user_123')) {
// Show new pricing
}
$result = PostHog::query(
'SELECT event, count() FROM events WHERE timestamp > now() - interval 7 day GROUP BY event ORDER BY count() DESC LIMIT 10'
);