Outbound links click tracking with Google Analytics

Google Analytics allows you to create events and track them. It can be used to track clicks on links to external sites. For example, we need to track only the outbound links and email clicks, then with jQuery filter links and register a click.

$(document).ready(function(){
	$('a').not('[href^="' + document.location.protocol + '//' + document.domain + '"]').filter('[href^="http://"], [href^="https://"], [href^="mailto:"]').click(function(){
		//for asynchronous google analytics code
		_gaq.push(['_trackEvent', 'Outbound Link', 'Click', $(this).attr('href')]);
	});
})

Links and email addresses will be in event category "Outbound Link" with action "Click".
Google Analytics Event Tracking Guide

This entry was posted in Programming and tagged , , , .

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.