Google analytics and Ajax

June 16th, 2008

adsense_anaytics_goal-792117
Last week, my colleague approached me with a quite interesting task. He is promoting our company website and wanted me a solution where in he can monitor the user enquiries through Google Analytics.

Interestingly the site used Ajax for the enquiry form, so the page was not getting redirected to a thank you page, which could have taken as a conversion URL, just like any lead generation campaign.

I always wanted to implement custom tracking features of Google Analytics, so this I took very positively. Next day we could see reports on Goals in Analytics interface !!

This custom implementation wasn’t much complex. I’ll explain.

We were using the new version of Google Analytics code. The enquiry form was getting submitted through an Ajax. If you are familiar with Ajax, you should be knowing what’s happening behind the browser. If not, please refer any tutorial. When the response is processed, the output is written to the browser, usually a response similar to “Thank you, we will be in touch with you shortly”. This is the situation we can consider as a conversion.

First, I added a new Goal in Google Analytics, giving a virtual URL corresponding to the goal (Why virtual URL? – Because I don’t have a real one J ). Then I added a single line javascript code to the existing Ajax processing code, immediately prior to the line which was outputting a thank you message to the browser.

The code was

pageTracker._trackPageview(”MY Virtual Conversion URL”);

That’s it, Google Analytics started recording Goal conversions !!

Similarly any browser events can be identified and tracked as per our requirements. Do remember Flash works with an action script, which is quite similar to javascript. So we can track flash events too !!

I am yet to have a hands on Experience in Omniture Site Catalyst implementation, but I feel it should have more flexible options for tracking on such scenarios. I am keen on having a trial on Omniture Sita Catalyst implementation. Its sad that Omniture University dont conduct trainings in India, but they do have a 2 hour web based training.

Leave a Reply