Track out-clicks with Google Analytics
One major feature that seems to be missing from Google Analytics is the ability to track out-clicks or clicks on external links.
With the Lucid Directory project, we wanted to be able to see which listings are being clicked on so we can provide statistics for this later down the track.
We have come up with the following solution to track all external clicks on the site while still linking directly to the sites so they get a link indexed in Google.
<script language="Javascript">
function lucid_clicks()
{
var SiteLinks = document.links;
for(var i=0;i < SiteLinks.length;i++)
{
var thehref = SiteLinks[i].href.toString();
if(thehref.indexOf("www.yourdomain.co.nz") == -1)
{
SiteLinks[i].setAttribute("onclick","javascript:urchinTracker('/Clicks/' + this.href)");
}
}
}
</script>
You can replace www.yourdomain.co.nz with your domain and /Clicks/etc with anything you wish to show in Google Analytics.
To use, simple call lucid_clicks() in your <body> tag as follows:
<body onload="lucid_clicks()">
Let us know if you have any suggestions on how this can be improved.


“If I already have an onload event, how to i make this work? <body> will that work?”
“Hi Anthony, you could try either:
Or you could create a new Javascript function that calls your method and the lucid_clicks() method and call that in your onload. Hope that makes sense. Let me know if it works.”“Galen, this looks like it is going to be a very powerful script for several sites I maintain. Once I have installed it on the site, where would I look in Analytics to find the data? My analytics usage up to this point has been more basic tasks of finding weak landing pages or flaws in the checkout and tinkering with them. I haven't used custom scripts before. Any help would be much appreciated.”
“Hi Brian, you can access the stats for this in the content section of Analytics. You will look for "content" beginning with the path you specified in this little script ("/clicks/" in the case of my example). Hope that helps.”
“Thank you so much for this Brian. It's a very useful piece of script. I'm trying to make it work for my at the moment.”