mixpanel/mixpanel-php
Official Mixpanel PHP library for tracking events and updating user profiles. Send server-side analytics data (events, people, groups) to Mixpanel using a simple API, with support for batching, async transport options, and configurable endpoints.
mixpanel/mixpanel-php package is a lightweight, purpose-built solution for tracking user events, funnel analysis, and cohort behavior—ideal for Laravel applications requiring real-time analytics without heavy infrastructure (e.g., self-hosted solutions like Matomo or Snowplow).AnalyticsService (or facade) to enforce consistency and reduce direct dependency sprawl.ServiceProvider (e.g., MixpanelServiceProvider) to bind the client and configure API keys from .env.user.registered, order.placed) to auto-track business-critical events.MixpanelTrackJob) to avoid blocking HTTP requests during peak loads.Validator or FormRequest) is needed to prevent malformed data.Http facade).distinct_id may require anonymization (e.g., hashing emails).spatie/laravel-analytics)?$this->app->singleton(Mixpanel::class, function ($app) {
return new Mixpanel($app['config']['services.mixpanel.token']);
});
config/services/mixpanel.php.Mixpanel facade for concise syntax (e.g., Mixpanel::track($user, 'purchase')).registered, created) to auto-track user actions.public function handle(UserRegistered $event) {
Mixpanel::track($event->user, 'user_registered', [
'plan' => $event->user->plan,
'referral_source' => $event->user->referral_source
]);
}
MixpanelTrackJob::dispatch($user, 'event_name', $properties);
shouldQueue() in jobs to handle failures gracefully.page_view, button_click) for a single feature (e.g., checkout flow).order_completed, subscription_canceled) to Mixpanel.observers or model events for consistency.cart_added → checkout_started → purchase).Mixpanel::identify()).user_updated).people.set()) to reduce latency.| Step | Task | Dependencies | Owner |
|---|---|---|---|
| 1 | Set up Mixpanel account + API token | Mixpanel signup | PM/Dev |
| 2 | Add package to composer.json |
- | Dev |
| 3 | Configure Laravel service provider | config/services/mixpanel.php |
Dev |
| 4 | Implement core event listeners | Laravel events | Dev |
| 5 | Test event tracking in staging | Mixpanel dashboard | QA/Dev |
| 6 | Integrate queue jobs for async tracking | Laravel Queues | Dev |
| 7 | Add error handling (retries, logging) | Mixpanel API errors | Dev |
| 8 | Document event schema + ownership | Confluence/ADR | PM/Dev |
| 9 | Monitor costs + event volume | Mixpanel billing | PM/Finance |
config/services/mixpanel.php to avoid hardcoded values.env() helper for dynamic token/environment switching.mixpanel_events.yml file to document event names/properties.storage/logs/mixpanel.log.Mockery or Laravel’s HTTP tests to simulate Mixpanel API failures.How can I help you explore Laravel packages today?