I’ve been reading about setting up Google Analytics on an AJAX site and I just wanted to try to confirm I’m implemented it correctly.
On the main page (that holds the AJAX DIV’s – in this case) I have the STD Google Analytics Code at the bottom of the page (for load speed) being:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxxxx']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
Then when a user clicks on a link that will load an AJAX div (could be called page) like:
www.domainname.com\#home
This kicks off an AJAX .load(). Actually before the .load() occurs I have included this extra line of JS (diff end value/page name for each AJAX page/div):
_gaq.push(['_trackPageview', '/home']);
Is that it? Is it ok to run the above code before the AJAX .load()? Is there a way to check its working by check the site? Or do I need to wait to see if Google Analytics starts to pick up extra pages etc?
Thanks
Here is an explanation about how to test google analytics
http://www.webanalyticsworld.net/2010/03/test-google-analytics-without-waiting.html