Skip to content

Instantly share code, notes, and snippets.

@paulmkoch
Created May 15, 2014 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulmkoch/e35e77e0603dbc69a3d9 to your computer and use it in GitHub Desktop.
Save paulmkoch/e35e77e0603dbc69a3d9 to your computer and use it in GitHub Desktop.
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