Quick tip: Converting to new Google Analytics asynchronous tracking code

I show you how to migrate your old Google's Analytics tracking code and convert it into the new asynchronous code.

Quick tip: Converting to new Google Analytics asynchronous tracking code

 

If you use the Google Analytics software package you may have noticed that they've recently launched a new version of the tracking code which uses asynchronous JavaScript to improve the performance and accuracy of the data collected.

As with any change however, there is a small amount of pain involved. In this case the pain is that Google has asked developers to conform to new code requirements and an alteration of the syntax required to get Analytics running on a web page.

Whilst these changes are relatively simple and well documented, I've decided to write a mini-guide to help you upgrade the various parts of your Analytics installation to run with the new code.

Step #1 - Remove the old Analytics Snippet and insert the new code

First you need to completely remove the old Tracking Snippet (the bit that causes Analytics to start tracking data on your website) from your website.

  • Find the old snippet (usually the last item before the closing body tag)
  • Make a note of the "Web Property ID"
  • Delete the code from your markup.
Insert the New Anaylitcs Snippet
  • Copy the new tracking snippet from Google's docs
  • Replace "UA-XXXXX-X" with your own "Web Property ID"
  • Paste as the last item before the closing HEAD tag in your web page.

It's worth noting that to help improve page rendering times, Google previously  recommended placing the traditional tracking snippet as the last item before the closing BODY tag on your page. However, as the new code is asynchronous we no longer need to worry about this.

Therefore, Google now suggests you insert the new code at the bottom of the <head> section of your web page.

Step #2  - upgrading your "_trackPageView" goal tracking code

For those of you using "_trackPageView" to track goal data for items that don't generate pageviews you'll also need to update your code.

Luckily that's relatively easy as it's fairly similar and is certainly recognisable.

After you've sucessfully completed Step #1 and verified everything is working, all you need to go is change the code from:

onClick="javascript: pageTracker._trackPageview('/goal/brochure-download');"

to

onClick="_gaq.push(['_trackPageview', '/goal/brochure-download']);"

Simple really.

I hope this makes someone's life a little easier. If you need more detailed information I suggest Google's extensive documentation.

Grow your business

Find out how Deep Blue Sky can grow your business.

  1. Digital benchmark
  2. Digital roadmap
  3. Digital engineering

Write a comment.

Responses. (1)

  1. C H

    Clare

    Thanks

    Just a clear description helps in comparison to all the extensive guides! Thanks for posting