Analytics: How to?

I’m trying to get a sense as to what people are doing for analytics within their Ember applications. I understand this is somewhat of a nebulous question and is somewhat domain specific – the intention is to get a high level view.


Are you talking about something like Google Analytics or Piwik?

If yes, this is a great blog post to get it started:


@stravid, although the post you linked is really useful I just found out that this solution is “not working” when you’re transitioning between dynamic segments in the same route

i.e from /posts/1 to /posts/2

I’ve put together a demo in this fiddle

basically if you look at the console the “currentPage” is not going to be logged when you transition from the first to the second post

My current solution to log all the transitions properly is to reopen Ember.Router and override the didTransition method

	didTransition: function(infos){
			path = window.location.pathname;
			// Google analytics code...

I don’t love the idea of using a private API to achieve this so if you have better suggestions please let me know !

There’s also a ‘url’ property on the router that could be used:

router.addObserver('url', function() {
        var lastUrl = undefined;
        return function() {
                var url = router.get('url');
                if (url !== lastUrl) {
                    lastUrl = url;
                    console.log("Google Analytics: " + url);

Here’s an updated fiddle using this method:

1 Like

Alex DiLiberto gave a really nice talk about a robust & scalable way of adding Google Analytics to an ember app in his EmberConf 2014 talk here.

  • slides

    App.ApplicationRoute = Ember.Route.extend({ actions: { didTransition: function() {, function() { ga(‘send’, ‘pageview’, this.router.get(‘url’)); }); } } });

The talk was aiming to be independent of which analytics library was used.


@stravid, your blog link is broken it seems my friend. :sleepy:

Thanks for the reply, I seems that the author changed the URL schema without adding redirects :frowning: New link:

1 Like

As it doesn’t seem to be mentioned in this thread it’s worth noting that there is an official Ember.js cookbook for Google Analytics:

1 Like

There is also an ember-cli addon available for Google Analytics: ember-cli-google-analytics - npm

Would be nice to have another one adding Piwik support.


found a great Ember Addon: