承接 okatsuralau/cakephp-mixpanel 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

okatsuralau/cakephp-mixpanel

Composer 安装命令:

composer require okatsuralau/cakephp-mixpanel

包简介

CakePHP plugin providing easy integration with Mixpanel's analytics

README 文档

README

Software License Build Status Build Status Latest Stable Version

CakePHP Mixpanel Plugin

This plugin provides a Mixpanel component to track events from your controllers using the official Mixpanel PHP library.

Requirements

  • PHP >= 5.6
  • CakePHP >= 3.0

How to Install

composer require okatsuralau/cakephp-mixpanel@1.0.0

How to Use

Load the plugin in your config/bootstrap.php file:

Plugin::load('CakephpMixpanel');

Add the plugin configurations in your config/app.php or config/app_custom.php file:

return [
    //...
    
    'Mixpanel' => [
        'token' => YOUR_TOKEN_HERE
    ]
]

Load the component in your src/Controller/AppController.php

public function initialize()
{
    parent::initialize();

    $this->loadComponent('CakephpMixpanel.Mixpanel');
}

and (optionally) add the following code to your beforeFilter() method to identify the users actions

public function beforeFilter(\Cake\Event\Event $event)
{
    // if a user is logged in
    $this->Mixpanel->identify($user_id);
    $this->Mixpanel->name_tag($user_name);
    $this->Mixpanel->register($superProperties);
    
    /* To make use of the people API */
    $this->Mixpanel->people($this->Auth->user('id'), array(
        '$username' => $this->Auth->user('username'),
        '$email' => $this->Auth->user('email'),
        '$created' => $this->Auth->user('created'),
        '$last_login' => $this->Auth->user('connected'),
        'my_custom_var' => $my_custom_var,
    ));
    
    // ...
    
    parent::beforeFilter($event);
}

To register an event, put the following code in your controller action. src/Controller/PostController.php

public function index()
{
    // ...
    
    $this->Mixpanel->track(
        'Post list', 
        [
            'author' => $this->Auth->user('name'),
            'category' => 'Post',
        ]
    );
}

public function create()
{
    if ($this->request->is('post')) {
        
        // ...
        
        $this->Mixpanel->track(
            'Post Created', 
            [
                'author' => $this->Auth->user('name'),
                'category' => 'Post',
            ]
        );
        
        $this->redirect(array('action'=>'index'));
    }
}

This should be enough to start sending events to Mixpanel.

License

Copyright 2017 Gabriel Lau

Available for you to use under the MIT license. See: http://www.opensource.org/licenses/MIT

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固