Tracking file downloads in Google Analytics AND Google Adwords

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

Foo


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 December 19, 2007 | Ethan


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. December 19, 2007 | joannes


(sorry, Ethan, deleted your message by error) No, I haven’t seen any other way to do it so far. December 19, 2007 | joannes