This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/initializers/page-tracking.js.es6
Robin Ward 5fc150e057 A mucher saner API for updating the title of routes, even when nested.
Properly sends the title of the page to google analytics
2014-10-09 14:55:29 -04:00

31 lines
796 B
JavaScript

/**
Sets up the PageTracking hook.
**/
export default {
name: "page-tracking",
after: 'register-discourse-location',
initialize: function() {
var pageTracker = Discourse.PageTracker.current();
pageTracker.start();
// Out of the box, Discourse tries to track google analytics
// if it is present
if (typeof window._gaq !== 'undefined') {
pageTracker.on('change', function(url, title) {
window._gaq.push(["_set", "title", title]);
window._gaq.push(['_trackPageview', url]);
});
return;
}
// Also use Universal Analytics if it is present
if (typeof window.ga !== 'undefined') {
pageTracker.on('change', function(url, title) {
window.ga('send', 'pageview', {page: url, title: title});
});
}
}
};