Created
May 9, 2014 08:27
-
-
Save Piioo/614f3c7410ed47d3d536 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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