Updated: Tracking Exit Links in Google Analytics

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.

11 Comments on "Updated: Tracking Exit Links in Google Analytics"


  1. 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 :)

    Reply

  2. 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.

    Reply

  3. 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.

    Reply

  4. 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 –>

    Reply

  5. 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.

    Reply

  6. 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

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *