Track files that are downloaded from you website with Google Analytics
This is just a small Javascript snippet I'd like to share. It allows you to track links that lead to file downloads (e.g. links to .mov, .m4v, .pdf, ... files) with Google Analytics (with the latest version of the tracking code, not the old urchin code). It requires the prototype library.
Add this just before the </body> tag to track links to .mov and .m4v files :
1 var links_to_track = $$('a').grep(/[(\.mov)|(\.m4v)]$/) ;
2
3 links_to_track.each(function(a) {
4 a.observe('click', function() {
5 pageTracker._trackPageview(a.href);
6 });
7 }) ;
Feel free to comment this solution.
