Last active
August 29, 2015 13:56
-
-
Save rodrigobarona/9242874 to your computer and use it in GitHub Desktop.
Tracking Google Analytics on a 1 page website using hashtags
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
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 (http://benalman.com/projects/jquery-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]); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credits for: http://stackoverflow.com/a/8246345