Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gabrielslau/cakephp-mixpanel
Mixpanel plugin for CakePHP 3.0
https://github.com/gabrielslau/cakephp-mixpanel
analytics-tracking cakephp component embed helper javascript mixpanel php56
Last synced: about 2 months ago
JSON representation
Mixpanel plugin for CakePHP 3.0
- Host: GitHub
- URL: https://github.com/gabrielslau/cakephp-mixpanel
- Owner: gabrielslau
- Created: 2017-05-04T21:29:38.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-05-16T19:09:12.000Z (over 7 years ago)
- Last Synced: 2024-10-13T13:04:04.325Z (3 months ago)
- Topics: analytics-tracking, cakephp, component, embed, helper, javascript, mixpanel, php56
- Language: PHP
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
CakePHP Mixpanel Plugin
=======================This plugin provides a Mixpanel component to track events from your controllers using the official [Mixpanel PHP library](https://github.com/mixpanel/mixpanel-php).
Requirements
------------- PHP >= 5.6
- CakePHP >= 3.0How to Install
----------```
composer require okatsuralau/[email protected]
```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:
```php
return [
//...
'Mixpanel' => [
'token' => YOUR_TOKEN_HERE
]
]
```Load the component in your `src/Controller/AppController.php`
```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
```php
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````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