Just a quick tip to remind you that if you use Google Analytics with a heavily Ajax driven site, you may want to update your code to track your Ajax requests. Google details this here:
How do I track AJAX applications?
I updated ColdFusionBloggers to add this code and did a bit of cleanup. Previously I had 4 different functions that loaded content into the main div for the site. There was loadContent(), which was called when you first hit the page, previous and next, called with pagination, and the search button. All of these used jQuery's .load() function to load a URL and then ran a callback function named cbfunc. (Yes, real imaginative.)
cbfunc took care of turning off the loading animation. I thought it would be a great place to handle logging the request with Google. Unfortunately, I didn't have access to the URL requested from within the call back function. I could have rewritten the 4 main functions to do something like so:
$("#content").load(u, function() {
$("#loadingmsg").hide();
pageTracker._trackPageview(u);
});
That would have worked - but it felt like a lot of repetition. I added a new method to handle everything called loadDiv():
function loadDiv(theurl) {
$("#content").load(theurl,function() {
<cfif not structKeyExists(variables, "isiphone") or not variables.isiphone>
$("#loadingmsg").hide();
</cfif>
<cfif not application.dev>
pageTracker._trackPageview(theurl);
</cfif>
});
}
The iPhone check in there simply disables hiding the loading indicator for the iPhone version. The application.dev check simply blocks Google Analytics from running when I test locally.
Anyway, I'll let folks know what kind of impact this has on my stats. To be honest, I don't ever go beyond page 1 myself, except when I'm searching. Still though I'm curious.
Archived Comments
You may be fully aware of this, so forgive me if you do... There is a beta program in Google Analytics called Event Tracking and you can track, well, events just like this. Since what you describing is essentially a page view, your solution works here, but what I am using it for is tracking other little functions like posting comments (we do ours via AJAX), etc. I don't know how one goes about getting into the program (we were invited), but once you are in, it just shows up in the content tab in the Analytics UI. Firing it off is as easy as adding this to your function that is doing the AJAX call: pageTracker._trackEvent(action, category, label);
<a href="http://code.google.com/apis...">Full documentation here</a>
I was _not_ aware of that. Thanks for sharing it.
The problem I found with this is that it uses the current window title for the hit's name. Kinda silly for an ajax app. DOH!
I got around it by changing the window title just before making the call.
document.title = newTitle;
pageTracker._trackPageview(track);
But that depends on how much of your page is changing with the ajax data. In my case, it was a large area so it makes sense to do so. EX: http://www.scenicmesa.com/b...
Thats not a bad tip. It probably would be a good idea, on CFBloggers, to change the title as well.
In the development version of that above site I am doing it like this...
// do fadeout effect
document.title = '...loading...';
// do ajax function
document.title = newTitle;
// do fadein effect
pageTracker._trackPageview(track);
Just a little added niceness for the viewer.
wow...thx for your sharing...
i will update at my code..
thx a lot