PHPackages                             danthedj/laravel-mixpanel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. danthedj/laravel-mixpanel

ActiveLibrary

danthedj/laravel-mixpanel
=========================

MixPanel wrapper for Laravel 5.

0.8.0(5y ago)0380MITPHPPHP &gt;=7.1.3

Since May 30Pushed 5y ago1 watchersCompare

[ Source](https://github.com/DanTheDJ/laravel-mixpanel)[ Packagist](https://packagist.org/packages/danthedj/laravel-mixpanel)[ RSS](/packages/danthedj-laravel-mixpanel/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (20)Versions (80)Used By (0)

MixPanel for Laravel 5
======================

[](#mixpanel-for-laravel-5)

[![Join the chat at https://gitter.im/GeneaLabs/laravel-mixpanel](https://camo.githubusercontent.com/8d358c6ea079bc2e9976b5b324e3850b83908a49269aaaf69fcaa63f5d35b063/68747470733a2f2f6261646765732e6769747465722e696d2f47656e65614c6162732f6c61726176656c2d6d697870616e656c2e737667)](https://gitter.im/GeneaLabs/laravel-mixpanel?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)[![Travis](https://camo.githubusercontent.com/06a1cdcbd944ef5132b6875bf0d9ba75c3cbbf988a4e541b147eedf4db3674a1/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f47656e65614c6162732f6c61726176656c2d6d697870616e656c2e737667)](https://travis-ci.org/GeneaLabs/laravel-mixpanel)[![Scrutinizer](https://camo.githubusercontent.com/91850facd38e3bba3a498a00b174938538b246d9564fb84a92d3a9512e55fbc6/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f47656e65614c6162732f6c61726176656c2d6d697870616e656c2e737667)](https://scrutinizer-ci.com/g/GeneaLabs/laravel-mixpanel)[![Coveralls](https://camo.githubusercontent.com/d4a16f40011a8ec05f2b12022bfb29c00842b9dc6a125b17f68f01b30c2a8c8b/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f47656e65614c6162732f6c61726176656c2d6d697870616e656c2e737667)](https://coveralls.io/github/GeneaLabs/laravel-mixpanel)[![GitHub (pre-)release](https://camo.githubusercontent.com/658aa49b0144f74865975e5bec33b52c73733cffb7e5305d9343173e0332ffa3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f47656e65614c6162732f6c61726176656c2d6d697870616e656c2f616c6c2e737667)](https://github.com/GeneaLabs/laravel-mixpanel)[![Packagist](https://camo.githubusercontent.com/f42ed15acef7cdc9b3bbfea0d8f996e546114a812f9be4509cb2cd00ceaf03a7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f47656e65614c6162732f6c61726176656c2d6d697870616e656c2e737667)](https://packagist.org/packages/genealabs/laravel-mixpanel)[![GitHub license](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://raw.githubusercontent.com/GeneaLabs/laravel-mixpanel/master/LICENSE)

Features
--------

[](#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
------------------------------

[](#requirements-and-compatibility)

- PHP &gt;= 7.1.3
- Laravel &gt;= 5.5

### Legacy Versions

[](#legacy-versions)

- [Laravel 5.2](https://github.com/GeneaLabs/laravel-mixpanel/tree/afcf3737412c1aebfa9dd1d7687001f78bdb3956)
- [Laravel 5.0](https://github.com/GeneaLabs/laravel-mixpanel/tree/ce110ebd89658cbf8a91f2cfb5db57e2b449e7f3)

Installation
------------

[](#installation)

```
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
```

Configuration
-------------

[](#configuration)

### Default Values

[](#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
-------------

[](#upgrade-notes)

### Version 0.7.0 for Laravel 5.5

[](#version-070-for-laravel-55)

- Remove the service provider from `/config/app.php`. The service provider is now auto-discovered in Laravel 5.5.

### Page Views

[](#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 &gt; Autotrack &gt; Web &gt; etc.* and enable Autotracking.

Usage
-----

[](#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:

```
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 ...

    ### Stripe Web-Hook

    [](#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`:

    ```
        protected $except = [
            'genealabs/laravel-mixpanel/stripe',
        ];
    ```

    The only other step remaining is to register the web-hook with Stripe: Log into your Stripe account: , and open your account settings' webhook tab:

    Enter your MixPanel web-hook URL, similar to the following: `http:///genealabs/laravel-mixpanel/stripe`: [![screen shot 2015-05-31 at 1 35 01 pm](https://cloud.githubusercontent.com/assets/1791050/7903765/53ba6fe4-079b-11e5-9f92-a588bd81641d.png)](https://cloud.githubusercontent.com/assets/1791050/7903765/53ba6fe4-079b-11e5-9f92-a588bd81641d.png)

    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 &amp; Auto-Track

    [](#javascript-events--auto-track)

    #### Blade Template (Recommended)

    [](#blade-template-recommended)

    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')
    ```

    #### Laravel Elixir

    [](#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:

    ```
    require('./../../../public/genealabs-laravel-mixpanel/js/mixpanel.js');
    mixpanel.init("YOUR_MIXPANEL_TOKEN");
    ```

### Laravel Integration

[](#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:

    ```
    Track:
      User:
        - Status: Registered
    People:
      - $first_name:
      - $email:
      - $last_name:
      - $created:

    ```
- 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:
      - $email:
      - $last_name:
      - $created:

    ```
- User logs out:

    ```
    Track:
      Session:
        - Status: Logged Out

    ```

### Stripe Integration

[](#stripe-integration)

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

[](#charges)

- Authorized Charge (when only authorizing a payment for a later charge date):

    ```
    Track:
      Payment:
        - Status: Authorized
        - Amount:

    ```
- Captured Charge (when completing a previously authorized charge):

    ```
    Track:
      Payment:
        - Status: Captured
        - Amount:
    People TrackCharge:

    ```
- Completed Charge:

    ```
    Track:
      Payment:
        - Status: Successful
        - Amount:
    People TrackCharge:

    ```
- Refunded Charge:

    ```
    Track:
      Payment:
        - Status: Refunded
        - Amount:
    People TrackCharge: -

    ```
- Failed Charge:

    ```
    Track:
      Payment:
        - Status: Failed
        - Amount:

    ```

### Subscriptions

[](#subscriptions)

- Customer subscribed:

    ```
    Track:
      Subscription:
        - Status: Created
    People:
      - Subscription:

    ```
- Customer unsubscribed:

    ```
    Track:
      Subscription:
        - Status: Canceled
        - Upgraded: false
      Churn! :(
    People:
      - Subscription: None
      - Churned:
      - Plan When Churned:
      - Paid Lifetime:  days

    ```
- Customer started trial:

    ```
    Track:
      Subscription:
        - Status: Trial
    People:
      - Subscription: Trial

    ```
- Customer upgraded plan:

    ```
    Track:
      Subscription:
        - Upgraded: true
      Unchurn! :-)
    People:
      - Subscription:

    ```
- Customer downgraded plan (based on dollar value compared to previous plan):

    ```
    Track:
      Subscription:
        - Upgraded: false
      Churn! :-(
    People:
      - Subscription:
      - Churned:
      - Plan When Churned:

    ```

The Fine Print
==============

[](#the-fine-print)

Commitment to Quality
---------------------

[](#commitment-to-quality)

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:

- ✅ Achieve as close to 100% code coverage as possible using unit tests.
- ✅ Eliminate any issues identified by SensioLabs Insight and Scrutinizer.
- ✅ Be fully PSR1, PSR2, and PSR4 compliant.
- ✅ Include comprehensive documentation in README.md.
- ✅ Provide an up-to-date CHANGELOG.md which adheres to the format outlined at .
- ✅ Have no PHPMD or PHPCS warnings throughout all code.

Contributing
------------

[](#contributing)

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](https://github.com/GeneaLabs/laravel-model-caching/blob/master/CODE_OF_CONDUCT.md).

### Reporting Issues

[](#reporting-issues)

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.

### Submitting Pull Requests

[](#submitting-pull-requests)

Please review the Contribution Guidelines . Only PRs that meet all criterium will be accepted.

❤️ Open-Source Software - Give ⭐️
---------------------------------

[](#️-open-source-software---give-️)

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.)

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 98.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~25 days

Recently: every ~265 days

Total

77

Last Release

2048d ago

PHP version history (4 changes)0.1.2PHP &gt;=5.4.0

0.3.2PHP &gt;=5.5.0

0.6.0-RCPHP &gt;=7.0.0

0.7.5PHP &gt;=7.1.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/d92d70e27f69cefaf8d40f94281be6ef3aa909c1841027aff08d198f1439cdef?d=identicon)[danthedj](/maintainers/danthedj)

---

Top Contributors

[![mikebronner](https://avatars.githubusercontent.com/u/1791050?v=4)](https://github.com/mikebronner "mikebronner (226 commits)")[![igorsantos07](https://avatars.githubusercontent.com/u/532299?v=4)](https://github.com/igorsantos07 "igorsantos07 (1 commits)")[![imam](https://avatars.githubusercontent.com/u/8213031?v=4)](https://github.com/imam "imam (1 commits)")[![mglinski](https://avatars.githubusercontent.com/u/78872?v=4)](https://github.com/mglinski "mglinski (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/danthedj-laravel-mixpanel/health.svg)

```
[![Health](https://phpackages.com/badges/danthedj-laravel-mixpanel/health.svg)](https://phpackages.com/packages/danthedj-laravel-mixpanel)
```

###  Alternatives

[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)[genealabs/laravel-mixpanel

MixPanel wrapper for Laravel.

122841.0k](/packages/genealabs-laravel-mixpanel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
