Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pageview onhashchange
<script>
var pageView = function() {
_gaq.push(['_trackPageview', {{url with hash}}]);
};
if (!('onhashchange' in window)) {
var oldHref = location.href;
setInterval(function() {
var newHref = location.href;
if (oldHref !== newHref) {
oldHref = newHref;
pageView.call(window, {
'type': 'hashchange',
'newURL': newHref,
'oldURL': oldHref
});
}
}, 100);
} else if (window.addEventListener) {
window.addEventListener('hashchange', pageView, false);
}
else if (window.attachEvent) {
window.attachEvent('onhashchange', pageView);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment