Tracking Ajax Pageloads with Universal Google Analytics

I just updated our new Ajax webpage and I am having trouble figuring out how to track pageviews for each ajax page loaded. So far, Google Analytics only reports views to the index/home page when internal ajax pages are loaded, but not each individual ajax page.

Here's the code that is included in the template page container, which loads at the bottom of each individual ajax page :

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-70690965-1', 'auto');
  ga('send', 'pageview', document.URL);

</script>

How can I track ajax page loads?

Answers


One method would be to check for ajaxComplete:

$(document).ajaxComplete(function(e,x,o){
   console.info('ajax completed');
   ga('send','page', '/vpv/ajax/page');
}

When an ajaxComplete is called, you can send a virtual page view.


Need Your Help

Star rating and microformats

image algorithm rating-system microformats

I have a star rating on my website and I'm trying to use microformats. I read the Google's documentation and they give as an example :

Read file from url java to android problems

java android file-io

I have a txt file at the online storage that my university offers me and I want to read it at an android application. I've managed to do this in Java but when I try to do this in Android nothing ha...