An Ember-CLI addon that eases integration between your application and Mixpanel. This is a close port of rahim's ember-segmentio.
Add ember-cli-mixpanel
as a dependency to your package.json
or just run ember install:addon ember-cli-mixpanel
.
There are two manual steps
- Extend your Router with
tracking_mixin.js
. - Add a
{{content-for 'mixpanel'}}
to your index.html to include the mixpanel script.
There are some options available to configure the mixpanel addon. Only token
is a mandatory option otherwise
mixpanel: {
enabled: false,
LOG_EVENT_TRACKING: false,
token: 'b619c413e0d49a362236388a4f5ec679',
disable_auto_tracking: true // default: false
}
Once included your router will automatically send a page view event to
Mixpanel everytime the URL changes. This behavior can be disabled with disable_auto_tracking: true
.
You can track addinional events as well. Let's say we would like to track play events on our controller.
import Ember from 'ember'
import TrackingMixin from './mixin/tracking_mixin'
var VideoController = Ember.Controller.extend(
TrackingMixin, {
actions: {
play: function() {
// ...
// this.trackEvent(event, properties, options, callback)
this.trackEvent('Play video');
// or
this.trackEvent('Play video', {
title: 'Never gonna give you up'
}
});
}
});
The mixin can be applied to any Ember object.
TBD
For debugging purposes you can enable logging for all events. Events are still send to Mixpanel but you will get an additional output in your console.
Add LOG_EVENT_TRACKING = true|false
to your config file
Simple ember-cli addon just follow the documentation :)