Whilst doing a website review I was pretty surprised to see that the old Google Analytics tracking code was still being used.

Given the benefits of using the newer asynchronous code, switching the tracking code used was pretty high up on our list of recommendations.

Why should you update your tracking code?

Websites that use a lot of scripts or rely on heavy assets (video content, etc) will especially benefit from switching their tracking code.

How do I find out which tracking code I’m using?

In Safari:

  1. Go to the website you wish to check
  2. Click “View” and select the “View Source” option

In Firefox:

  1. Go to the website you wish to check
  2. Click “View” and select “Page Source”

In Chrome:

  1. Go to the website you wish to check
  2. Click on the icon of a wrench and select “Tools” and then “View Source”

In Internet Explorer:

  1. Go to the website you wish to check
  2. Click “View” and select “Source in the browser toolbar

If the website is running Google Analytics then you will find some javascript code that looks like:

a) Old version of tracking code

<script type="text/javascript" src=" http://www.google-analytics.com/urchin.js "></script>

<script type="text/javascript">
_uacct = "UA-xxxxxx-x"
urchinTracker();
</script>

b) Asynchronous tracking code

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();
</script>

If the website is using the older tracking code please follow these steps to switch to the new one:

  1. Log in to Google Analytics
  2. Select the profile you are looking to change the code over for
  3. Click on “Edit” in the far right “Actions” column
  4. Click on “Check Status” at the top right of the “Main Website Profile Information”
  5. Select the relevant “What are you tracking checkbox”
  6. Copy the relevant tracking code
  7. Replace the old tracking code with the new one

In terms of adding this to your website you should experiment with two placements:

  1. immediately before the </head> tag
  2. immediately before the </body> tag

We settled on 2 even if this contravenes Google Analytics advice to use 1. The reason being we just ran into to many errors in Internet Explorer which we haven’t experienced when placing it immediately preceding the </body> tag. Please note that not placing the code preceding the </head> tag will minimise the benefits of more accurate data capture that the asynchronous code is meant to provide.

Once you’ve correctly installed your tracking code, you should allow up to 24 hours for data to appear in your account.

If it has been more than 24 hours since you installed the tracking code and you’re still not seeing any data you can start troubleshooting using this basic help documentation or for more advanced information please refer to troubleshooting the tracking code.

François Roshdy

François is director of user experience at Border Crossing UX. He specialises in helping clients continuously improve the experiences they deliver.