I have a long single page website using hashtags in the URL when you get to a certain section from scrolling or clicking. What technique can I use to track these hashtags as "pages" in google analytics?
(Recycling from a prior answer...)
Generically, your code could look like this:
_gaq.push(['_trackPageview',location.pathname + location.search + location.hash]);
You could either bind that code to every time you have a hash change within your application, or you could use a generic hashchange plugin, that uses the HTML5 onhashchange, and some backwards compatible hacks for older browsers, and bind this code to that event, so that it fires every time your hash changes.
Using that plugin, your code could look like:
$(window).hashchange( function(){
_gaq.push(['_trackPageview',location.pathname + location.search + location.hash]);
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With