Skip to content

Instantly share code, notes, and snippets.

View poteto's full-sized avatar
🥔
ポテト

lauren poteto

🥔
ポテト
View GitHub Profile
/**
* Where:
* button is the category
* click is the action
* nav buttons is the label
* 4 is the value
*/
ga('send', 'event', 'button', 'click', 'nav buttons', 4);
mixpanel.track('Clicked Nav Button', { value: 4 });
_kmq.push(['record', 'Clicked Nav Button', { value: 4 }]);
import Ember from 'ember';
export default Ember.Route.extend({
metrics: inject.service(),
activate() {
this._trackPage();
},
_trackPage() {
// only invokes the `trackPage` method on the `GoogleAnalyticsAdapter`
metrics.trackPage('GoogleAnalytics', { title: 'My Awesome App' });
module.exports = function(environment) {
var ENV = {
metricsAdapters: [
{ name: 'GoogleAnalytics', config: { id: 'UA-XXXX-Y' } },
{ name: 'Mixpanel', config: { token: 'xxx' } }
]
}
}
import config from '../config/environment';
export function initialize(_container, application) {
const { metricsAdapters = {} } = config;
application.register('config:metrics', metricsAdapters, { instantiate: false });
application.inject('service:metrics', 'metricsAdapters', 'config:metrics');
}
export default {
import Ember from 'ember';
export default Ember.Service.extend({
_adapters: {},
init() {
const adapters = Ember.getWithDefault(this, 'metricsAdapters', Ember.A([]));
this._super(...arguments);
this.activateAdapters(adapters);
},
_activateAdapter(adapterOption = {}) {
const metrics = this;
const { name, config } = adapterOption;
const Adapter = this._lookupAdapter(name);
assert(`[ember-metrics] Could not find metrics adapter ${name}.`, Adapter);
return Adapter.create({ metrics, config });
}
_lookupAdapter(adapterName = '') {
const container = Ember.get(this, 'container');
if (isNone(container)) {
return;
}
const dasherizedAdapterName = dasherize(adapterName);
const availableAdapter = container.lookupFactory(`ember-metrics@metrics-adapter:${dasherizedAdapterName}`);
const localAdapter = container.lookupFactory(`metrics-adapter:${dasherizedAdapterName}`);