This repository has been archived on 2023-03-18. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
osr-discourse-src/app/assets/javascripts/discourse/initializers/page-tracking.js.es6
T
2014-05-21 07:36:58 -04:00

29 lines
691 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() {
window._gaq.push(['_trackPageview']);
});
return;
}
// Also use Universal Analytics if it is present
if (typeof window.ga !== 'undefined') {
pageTracker.on('change', function() {
window.ga('send', 'pageview');
});
}
}
};