PHP product analytics installation

Add the following to composer.json:

JSON
{
"require": {
"posthog/posthog-php": "3.0.*"
}
}

And then install the dependencies with the command:

Terminal
composer install

In your app, set your project API key before making any calls.

PHP
PostHog\PostHog::init("<ph_project_api_key>",
array('host' => 'https://us.i.posthog.com')
);

Note: As a rule of thumb, we do not recommend having API keys in plaintext. Setting it as an environment variable is best.

You can find your project API key and instance address in the project settings page in PostHog.

Community questions

Was this page useful?

Questions about this page? or post a community question.