genealabs/mixpanel 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

genealabs/mixpanel

最新稳定版本:0.3.16

Composer 安装命令:

composer require genealabs/mixpanel

包简介

MixPanel wrapper for Laravel 5.

README 文档

README

MixPanel for Laravel 5

Considerations

  1. This package adds the multiple routes under mixpanel/webhooks/*. Please verify that these don't collide with your existing routes.

Installation

  1. Install MixPanel via composer:

    composer require genealabs\mixpanel:~0.1
  2. Add the service provider entry in config\app.php:

            'GeneaLabs\MixPanel\MixPanelServiceProvider',

Configuration

  1. Update your .env file with your MixPanel token:

    MIXPANEL_TOKEN=xxxxxxxxxxxxxxxxxxxxxx
    
  2. Load the token in the services configuration (config\services.php):

        'mixpanel' => [
            'token' => env('MIXPANEL_TOKEN'),
        ],
  3. We need to disable CSRF checking for the stripe webhook endpoints. To do that, open app/HTTP/Middleware/VerifyCsrfToken.php and add the following above the return statement:

            if ($request->is('mixpanel/webhooks/*')) {
                return $next($request);
            }
  4. Configure Stripe webhook (if you're using Stripe): Log into your Stripe account: https://dashboard.stripe.com/dashboard, and open your account settings' webhook tab:

    Enter your MixPanel webhook URL, similar to the following: http://<your server.com>/mixpanel/webhooks/stripe/transaction: screen shot 2015-05-31 at 1 35 01 pm

    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 the mixpanel endpoint can make full use of the Stripe data.

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\MixPanel\MixPanel;

class MyClass
{
    protected $mixPanel;

    public function __construct(MixPanel $mixPanel)
    {
        $this->mixPanel = $mixPanel;
    }
}

If DI is impractical in certain situations, you can also manually retrieve it from the IoC:

$mixPanel = App::make('GeneaLabs\MixPanel\MixPanel');

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:

    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
    
  • View loaded:

    Track:
      Page View:
        - Url: <page URL>
        - Route: <route name>
        - Referrer: <referring URL>
    

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

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

Subscriptions

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

genealabs/mixpanel 适用场景与选型建议

genealabs/mixpanel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 530 次下载、GitHub Stars 达 9, 最近一次更新时间为 2015 年 05 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 genealabs/mixpanel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 genealabs/mixpanel 我们能提供哪些服务?
定制开发 / 二次开发

基于 genealabs/mixpanel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 530
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-05-30