I’ve just updated my code on tracking exit links in Google Analytics to skip applying the code if the href of an anchor tag is ‘#’. This is usually the case when the anchor tag is there to execute javascript or to scroll to the top of the page, thus does not contain any exit liks.
This can be found on line 29 with the addition of a condition in the condition statement, anchors[i].href != (document.location + ‘#’).
I’ve seen a few other scripts that tracks exit links but some of them I don’t think are very good as they lack error checking and also some of them overwrite the existing onclick attribute which I guess could break the site’s functionality.
Also to prove to you that my script is working, I’ve included a screenshot of the report found in google analytics.
Of course you can click through to the individual links and analyse the dimensions for further analysis. I will be working on more google analytics custom scripts to help bring and enhance more meaningful reports.























November 6th, 2008 at 1:05 pm
Question….
If some of my links are in a javascript will the code still pick up the exit stats from them and register it in analytics? IE: I have a banner on my page that loads random images each of which links to different sites
November 6th, 2008 at 1:31 pm
What do you mean in javascript? You mean they have onclick attributes?
If so, my script should accomodate that. However, if your onclick statement returns false, then it won’t work.
November 6th, 2008 at 1:45 pm
ok here is the script im useing do you think it will work??
<!– Begin
var how_many_ads = 4;
var now = new Date()
var sec = now.getSeconds()
var ad = sec % how_many_ads;
ad +=1;
if (ad==1) {
txt=”";
url=”http://www.example.com.com”;
alt=”banner 1″;
banner=”http://www.example.jpg”;
width=”880″;
height=”120″;
}
if (ad==2) {
txt=”";
url=”http://www.example.com.com/”;
alt=”banner 2″;
banner=”http://www.okinawa-information.com/banners/banner_02.jpg”;
width=”880″;
height=”120″;
}
if (ad==3) {
txt=”";
url=”http://www.example.com.com”;
alt=”banner 3″;
banner=”http://www.example.jpg”;
width=”880″;
height=”120″;
}
if (ad==4) {
txt=”";
url=”http://www.example.com.com/”;
alt=”banner 4″;
banner=”http://www.example.jpg”;
width=”880″;
height=”120″;
}
document.write(”);
document.write(’‘);
document.write(”);
document.write(” + txt + ‘‘);
document.write(”);
// End –>
November 6th, 2008 at 1:58 pm
Txt is always an empty string. And also you don’t need width and height to be set in each if statement. The if statements should have else if instead?
Anyways, that’s besides the point. I’m not quite sure how this relates to javascript links.
November 7th, 2008 at 12:00 pm
How long did it take you before you could track results in Analytics?
November 7th, 2008 at 1:44 pm
Well, assuming that people actually clicked on exit links, it should take 24 hours for it to appear on Google Analytics reports. I guess it depends also when GA updates the data, but from experience it is usually 24 hours.
November 9th, 2008 at 5:48 pm
Danny,
Thanks for all your help, I put a perma link on my Japan Travel Blog that I hope will send some trafic your way. you can check it out at
http://www.blog.japan-travel-information.com/
CHeers and thanks again
November 9th, 2008 at 8:04 pm
No worries mate. Glad I could help :)