Skip to content

Instantly share code, notes, and snippets.

@Piioo
Created May 9, 2014 08:27
Show Gist options
  • Save Piioo/614f3c7410ed47d3d536 to your computer and use it in GitHub Desktop.
Save Piioo/614f3c7410ed47d3d536 to your computer and use it in GitHub Desktop.
/**
Sets up the PageTracking hook.
**/
Discourse.addInitializer(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']);
});
}
// Also use Universal Analytics if it is present
if (typeof window.ga !== 'undefined') {
pageTracker.on('change', function() {
console.log('update');
window.ga('send', 'pageview');
});
}
console.log('foo');
if (typeof window.ga !== 'undefined') {
console.log('bar');
var real_ga = window.ga;
window.ga = function () {
console.log('changenew');
Discourse.ajax("/google/dimensions", {
type: "GET",
data: { path: window.location.pathname }
}).then(function (data) {
console.log(data);
});
return real_ga.call(arguments);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment