Created
May 15, 2014 17:04
-
-
Save paulmkoch/e35e77e0603dbc69a3d9 to your computer and use it in GitHub Desktop.
Pageview onhashchange
This file contains hidden or 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
<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