Tracking file downloads in Google Analytics AND Google Adwords
Friday, November 16, 2007 at 2:33PM Google has not one web analytics system, but two of them, namely Google Analytics and Google Adwords. For the average webmaster, this situation is quite a pain, because most of the tracking code must be duplicated. To make the situation worse, Google Adwords does not support any straightforward solution to track file downloads.
For the sake of my own μISV, I have designed the following script that enables both Analytics and Adwords tracking in a single function.
// Tracking.js - Joannes Vermorel, Lokad.com, 2007
function dhtmlLoadScript(url)
{
var e = document.createElement("script");
e.src = url;
e.type="text/javascript";
document.getElementsByTagName("head")[0].appendChild(e);
}
function lokadTracker(path)
{
urchinTracker(path);
google_conversion_id = 10683XXXX; // use your own ID here
google_conversion_language = "en_US";
google_conversion_format = "1";
google_conversion_color = "FFFFFF";
if (1) {
google_conversion_value = 1;
}
google_conversion_label = "pageview";
dhtmlLoadScript('http://www.googleadservices.com/pagead/conversion.js');
}
In order to track a file download just embed the script here above, and intercept the onclick event of your download link
<a onclick="lokadTracker('/Foo.zip')" href="Foo.zip" > Foo <a>
google,
practices,
web in
Software Engineering,
uISV 
Reader Comments (3)
Thanks for this Joannes. I posted a question about this on the BOS forum a coupe of weeks ago and didn't get any replies.
Are you having success in using the above code?
--
Ethan
Declan Software
Sorry for the delay, I may have forgotten to check that thread.
On Lokad.com, the Urchin tracker is working, but for AdWords, I am mixing "download" conversions with "user registration" conversions, so I can't be sure that the piece of code here above working.
Obviously, it would need to be done seriously, but I have been very busy with other stuff lately.
(sorry, Ethan, deleted your message by error)
No, I haven't seen any other way to do it so far.