sanderverkuil / posthog-symfony
Symfony integration for PostHog (https://posthog.com)
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.0
- jean85/pretty-package-versions: ^1.0|^2.0
- posthog/posthog-php: ^3.0
- symfony/config: ^6.0|^7.0
- symfony/dependency-injection: ^6.0|^7.0
- symfony/event-dispatcher: ^6.0|^7.0
- symfony/http-kernel: ^6.0|^7.0
- symfony/polyfill-php80: ^1.28
- symfony/security-core: ^6.0|^7.0
- symfony/security-http: ^6.0|^7.0
Requires (Dev)
- ergebnis/composer-normalize: ^1.0|^2.0
- friendsofphp/php-cs-fixer: ^3.35
- monolog/monolog: ^1.0|^2.0|^3.4
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^1.10
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-symfony: ^1.3
- phpunit/phpunit: ^8.5.14|^9.3.9|^10.4
- symfony/browser-kit: ^6.0|^7.0
- symfony/cache: ^6.0|^7.0
- symfony/console: ^6.0|^7.0
- symfony/dom-crawler: ^6.0|^7.0
- symfony/framework-bundle: ^6.0|^7.0
- symfony/http-client: ^6.0|^7.0
- symfony/monolog-bundle: ^3.4
- symfony/phpunit-bridge: ^6.0|^7.0
- symfony/process: ^6.0|^7.0
- symfony/yaml: ^6.0|^7.0
- vimeo/psalm: ^5.15
This package is auto-updated.
Last update: 2025-03-20 16:13:18 UTC
README
Important
This repository and project are not backed by PostHog.
Unofficial PostHog SDK for Symfony
This is the unofficial Symfony SDK for PostHog.
Getting Started
Using this posthog-symfony
SDK provides you with the following benefits:
- Quickly integrate and configure PostHog for your Symfony app
- Out of the box, each event will contain the following data by default
- The currently authenticated user
- The Symfony environment
Install
To install the SDK you will need to be using Composer in your project. To install it please see the docs.
composer require sanderverkuil/posthog-symfony
Enable the Bundle
If you installed the package using the Flex recipe, the bundle will be automatically enabled. Otherwise, enable it by adding it to the list
of registered bundles in the Kernel.php
file of your project:
class AppKernel extends \Symfony\Component\HttpKernel\Kernel { public function registerBundles(): array { return [ // ... new \PostHog\PostHogBundle\PostHogBundle(), ]; } // ... }
The bundle will be enabled in all environments by default. To enable event reporting, you'll need to add a key (see the next step).
Configure
Add the PostHog key of your project.
Add the key to your config/packages/posthog.yaml
file.
Keep in mind that by leaving the key
value empty (or undeclared), you will disable the PostHog integration:.
post_hog: key: "<ph_project_api_key>" host: "https://app.posthog.com/" # Or https://eu.posthog.com/ for EU
Optional: use custom HTTP factory/transport
This uses HTTPlug to remain transport-agnostic, you need to install two packages that provide
php-http/async-client-implementation
and psr/http-message-implementation
.
The suggested packages are:
- the Symfony HTTP Client (
symfony/http-client
) - Guzzle's message factory (
http-interop/http-factory-guzzle
)
Maintained versions
- 0.x is actively maintained and developed on the master branch, and uses PostHog SDK 3.0;
Contributing to the SDK
Please refer to CONTRIBUTING.md.
License
Licensed under the MIT license, see LICENSE
Attributions
- I would like to thank @getsentry for inspiration on how to set up a symfony bundle with regards to general things.
- I would like to thank @posthog for their product.