Previously I blogged about possible solutions for tracking downloads with Google Analytics. The solution I am going to experiment with first is to dynamically add the tracking code to my download links via JavaScript. I spent quite a bit of time on my script to make it cross-browser compatible and so that it would handle proper timing of execution based on the loading of the links. I also used a regular expression to limit the tracking to specific link types. Hopefully those match most cases. If all goes well I will probably wrap all of this into a simple ASP.NET control that can be added to an page you want tracked.
First off you need the standard Google tracking scripts:
<
Second is my new download tracking script. I have placed it in a separate file for browser caching and easy updating. Also it has the defer="defer" attribute so that IE will not load the script until the content has finished loading. XHTML compliance required me to include a value for the attribute. Please let me know if you come up with any improvements to the script or if you find any errors. Thanks to quirksmode for info on the dynamic event models and dean edwards for info on deferred script execution.
Here is the actual downloadtracker.js code
// We dont want the try adding the tracking code until the page links are loaded
function
function TrackIt(link){// Remove the conversion to Lowercase if you are on a Case sensitive web serverurchinTracker(link.href.toLowerCase());}
Remember Me
Powered by: newtelligence dasBlog 1.7.5016.2
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
© Copyright 2008, Cory Isakson
E-mail