Sakin Shrestha

Tracking Exit/Outbound Links through Google Analytics

Google Analytics Exit Link Screenshot
Google Analytics Exit Link Screenshot

Google Analytics is the enterprise-class web analytics solution that gives you rich insights into your website traffic and marketing effectiveness. Powerful, flexible and easy-to-use features now let you see and analyze your traffic data in an entirely new way. With Google Analytics, you’re more prepared to write better-targeted ads, strengthen your marketing initiatives and create higher converting websites.

I use Google Analytics for my own site and other sites I work on.  I mostly use this tool to track the visitor and my popular post, keywords and also the click on Site Overlay. I had never tracked exit/outbound link with Google Analytics. One day, my client asked to me research about it and track the exit link.  Then my search for the exit link tracker begins. I fund lot of codes but non of them work properly. Finally, I was lucky enough to get read an article written by Jordi Romkema. But now I see that his site is not available. So, I am writing here again with reference to his code. If you are finding difficult to track the exit/outbound link then just follow the instruction below:

1) Create a Javascript file. For example let’s save it as exittracker.js and write the following code and save it.
var ExitTracker = Class.create({
initialize: function()
{
this.domain = document.location.toString().toLowerCase().split("/")[2];
$$("a").each(function(item)
{
if (item.href && (item.href != (document.location + "#")))
{
$(item).observe("click", this.track.bindAsEventListener(this));
}
}.bind(this));
},
track: function(e)
{
var el = e.element();
var exit_domain = el.href.split("/")[2].toLowerCase();
if (this.domain.toLowerCase().indexOf(exit_domain) == -1)
{
if (typeof pageTracker != "undefined")
{
pageTracker._trackPageview("/exit/" + el.href);
}
}
}
});

2) Now insert the following code to link the scripts. You should place the code right after your Google Analytics code:
<!-- Google Analytics code here -->
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="exittracker.js"></script>
<script type="text/javascript">
new ExitTracker();
</script>

Note: Click here to download the prototype.js

If you find difficult to write the code then Click here to download the set of prototype.js and exittracker.js . Then you can just add the code to link these two file after your Google analytics code.

If there is any problem then just write a comment and then I will reply you back.

Exit mobile version