Outbound links in Google analytics

Google with "Google analytics" the web site statistics service offers a very important service to webmasters for free. The service is undoubtedly perfect for its price. There is a missing feature though that many webmasters wish they had; where do visitors go when leaving the website. Google has addressed this partially and you can add an onclick event in your outbound links (inside your anchor tag)


I am saying that this is a partial solution because it would be tedious for people with websites that have more than say 100 pages to do this manually. Therefore I created this simple javascript solution that goes on each and every outbound link on you page and adds this click event. Here it is

function attachOnClick() {
var _B = document.domain;
var _A = document.getElementsByTagName("a");
for( var i = 0; i  0 )
_A[i].onclick = function(){
outlink = "/outlinks/"+this.href.substring(7) ;

You can save this in a javascript file analytics_report_outbound.js and then insert it in your page footer like this

<script xsrc="analytics_report_outbound.js" mce_src="analytics_report_outbound.js"     type="text/javascript"></script>

Hope it helps.



I just added this code to my blog and footer, I will let you know how well it works for me.

it would be great if you could know were the visitor went after leaving your website, but you're right making it manually is time consuming, I'll try your code to see if it make that process better, thanks!.

Try crazyegg. It has pretty heatmaps showing where people are clicking on the page and has "confetti" which shows you the users clicks as dots, looking like confetti. Like analytics just throw the javascript at the end and it'll collect it all.

But it has a price. And there is much competition for these things

clickdensity has a free package on offer I think but it'll only track one page at a time.

If you can host your own analytics then go for perhaps php link tracking, clickheat or piwik. There are plenty of option and you could even run a link trading script but have it do no trading or traffic skimming (redirecting them elsewhere) and simply use it's link tracking.

There are a ton more I havn't even touched on, Google analytics isn'et the only source of analytic data :)