Db11d496fa96adac53b422feb6efd493

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.

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 !

Bfec5f7d1a4aaafc5a2451be8c42d26a

macournoyer

October 4, 2007, October 04, 2007 19:07, permalink

No rating. Login to rate!

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!

Dce90ceb553a872aa5c621c363c5ff57

Bosko

October 4, 2007, October 04, 2007 20:38, permalink

No rating. Login to rate!

he does that because google analytics will then associate from urchinTracker(pageview) views on pageview. So if you download wtf.mp3, it'll show up in ganalytics as /downloads/wtf.mp3

Your refactoring





Format Copy from initial code

or Cancel