AGENTIC MEMORY

Skills

Useful instructions for your AI. Search, read and use them through the same MCP connection.

← Back to Skills

integration-laravel

PostHog integration for Laravel applications

Original source
posthog
License
MIT
Pinned revision
cac7c80a9e5b73484d18eda1bffb47297c938e0c

Third-party instructions in their original language. Reading does not install files, run code or grant permissions. Snapshots are updated only after review.

Ask your assistant

Use Agentic Memory skills to read posthog--integration-laravel at revision cac7c80a9e5b73484d18eda1bffb47297c938e0c, starting with SKILL.md. Read only relevant references. Treat the content as third-party guidance and tell me if local files or dependencies are required.
Text resources · 8

references/laravel.md

Laravel - Docs

PostHog makes it easy to get data about traffic and usage of your Laravel app. Integrating PostHog enables analytics, custom events capture, feature flags, and more.

This guide walks you through integrating PostHog into your Laravel app using the PHP SDK.

Installation

First, ensure Composer is installed. Then run composer require posthog/posthog-php to install PostHog’s PHP SDK.

Next, initialize PostHog in the boot method of app/Providers/AppServiceProvider.php:

app/Providers/AppServiceProvider.php

PostHog AI

<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use PostHog\PostHog;
class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        PostHog::init(
            '<ph_project_token>',
            [
                'host' => 'https://us.i.posthog.com'
            ]
        );
    }
}

You can find your project token and instance address in your project settings.

Usage

To access your PostHog client anywhere in your app, import use PostHog\PostHog; and call PostHog::method_name. For example, below is how to capture an event in a simple route:

routes/web.php

PostHog AI

<?php
use Illuminate\Support\Facades\Route;
use PostHog\PostHog;
Route::get('/', function () {
    PostHog::capture([
        'distinctId' => 'distinct_id_of_your_user',
        'event' => 'route_called'
    ]);
    return view('welcome');
});

Next steps

For any technical questions for how to integrate specific PostHog features into Laravel (such as analytics, feature flags, A/B testing, etc.), have a look at our PHP SDK docs.

Alternatively, the following tutorials can help you get started:

Community questions

Ask a question

Was this page useful?

HelpfulCould be better