Tracking file downloads with Google Analytics and Prototype

Using Prototype’s CSS-style selectors you can easily track file downloads with Google Analytics:

Event.observe(window, 'load', function() {
$$('a[href$=".zip"]', 'a[href$=".pdf"]').each(function(anchor) { anchor.observe('click', function(event) { if (pageTracker) pageTracker._trackPageview(anchor.getAttribute('href')); }); }); });
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.