PHP product analytics installation

  1. Install the package

    Required

    Install the PostHog PHP library using Composer:

    Terminal
    composer require posthog/posthog-php
  2. Configure PostHog

    Required

    Initialize the PostHog client with your API key and host:

    PHP
    PostHog\PostHog::init(
    '<ph_project_api_key>',
    ['host' => 'https://us.i.posthog.com']
    );
  3. Send events

    Optional

    Once installed, you can manually send events to test your integration:

    PHP
    PostHog::capture([
    'distinctId' => 'test-user',
    'event' => 'test-event',
    ]);

    By default, for backwards compatibility reasons, events are sent with person profile processing enabled. This means a person profile will be created for each user who triggers an event.

    If you want to disable person profile processing for certain events, send the event with the following property:

    PHP
    '$process_person_profile' => false
  4. Next steps

    Recommended
    ResourceDescription
    Capturing eventsLearn how to capture custom events beyond autocapture
    Identifying usersAssociate events with specific users
    Creating insightsBuild trends, funnels, and retention charts
    Group analyticsTrack events at the company or account level

Community questions

Was this page useful?

Questions about this page? or post a community question.