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)
onclick="javascript:urchinTracker('/outgoing/example_com');"
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 < _A.length; i++ )
{
if ( ( (_B != '' && _A[i].href.indexOf(_B) < 0) || _B == '') && _A[i].href.indexOf('://') > 0 )
{
_A[i].onclick = function(){
outlink = “/outlinks/”+this.href.substring(7) ;
urchinTracker(outlink);
};
}
}
}
attachOnClick();
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.
2 responses so far ↓
1 hitech // Nov 23, 2007 at 8:01 pm
I just added this code to my blog and footer, I will let you know how well it works for me.
2 Markus Diersbock // Mar 1, 2008 at 6:15 am
To see how Google Analytics detects clicks and displays them within the Site Overlay check out:
Google Analytics Site Overlay
Leave a Comment