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.
UPDATE:
The statistics seem to be picked up by Analytics now. I’m not sure exactly how this is working as the links don’t have an attached Onclick event, so I guess it’s JS magic :)
That’s great. Let me know how it goes along.
Yes, javascript applies an onclick event on all exit links.
Hi Danny,
is this script supposed to add an onClick event in the link? If this is the case, I can’t seem to get it working. Please have a look on this page and let me know if it looks ok to you: http://tomorrowsdate.com/date/detail/bondi_openair/
Thanks!
Marko
No worries mate. Glad I could help :)
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
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.
How long did it take you before you could track results in Analytics?
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.
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 –>
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.
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