News

Manage Events, Feature Flags, and More with PostHog for Laravel

Published
Manage Events, Feature Flags, and More with PostHog for Laravel image

Laravel PostHog is a package integrating PostHog—a platform to analyze, test, observe, and deploy new features—with Laravel. It builds on top of the posthog-php package, offering a Facade and simplified configuration in your Laravel app:

use QodeNL\LaravelPosthog\Facades\Posthog;
 
Posthog::capture('event name', ['property' => 'value']);

PostHog has a variety of features that you can use, and the PHP/Laravel package specifically provides the following features that you can integrate:

  • Event capture
  • User identification
  • Feature flags
  • Group analytics
  • Sending pageviews

PostHog doesn't have a Laravel Pennant feature flag driver, but you can use PostHog's feature flags directly via the package:

use QodeNL\LaravelPosthog\Facades\Posthog;
 
Posthog::getAllFlags();
Posthog::isFeatureEnabled('myFeatureFlagKey');
 
// Return true/false/payload (if set)
Posthog::getFeatureFlag('myFeatureFlagKey');

You can learn more about this package, get full installation instructions, and view the source code on GitHub. The PostHog documentation has more examples of using this package with Laravel and PHP.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Filed in

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article