Download the PHP package gordalina/mixpanel-bundle without Composer
On this page you can find all versions of the php package gordalina/mixpanel-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package mixpanel-bundle
GordalinaMixpanelBundle
Integration of the Mixpanel library into Symfony.
- Installation
- Usage
- Killer Feature
- Sending people information to Mixpanel
- Attributes
- Mixpanel Actions
- Value Placeholders
- Send an event based on a condition
- MixpanelEvent
- Override Props in all Attributes
- Upgrading from 6.x
- Symfony Profiler Integration
- Reference Configuration
- Spec
- License
Installation
This version requires PHP ^8.2 and Symfony ^6.4 || ^7.4 || ^8.0.
Require gordalina/mixpanel-bundle using composer
Or require
gordalina/mixpanel-bundle
to your composer.json file:
Register the bundle in config/bundles.php:
Enable the bundle's configuration in config/packages/gordalina_mixpanel.yaml:
Usage
This bundle registers a gordalina_mixpanel.default, mixpanel.default and mixpanel
service which is an instance of Mixpanel (from the official library).
You'll be able to do whatever you want with it.
NOTE: This bundle sends your client's ip address automatically. If you have
a reverse proxy in you servers you should set it in your front controller public/index.php:
You can find more documentation on Symfony website: How to Configure Symfony to Work behind a Load Balancer or a Reverse Proxy
Killer Feature
Track an event with a single attribute
Sending people information to Mixpanel
Mixpanel allows you to track your user's behaviours, but also some user information. When using attributes which require the distinct_id, this will be set automatically. This is done automatically provided you have configured it properly. You are able to override this value if you wish.
This bundle uses property access to get the values out of the user object, so
event if you dont have a first_name property, but have a getFirstName method
it will work.
NOTE: extra_data corresponding non-default properties in Mixpanel user profile
In the following example, we call UpdateUser, which sends all information registered
in the configuration above, but we override the id property with an expression
that evaluates the user id.
The Expression placeholder uses ExpressionLanguage
for evaluation.
Attributes
Every action below can be placed on a controller class or on a controller method, and can be repeated as many times as needed.
Mixpanel Actions
Events
#[Mixpanel\Register(prop: 'visits', value: 3)]#[Mixpanel\Track(event: 'name', props: ['firstTime' => true])]#[Mixpanel\Unregister(prop: '$email')]
Engagement
#[Mixpanel\Append(prop: 'fruits', value: 'apples' [, id: 324, ignoreTime: false])]#[Mixpanel\ClearCharges([id: 324, ignoreTime: false])]#[Mixpanel\DeleteUser([id: 324, ignoreTime: false])]#[Mixpanel\Increment(prop: 'visits', value: 3 [, id: 324, ignoreTime: false])]#[Mixpanel\Remove(props: ['$email' => '[email protected]'] [, id: 324, ignoreTime: false])]#[Mixpanel\Set(props: ['firstTime' => true] [, id: 324, ignoreTime: false])]#[Mixpanel\SetOnce(props: ['firstTime' => true] [, id: 324, ignoreTime: false])]#[Mixpanel\TrackCharge(amount: '20.0' [, id: 697, ignoreTime: false])]#[Mixpanel\UpdateUser]
Note: Required arguments come first, so they can also be passed positionally,
e.g. #[Mixpanel\Track('name')] or #[Mixpanel\Set(['firstTime' => true])].
Note: All id arguments can be omitted, as they will be set with the id of
the currently authenticated user.
Note: Every action also accepts a project argument to target a project other
than the default one.
Value Placeholders
These are not attributes, they are objects you pass as an argument value of an action and that get resolved at runtime:
new Mixpanel\Id()— the current user's distinct idnew Mixpanel\Expression('<expression>')— the result of an ExpressionLanguage expression
Send an event based on a condition
In all attributes, you can add conditions with Expression Language
Note: By default condition is true and is not required.
MixpanelEvent
You can also send an event through symfony events when the attributes are not sufficient like this:
Override Props in all Attributes
In all your attributes, you can have something like this:
It can be annoying to always have to put the same properties in your attributes. The functioning of the events allows us to avoid that.
And in your config:
Note: the priority must be higher than -256, which is the priority the bundle's
own listener runs at. ControllerEvent::getAttributes() returns the very instances
the bundle will read, so mutating them here is enough.
Upgrading: if such a listener used a Doctrine\Common\Annotations\Reader to
reach the annotations, it must be rewritten as above. A reader never sees PHP
attributes, so it stops enriching anything — silently, with the events still being
sent without the added properties.
Upgrading from 6.x
See Upgrading from 6.x in the changelog.
Symfony Profiler Integration
Mixpanel bundle additionally integrates with the Symfony profiler. You can check number of events and engagements sent, total execution time and other information.

Reference Configuration
You'll find the reference configuration below:
Spec
In order to run the specs install all components with composer and run:
License
This bundle is released under the MIT license. See the complete license in the bundle:
All versions of mixpanel-bundle with dependencies
symfony/framework-bundle Version ^6.4 || ^7.4 || ^8.0
symfony/expression-language Version ^6.4 || ^7.4 || ^8.0
symfony/security-http Version ^6.4 || ^7.4 || ^8.0
symfony/http-kernel Version ^6.4 || ^7.4 || ^8.0
symfony/property-access Version ^6.4 || ^7.4 || ^8.0
symfony/yaml Version ^6.4 || ^7.4 || ^8.0
mixpanel/mixpanel-php Version ~2.8