Reputation: 13080
Looking at the options listed on this page: https://github.com/browserstate/history.js
It would appear there is no way to set the plugin to sent page view data to Google Analytics.
This makes it hard to deduce where users are going when viewing AJAX powered pages using the history.js
plugin.
I know that other plugins have had this implemented such as jQuery Address
: http://www.asual.com/jquery/address/ . I would have expected the history plugin to have this too.
Is there a way to enable Google Analytics with history.js
?
Upvotes: 0
Views: 1188
Reputation: 21
Just a note on this question – the Google Analytics library has been updated since this was answered in 2013.
You can learn about tracking virtual pageviews here:
Upvotes: 2
Reputation: 5193
A similar question has already been answered here: https://stackoverflow.com/a/5307532/1854499
History.js is more of a wrapper for the HTML5 History API, so the answer is the same.
After you've determined which page you'll show when the history state changes (in the statechange
callback), push another _trackPageview
call to the Google Analytics stack like so:
_gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
_gaq.push(['_trackPageview', '/new/content']);
Don't forget to add the new URL as the second argument.
You can find the documentation on these so called 'virtual pageviews' on this page (scroll to the bottom) on Google Developers.
Good luck!
Upvotes: 3