Blog

Tracking file downloads with Google Analytics and Prototype

Wednesday July 16, 2008

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'));
		});
	});
});

Comments

Post Comment

Top

Copyright © 2007-2008 Undesigned