It’s been a while since us all have been working in fully AJAX enabled sites (as is the case of Indieoma(Indieoma), one of our projects). Time comes when you’d like to know a little bit about who is accessing the site, when, which page, why .. and a few more questions Google Analytics can answer for you (not particularly the last one) in a very simple manner most of you already know about.
You may encounter some issue when trying to check your stats for the AJAX requests people have made. As you can imagine, the code you place in your web pages won’t execute itself on each AJAX request, but more like on each entire page load. But Google doesn’t let us down and give us a tiny explanation( How do I track AJAX applications?) on how to pull this off.
1 2 3 4 5 6
Using the Ajax.Responders(Prototype Ajax.Responders), we register a function that will fire the tracker after each AJAX request has been completed.
_trackPageview(request.url) allows us to name the tracked page exactly as the requested URL. Note that you can name this page in any way you like. We chose to do so with the requested URL in this case.
So, that’s it and happy analytics!