Skip to content

Instantly share code, notes, and snippets.

@gpoitch
Last active December 16, 2015 16:40
Show Gist options
  • Save gpoitch/5465085 to your computer and use it in GitHub Desktop.
Save gpoitch/5465085 to your computer and use it in GitHub Desktop.
A Google Analytics mixin for an Ember application controller. Sends a page view whenever the currentPath (url) changes. Normalizes the page url for both history and hash location routers.
Ember.GoogleAnalytics = Ember.Mixin.create({
trackPageView: function() {
if(!Ember.isNone(ga)) {
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')
});
@gpoitch
Copy link
Author

gpoitch commented Apr 26, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment