JavaScript advice

Reading Time: 2 minutes

JavaScript for Dummies There’s a good post over on Avinash’s blog with 9 tips for getting JavaScript tagging right on your website. There’s not much for me to add except to say that you should click the link above and read his advice; but I do have one thing to add about redirects (point 7 in Avinash’s post).

If you’re using redirects in your site, you have two options:

  1. Ignore (don’t capture) the redirect
  2. Capture the redirect as a ‘valid’ page impression

When might you want to choose one or other of these options? Well, you would choose no. 1 when you’re using redirects internally, for example (as in Avinash’s example) if you’re using an ad platform to serve internal ads – the ad platform usually demands you redirect the click so that you get measurement within the ad platform (this is what we’re doing on In your main web analytics data stream, you don’t want loads of extra ‘pages’ popping up that are odd URL formats and are going to throw your numbers out. So in this case, use a server-side redirect (e.g. 301) which will automatically re-point the browser without an actual page-load happening on the client.

You want to capture the redirect happening in the instance when you’re tracking outbound (off-site) clicks – for example to affiliates. In this case you want to use a redirect which actually serves a real page and then (probably) uses JavaScript to redirect the browser. The advantage with this method is that you capture the click before the user leaves the site and is lost for ever. The only problem with this is that the outbound redirect page looks like a real page impression, which isn’t really true. If you were trying to get your numbers audited you’d get spanked.

A refinement of method 2 is to use a web analytics tool which you can redirect the outbound click through – that is, then vendor provides a mechanism where you can direct users to a URL on their domain which then redirects to the URL that you really want (which may or may not be one of yours). This is how the ad-serving companies capture click information. I think Omniture does this, and I know some others (e.g. NedStat’s SiteStat product) do too. In this instance the web analytics tool handles (and logs) the redirect; savvy tools can then report this information separately without it polluting the main page impression counts.

The only other thing to add is that the tool that Avinash references that Omniture uses to track tag coverage and deployment is (I believe) Maxamine. The folks at Maxamine are great; if you’re running tag-based data collection over a large ad complex site, you should give them a call.