How To Track Ajax And Flash Pageviews In Google Analytics?
Google Analytics has a fresh & nice feature that Ajax & Flash developers will like. Yes, it is now possible to track pageviews in Ajax & Flash applications. And, it is simple.
It is enough to call a function named _trackPageview when an Ajax request or Flash event is called.

An example provided by Google is:
...
http_request.onreadystatechange = sendAlert;
http_request.open('GET', url, true);
http_request.send(null);
}
function sendAlert() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
alert(http_request.responseText);
pageTracker._trackPageview("/pagefilename1" ); }
else {
alert('Error.');
}
}
}
...
To summarize, after an Ajax request is made, the function is called with the page name that is viewed. And, Analytics tracks this page name.
An important usage tip about this feature is that, Google Analytics codes are normally installed just before the </body> tag. When calling _trackPageview function, you’ll need to use it after the Analytics codes are included. Which means installing the Analytics codes just after the <body> tag is a guaranteed solution.
Google is presenting detailed info & examples for both Ajax & Flash.
P.S. The feature is only available with the new Analytics code: the gaJsHos one.
Website 2: http://www.google.com/support/analytics/bin/answer.p...
- Tags:
Ajax Flash
- Filed under: Extras, Goodies, Info, Other License, Statistics
- 6 Comments















6 Responses for "How To Track Ajax And Flash Pageviews In Google Analytics?"
Thanks for pointing this out, I was looking for it a few months ago… now it’s gotten a lot easier.
Nice one, but they had this functionality on the old version too.
It was the urchinTracker function.
Anyway, thanks for the work on the site, helps a lot!
btw, first (ajax) link goes to the old version.
Tiago said it, the old version supports this method too.
Liveconnect makes it possible to call JavaScript from within Java, this way you can use Analytics to track your Java-based web applications also, what makes it possible to you to track the version of the installed Java Plug also.
This used to be a preferable means of tracking these events, but if you want your pageview count to be accurate and be able to segment user actions like this from normal pageload activity, I’d recommend the newer Event tracking:
http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer=55520
I have it on some of my accounts and not others. However, over the coming weeks they are rolling out newer features to all users, so keep your eyes peeled.
Sorry, wrong link.
http://code.google.com/apis/analytics/docs/eventTrackerGuide.html
This is the new _trackEvent method.
Thanks for pointing this out