Update on Tracking JavaScript Redirects

In a previous post (Track Redirects in Analytics), I gave a couple of examples on how you can track redirects using Google Analytics.  One of these methods was to implement a JavaScript redirect after you run your Google Analytics tracking JavaScript.  This way the redirect runs after the page has tracked a visit (and the visit will show up in your Content section in Analytics).

Someone pointed out that, having tried this, they noticed that not every redirect was tracking, and that it was likely that the page was sometimes redirecting before the Analytics JavaScript was being completely run.  So I decided to run a test with the help of some co-workers.

Testing with a Delay

We created two JavaScript redirect pages with the Analytics tracking running before the redirect.  However, one of the pages had a time delay of one second.  8 of us visited both redirecting URLs.  Sure enough, the page with the one second delay showed 8 visitors.  The page with no delay showed 4.  So half of the visitors weren’t tracked when no delay being implemented.  So it would appear that a redirect with no time delay doesn’t always allow for enough time for the Analytics tracking to run.

The lesson here is; if you’re going with the JavaScript redirect option, you’ll want to use a one second delay in order to track visitors correctly.

Related Posts:

Track Redirects in Analytics

7 thoughts on “Update on Tracking JavaScript Redirects”

  1. Hi there

    Thanks a lot for this post!

    I was trying to track traffic on a redirecting page. I tried it with a php-redirect after the analytics tracking code, adding a delay. Still, i could not find any data in the analytics’ content section.

    I’m currently trying to do the redirect with a java script as described in your post. However, since there is no code-example in this post, here is what i wrote (placed beneath the GA-tracking code):

    window.setTimeout (‘redirect_to (“http://www.mylandingpage.com”)’, 3000);

    function redirect_to (destination) {
    window.location.href = destination;
    }

    Should this work or what would you suggest?

    Thank you very much!

  2. Hello,

    I am not a Javascript guru so I won’t be able to answer your question in depth. However, here are some snippets from the type of javascript redirect our developers are using, which are tracking just fine in Analytics,

    In the body tag…

    body onLoad=”setTimeout(‘delayedRedirect()’, 1000)”

    Then, after the Analytics tracking, inside javascript tags…

    window.location = “http://www.urltoredirecttohere.com”

    Let me know if this helps.

Leave a Comment