Tracking Exit/Outbound Links through Google Analytics

Square

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.

Google Analytics Exit Outbound Code
Google Analytics Exit Outbound Code

We use Google Analytics for our own site and most of the clients. We mostly use this tool to track the visitor and my popular post, keywords and also the click on Site Overlay. We 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 we search for the exit link tracker begins. We fund lot of codes but non of them work properly. Finally, found article written by Jordi Romkema. But now we see that his site is not available. So, we are 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 we will reply you back.

Leave a Reply

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