Alex DiLiberto
{{link-to}}
this.transitionTo()
this.replaceWith()
/post/1
→ /post/2
{{action}}
this.send()
this.triggerAction()
this.sendAction()
Ember.Analytics = Ember.Mixin.create({
trackPageView: function() {
Ember.run.next(function() {
var loc = window.location,
page = loc.hash ? loc.hash.substring(1) : loc.pathname + loc.search;
ga('send', 'pageview', page);
});
}.observes('currentPath')
});
http://emberjs.jsbin.com/puzax/12/edit
controller:application
window.location
App.ApplicationRoute = Ember.Route.extend({
actions: {
didTransition: function() {
Ember.run.once(this, function() {
ga('send', 'pageview', this.router.get('url'));
});
}
}
});
http://emberjs.jsbin.com/puzax/14/edit
controller:application
http://emberjs.jsbin.com/puzax/18/edit
App.ApplicationRoute = Ember.Route.extend({ actions: { track: function(data) { ga('send', 'event', event.target.nodeName, event.type, event.target.className, data); } } });
var analyticsObject = Ember.Object.create({
// Default data to be passed on every request
_: { site: "My Webapp Name" },
// Non route-based/global or fallback actions
_global: { _trackPromise: function(r, s) { return { route: r, status: s }; },
},
// Route-specific - e.g. {{action "baz"}} in foo.bar
// foo: { //Route name
// bar: { //Leaf-most route name
// baz: { var: 'borf' } //Action name
// }
// }
products: {
product: {
vote: function(v, c, p) { return { vote: v, color: c, product: p }; },
otherStuff: { var1: 'other-stuff' }
}
}
});
http://emberjs.jsbin.com/puzax/47/edit
// Handles existing template {{action}}'s as well as programattic send()'s
// {{action 'transferFunds'}}
// this.send('_trackAppEvent', '_trackPromise', 'accounts#model', 'reject');
Ember.ActionHandler.reopen({
send: function(actionName) {
analyticsHandler.apply(this, arguments);
}
});
http://emberjs.jsbin.com/puzax/47/edit
// Condensed analyticsHandler
var analyticsHandler = function(actionName) {
var router = this.target ? this.target.router : this.router.router,
activeTrans = router.activeTransition && router.activeTransition.targetName,
curHandlerInfos = router.currentHandlerInfos,
activeLeafMostRoute = curHandlerInfos[curHandlerInfos.length - 1].name,
routeName = activeTrans || activeLeafMostRoute,
trackObj = aObj.get(routeName+'.'+actionName) || aObj.get('_global.'+actionName);
if (typeof trackObj == 'function') {
trackObj = trackObj.apply(this, [].slice.call(arguments, 1));
}
if (trackObj) {
analyticsSendHandlers.action(Em.Object.create(aObj.get('_'), trackObj));
}
if (actionName.indexOf('_track') !== 0) {
this._super.apply(this, arguments);
}
};
http://emberjs.jsbin.com/puzax/47/edit
{{action}}
this.send()
this.triggerAction()
this.sendAction()
Alex DiLiberto