Track outbound links for Google Analytics automatically
Place this code before the </body> tag and it’ll track all outbound links that aren’t part of your website.
<script type=”text/javascript”>
if (document.getElementsByTagName) {
var ahrefs = document.getElementsByTagName(’a');
for (var i=0; i<ahrefs.length;i++) {
if (ahrefs[i].href.indexOf(’http://www.jhuskisson.com‘) == -1 && !ahrefs[i].onclick) {
ahrefs[i].onclick = function () { var track = this.href + ”; urchinTracker (’/outgoing/’+track.substring(7)); }
}
}
}
</script>
Simply replace http://www.jhuskisson.com with your own site URL and hey presto - all outbound links that aren’t internal are being tracked by Google Analytics.
There are 16 responses to this post so far
-
Dan wrote: -
MR wrote: -
Curious wrote: -
Ross wrote: -
LKamoku wrote: -
Konrad wrote: -
Yunus wrote: -
Chris wrote: -
Chris wrote: -
Chris wrote: -
Brad wrote: -
Ryota wrote: -
Ryota wrote:


