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?
- faster tracking code load times
- better data collection and accuracy
- reduction of tracking errors
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:
- Go to the website you wish to check
- Click “View” and select the “View Source” option
In Firefox:
- Go to the website you wish to check
- Click “View” and select “Page Source”
In Chrome:
- Go to the website you wish to check
- Click on the icon of a wrench and select “Tools” and then “View Source”
In Internet Explorer:
- Go to the website you wish to check
- 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:
- Log in to Google Analytics
- Select the profile you are looking to change the code over for
- Click on “Edit” in the far right “Actions” column
- Click on “Check Status” at the top right of the “Main Website Profile Information”
- Select the relevant “What are you tracking checkbox”
- Copy the relevant tracking code
- Replace the old tracking code with the new one
In terms of adding this to your website you should experiment with two placements:
- immediately before the </head> tag
- 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.