Download the PHP package canerdogan/laravel-mixpanel without Composer
On this page you can find all versions of the php package canerdogan/laravel-mixpanel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download canerdogan/laravel-mixpanel
More information about canerdogan/laravel-mixpanel
Files in canerdogan/laravel-mixpanel
Package laravel-mixpanel
Short Description MixPanel wrapper for Laravel 5.*
License MIT
Informations about the package laravel-mixpanel
MixPanel for Laravel 5
Features
- Asynchronous data transmission to Mixpanel's services. This prevents any delays to your application if Mixpanel is down, or slow to respond.
- Drop-in installation and configuration into your Laravel app, tracking the most common events out of the box.
- Simple Stripe integration allowing you to track revenues at the user level.
- Front-end-ready Mixpanel JS library, both for Laravel Elixir inclusion or Blade template use.
Requirements and Compatibility
- PHP 7
- Laravel 5.1 (LTS)
- Laravel 5.3
- Laravel 5.4 (current)
Legacy Versions
Installation
Add the service provider entry in config\app.php
:
Verify that your auth configuration file config/auth.php
has the user model
specified in auth.providers.users.model
(or in auth.model
for L5.1). If
that entry is missing, go ahead and add it.
Lastly, add your Mixpanel API token to your .env
file:
Configuration
Default Values
services.mixpanel.token
: pulls the 'MIXPANEL_TOKEN' value from your.env
file.services.mixpanel.enable-default-tracking
: (default: true) enable or disable Laravel user event tracking.services.mixpanel.consumer
: (default: socket) set the Guzzle adapter you want to use.services.mixpanel.connect-timeout
: (default: 2) set the number of seconds after which connections timeout.services.mixpanel.timeout
: (default: 2) set the number of seconds after which event tracking times out.
Upgrade Notes
Page Views
- Page view tracking has been removed in favor of Mixpanels in-built Autotrack functionality, which tracks all page views. To turn it on, visit your Mixpanel dashboard, click Applications > Autotrack > Web > etc. and enable Autotracking.
Usage
Track
OR
OR With parameters
Increment
PHP Events
Stripe Web-Hook
If you wish to take advantage of the Stripe web-hook and track revenue per user, you should install Cashier:
Once that has been completed, exempt the web-hook endpoint from CSRF-validation
in /app/Http/Middleware/VerifyCsrfToken.php
:
The only other step remaining is to register the web-hook with Stripe: Log into your Stripe account: https://dashboard.stripe.com/dashboard, and open your account settings' webhook tab:
Enter your MixPanel web-hook URL, similar to the following: http://<your server.com>/canerdogan/laravel-mixpanel/stripe
:
Be sure to select "Live" if you are actually running live (otherwise put into test mode and update when you go live). Also, choose "Send me all events" to make sure Laravel Mixpanel can make full use of the Stripe data.
JavaScript Events & Auto-Track
Laravel Elixir
Add the following lines to your /resources/js/app.js
(or equivalent), and
don't forget to replace YOUR_MIXPANEL_TOKEN
with your actual token:
Blade Template
First publish the necessary assets:
Then add the following to the head section of your layout template:
Usage
MixPanel is loaded into the IoC as a singleton. This means you don't have to manually call $mixPanel::getInstance() as described in the MixPanel docs. This is already done for you in the ServiceProvider.
Common user events are automatically recorded:
- User Registration
- User Deletion
- User Login
- User Login Failed
- User Logoff
- Cashier Subscribed
- Cashier Payment Information Submitted
- Cashier Subscription Plan Changed
- Cashier Unsubscribed
To make custom events, simple get MixPanel from the IoC using DI:
If DI is impractical in certain situations, you can also manually retrieve it from the IoC:
After that you can make the usual calls to the MixPanel API:
$mixPanel->identify($user->id);
$mixPanel->track('User just paid!');
$mixPanel->people->trackCharge($user->id, '9.99');
-
$mixPanel->people->set($user->id, [$data]);
And so on ...
Laravel Integration
Out of the box it will record the common events anyone would want to track. Also, if the default $user->name
field is
used that comes with Laravel, it will split up the name and use the last word as the last name, and everything prior for
the first name. Otherwise it will look for first_name
and last_name
fields in the users table.
-
User registers:
-
User is updated:
-
User is deleted:
-
User is restored (from soft-deletes):
-
User logs in:
-
User login fails:
- User logs out:
Stripe Integration (test needed)
Many L5 sites are running Cashier to manage their subscriptions. This package creates an API webhook endpoint that keeps vital payment analytics recorded in MixPanel to help identify customer churn.
Out of the box it will record the following Stripe events in MixPanel for you:
Charges
-
Authorized Charge (when only authorizing a payment for a later charge date):
-
Captured Charge (when completing a previously authorized charge):
-
Completed Charge:
-
Refunded Charge:
- Failed Charge:
Subscriptions
-
Customer subscribed:
-
Customer unsubscribed:
-
Customer started trial:
-
Customer upgraded plan:
- Customer downgraded plan (based on dollar value compared to previous plan):
All versions of laravel-mixpanel with dependencies
illuminate/config Version 5.1.* || 5.3.* || 5.4.*
illuminate/events Version 5.1.* || 5.3.* || 5.4.*
illuminate/routing Version 5.1.* || 5.3.* || 5.4.*
illuminate/support Version 5.1.* || 5.3.* || 5.4.*
nesbot/carbon Version ^1.19
mixpanel/mixpanel-php Version ~2.0
sinergi/browser-detector Version ~5.0