1 2 3 4 5 6 7
$w('mp3 pdf doc txt rtf').each(function(ext){ $$('a[href$=.' + ext + ']').each(function(a){ var pageview = '/downloads' + a.href.substr(a.href.lastIndexOf('/'), a.href.length); /* /downloads/wtf.mp3 */ a.observe('click', function(){ urchinTracker(pageview); }); }); });
Refactorings
No refactoring yet !
macournoyer
October 4, 2007, October 04, 2007 19:07, permalink
Nice script deleteme (wtf's that name?) I like how the code looks.
But why to you rewrite the url, taking the filename and adding downloads on line 3 ?
Thanks for sharing this!
This is dependent on the Prototype JavaScript library and Google Analytics. It looks for links to any mp3s, pdfs, etc, and allows for those clicks to be tracked by Google Analytics.