jeffersongoncalves / laravel-mixpanel
This Laravel package seamlessly integrates Mixpanel analytics into your Blade templates. Easily track user interactions and product usage directly within your Laravel application using the Mixpanel JavaScript SDK, with all configuration managed via database settings.
Installs: 6
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
pkg:composer/jeffersongoncalves/laravel-mixpanel
Requires
- php: ^8.2|^8.3
- laravel/framework: ^11.0|^12.0
- spatie/laravel-package-tools: ^1.14.0
- spatie/laravel-settings: ^3.3
Requires (Dev)
- larastan/larastan: ^3.0
- orchestra/testbench: ^9.0|^10.0
- pestphp/pest: ^3.7.4
- pestphp/pest-plugin-laravel: ^3.0
This package is auto-updated.
Last update: 2026-02-23 02:39:24 UTC
README
This Laravel package seamlessly integrates the Mixpanel JavaScript SDK into your Blade templates. Easily track user interactions, page views, and product usage directly within your Laravel application, with all configuration managed via database settings using spatie/laravel-settings.
Requirements
- PHP 8.2+
- Laravel 11+
- spatie/laravel-settings configured (the
settingstable must exist)
Installation
Install the package via composer:
composer require jeffersongoncalves/laravel-mixpanel
If you haven't already, publish the spatie/laravel-settings migration to create the settings table:
php artisan vendor:publish --provider="Spatie\LaravelSettings\LaravelSettingsServiceProvider" --tag="migrations"
Then publish and run the Mixpanel settings migration:
php artisan vendor:publish --tag=mixpanel-settings-migrations php artisan migrate
Usage
Add the Mixpanel script to your Blade layout (typically before </head>):
@include('mixpanel::script')
Configuring Settings
Settings are stored in the database and can be managed via code:
use JeffersonGoncalves\Mixpanel\Settings\MixpanelSettings; $settings = app(MixpanelSettings::class); $settings->project_token = 'YOUR_MIXPANEL_PROJECT_TOKEN'; $settings->save();
Data Residency
Mixpanel supports data residency in the EU and India. Set the api_host accordingly:
// EU Data Residency $settings->api_host = 'https://api-eu.mixpanel.com'; $settings->save(); // India Data Residency $settings->api_host = 'https://api-in.mixpanel.com'; $settings->save();
Proxy Configuration
To route Mixpanel requests through your own proxy:
$settings->api_host = 'https://proxy.yourdomain.com'; $settings->custom_lib_url = 'https://proxy.yourdomain.com/lib.min.js'; $settings->save();
Available Settings
| Property | Type | Default | Description |
|---|---|---|---|
project_token |
?string |
null |
Your Mixpanel project token (required for tracking) |
api_host |
?string |
null |
Custom API endpoint for data residency (EU: https://api-eu.mixpanel.com, India: https://api-in.mixpanel.com) or proxy |
custom_lib_url |
?string |
null |
Custom library URL for proxy setups |
debug |
bool |
false |
Enable debug logging to browser console |
autocapture |
bool |
true |
Automatically capture clicks, inputs, scrolls, and other user interactions |
track_pageview |
string |
'true' |
Track page views automatically. Values: 'true', 'false', 'full-url', 'url-with-path-and-query-string', 'url-with-path' |
persistence |
string |
'cookie' |
Storage method for super properties ('cookie' or 'localStorage') |
cookie_expiration |
int |
365 |
Cookie lifespan in days |
secure_cookie |
bool |
false |
Only transmit cookies over HTTPS |
cross_subdomain_cookie |
bool |
true |
Enable cookie persistence across subdomains |
ip |
bool |
true |
Use IP address for geolocation data |
property_blacklist |
?string |
null |
Comma-separated list of properties to exclude from tracking |
opt_out_tracking_by_default |
bool |
false |
Initialize with tracking disabled (for GDPR/privacy compliance) |
stop_utm_persistence |
bool |
false |
Disable automatic UTM parameter retention |
record_sessions_percent |
int |
0 |
Percentage of sessions to record (0-100) |
record_heatmap_data |
bool |
false |
Enable heatmap data collection |
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.