Package Data | |
---|---|
Maintainer Username: | mikebronner |
Maintainer Contact: | hello@genealabs.com (Mike Bronner) |
Package Create Date: | 2015-09-14 |
Package Last Update: | 2024-05-21 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-19 03:07:50 |
Package Statistics | |
---|---|
Total Downloads: | 742,198 |
Monthly Downloads: | 4,310 |
Daily Downloads: | 167 |
Total Stars: | 117 |
Total Watchers: | 6 |
Total Forks: | 53 |
Total Open Issues: | 16 |
composer require genealabs/laravel-mixpanel
Only if you are running Laravel 5.4 or below:
Add the service provider entry in config\app.php
:
GeneaLabs\LaravelMixpanel\Providers\Service::class,
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.
// Laravel 5.3
'providers' => [
'users' => [
'driver' => '...',
'model' => App\User::class,
],
// Laravel 5.1
'model' => App\User::class,
Lastly, add your Mixpanel token to your .env
file:
MIXPANEL_TOKEN=xxxxxxxxxxxxxxxxxxxxxx
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./config/app.php
. The service provider is now
auto-discovered in Laravel 5.5.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:
To make custom events, simple get MixPanel from the IoC using DI:
use GeneaLabs\LaravelMixpanel\LaravelMixpanel;
class MyClass
{
protected $mixPanel;
public function __construct(LaravelMixPanel $mixPanel)
{
$this->mixPanel = $mixPanel;
}
}
If DI is impractical in certain situations, you can also manually retrieve it from the IoC:
$mixPanel = app('mixpanel'); // using app helper
$mixPanel = Mixpanel::getFacadeRoot(); // using facade
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 ...
If you wish to take advantage of the Stripe web-hook and track revenue per user, you should install Cashier: https://www.laravel.com/docs/5.5/billing
Once that has been completed, exempt the web-hook endpoint from CSRF-validation
in /app/Http/Middleware/VerifyCsrfToken.php
:
protected $except = [
'genealabs/laravel-mixpanel/stripe',
];
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>/genealabs/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.
First publish the necessary assets:
php artisan mixpanel:publish --assets
Then add the following to the head section of your layout template (already does the init call for you, using the token from your .env file):
@include('genealabs-laravel-mixpanel::partials.mixpanel')
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:
require('./../../../public/genealabs-laravel-mixpanel/js/mixpanel.js');
mixpanel.init("YOUR_MIXPANEL_TOKEN");
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:
Track:
User:
- Status: Registered
People:
- $first_name: <user's first name>
- $last_name: <user's last name>
- $email: <user's email address>
- $created: <date user registered>
User is updated:
People:
- $first_name: <user's first name>
- $last_name: <user's last name>
- $email: <user's email address>
- $created: <date user registered>
User is deleted:
Track:
User:
- Status: Deactivated
User is restored (from soft-deletes):
Track:
User:
- Status: Reactivated
User logs in:
Track:
Session:
- Status: Logged In
People:
- $first_name: <user's first name>
- $last_name: <user's last name>
- $email: <user's email address>
- $created: <date user registered>
User login fails:
Track:
Session:
- Status: Login Failed
People:
- $first_name: <user's first name>
- $last_name: <user's last name>
- $email: <user's email address>
- $created: <date user registered>
User logs out:
Track:
Session:
- Status: Logged Out
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:
Authorized Charge (when only authorizing a payment for a later charge date):
Track:
Payment:
- Status: Authorized
- Amount: <amount authorized>
Captured Charge (when completing a previously authorized charge):
Track:
Payment:
- Status: Captured
- Amount: <amount of payment>
People TrackCharge: <amount of intended payment>
Completed Charge:
Track:
Payment:
- Status: Successful
- Amount: <amount of payment>
People TrackCharge: <amount of payment>
Refunded Charge:
Track:
Payment:
- Status: Refunded
- Amount: <amount of refund>
People TrackCharge: -<amount of refund>
Failed Charge:
Track:
Payment:
- Status: Failed
- Amount: <amount of intended payment>
Customer subscribed:
Track:
Subscription:
- Status: Created
People:
- Subscription: <plan name>
Customer unsubscribed:
Track:
Subscription:
- Status: Canceled
- Upgraded: false
Churn! :(
People:
- Subscription: None
- Churned: <date canceled>
- Plan When Churned: <subscribed plan when canceled>
- Paid Lifetime: <number of days from subscription to cancelation> days
Customer started trial:
Track:
Subscription:
- Status: Trial
People:
- Subscription: Trial
Customer upgraded plan:
Track:
Subscription:
- Upgraded: true
Unchurn! :-)
People:
- Subscription: <new plan name>
Customer downgraded plan (based on dollar value compared to previous plan):
Track:
Subscription:
- Upgraded: false
Churn! :-(
People:
- Subscription: <new plan name>
- Churned: <date plan was downgraded>
- Plan When Churned: <plan name prior to downgrading>
During package development I try as best as possible to embrace good design and development practices to try to ensure that this package is as good as it can be. My checklist for package development includes:
Please observe and respect all aspects of the included Code of Conduct https://github.com/GeneaLabs/laravel-model-caching/blob/master/CODE_OF_CONDUCT.md.
When reporting issues, please fill out the included template as completely as possible. Incomplete issues may be ignored or closed if there is not enough information included to be actionable.
Please review the Contribution Guidelines https://github.com/GeneaLabs/laravel-model-caching/blob/master/CONTRIBUTING.md. Only PRs that meet all criterium will be accepted.
We have included the awesome symfony/thanks
composer package as a dev
dependency. Let your OS package maintainers know you appreciate them by starring
the packages you use. Simply run composer thanks after installing this package.
(And not to worry, since it's a dev-dependency it won't be installed in your
live environment.)