How to upgrade your Google Analytics code

Here’s one for those of you who are happy to entertain thoughts of the code behind your website, and who run Google Analytics. For everyone else, here’s today’s Dilbert cartoon.

If you run Google Analytics, every page on your website will have an additional bit of code added to it. It’s nothing you can see, unless you look at the source code behind the page. Some time back, Google introduced new code, which works a lot better than the old one, but it did mean you have to change the existing code, so many website owners didn’t bother. There are some good reasons for changing, however, so I’d recommend seeing if you still need to do this, and if you do, to get it done. If you have a template-driven website, or are running under a content management system, it should be a 5-minute job for your website manager.

To check if you’re still running the old code, have a look at the source of any page on your site (right-click on the page and “View Source”). Finding the Google Analytics code is quite tricky, but search for “UA-” (which is the start of your account number) using the “find” facility. If you’re using the old code, it’ll almost certainly be found at the end of the page code, in a line like this:
var pageTracker = _gat._getTracker(“UA-XXXXX-X”);
…or this:
_uacct = “UA-XXXXX-X”;

If you have the new code running, it’ll be towards the top of the page code, and will look like this:
_gaq.push([‘_setAccount’, ‘UA-XXXXX-X’]);

As I mentioned, changing the code isn’t difficult for any competent website designer or manager. The rather dry instructions from Google are here and there’s a better guide to finding and installing the new code here. The old code, to be removed, consists of the half a dozen lines of code containing one of the lines shown above, starting and finishing with a “script” tag.

Check back the next day to see if the new code has been installed correctly and is recording traffic. Not only is it more efficient, but it’ll give you access to things like the Site Speed Report and possibly even more features in the future.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.