Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

3.6 KB
Raw Blame
import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'

import { StepDefinition } from '../steps'

export const getLaravelInstallSteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {
    const { CodeBlock, Markdown, dedent } = ctx

    return [
        {
            title: 'Install the package',
            badge: 'required',
            content: (
                <>
                    <Markdown>Install the PostHog PHP library using Composer:</Markdown>
                    <CodeBlock
                        blocks={[
                            {
                                language: 'bash',
                                file: 'Terminal',
                                code: dedent`
                                composer require posthog/posthog-php
                            `,
                            },
                        ]}
                    />
                </>
            ),
        },
        {
            title: 'Configure PostHog',
            badge: 'required',
            content: (
                <>
                    <Markdown>
                        Initialize PostHog in the `boot` method of `app/Providers/AppServiceProvider.php`:
                    </Markdown>
                    <CodeBlock
                        blocks={[
                            {
                                language: 'php',
                                file: 'app/Providers/AppServiceProvider.php',
                                code: dedent`
                                <?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' => '<ph_client_api_host>'
                                            ]
                                        );
                                    }
                                }
                            `,
                            },
                        ]}
                    />
                </>
            ),
        },
    ]
}

export const getLaravelEventStep = (ctx: OnboardingComponentsContext): StepDefinition => {
    const { CodeBlock, Markdown, dedent } = ctx

    return {
        title: 'Send events',
        badge: 'optional',
        content: (
            <>
                <Markdown>Capture custom events using the PostHog client:</Markdown>
                <CodeBlock
                    blocks={[
                        {
                            language: 'php',
                            file: 'PHP',
                            code: dedent`
                                PostHog::capture([
                                    'distinctId' => 'test-user',
                                    'event' => 'test-event',
                                ]);
                            `,
                        },
                    ]}
                />
            </>
        ),
    }
}

export const getLaravelSteps = (ctx: OnboardingComponentsContext): StepDefinition[] => [
    ...getLaravelInstallSteps(ctx),
    getLaravelEventStep(ctx),
]

export const LaravelInstallation = createInstallation(getLaravelSteps)