Вопрос

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?

Это было полезно?

Решение

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!

Другие советы

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:

https://developers.google.com/analytics/devguides/collection/analyticsjs/single-page-applications#tracking_virtual_pageviews

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top