Friday, January 8, 2010

Asynchronous Tracking Code - Google Analytics

Google Analytics announced a couple of weeks ago the new Asynchronous Tracking Code. Before starting to explain how the new snippet looks like, we would like to tell you why you should use it. When you talk to clients and general users of Google Analytics about installing the tracking code in their sites, some of the concerns that come to mind are:
  • How long time their sites take to be loaded?
  • How many JavaScript functions are they using in their website?
  • How much data I could lost bearing in mind that other JavaScript functions can affect my Google Analytics Tracking Code (GATC)?
  • How much the right execution of the GATC depends of the other JavaScripts installed in the sites?
With the new Asynchornous Tracking Code you no longer have to worry about these issues. Before, the Tracking Code was executed sequentially following the program flow and within the rest of the code included in the website. Using this alternative the tracking code will be executed independently, which means that it does not affect the execution of other processes being processed to load the page correctly.

If you are using heavy custom scripts that makes your website slow to load, you have a site with rich media content and long data or you just want to improve the accuracy of your data collection? Then, we recommend you to migrate from the traditional tracking code snippet to the asynchronous one. It is just an option, you can continue using your traditional tracking code, but you can get lots of benefits with the asynchronous snippet. The next are some of the benefits listed by Google Analytics:

• Faster tracking code load times for your web pages due to improved browser execution
• Enhanced data collection and accuracy
• Elimination of tracking errors from dependencies when the JavaScript hasn't fully loaded

Now, that you know why using the Asynchronous Tracking Code is a good idea, lets have a look to the changes in the snippet and the steps you should follow to do the migration.



Yes, I know, it looks very different, but don't worry, after you finish reading this post you will be able to make the migration and understand how does it work compared to the traditional snippet. We have highlighted the most important change in the snippet, which are related to the initialization of the page tracker object and the call to the trackPageview method.

First of all, for the traditional tracking code we use the variable _gat and for the asynchronous _gaq. Both of them are global objects and perform similar functions but are called different. Secondly, in the traditional form, we declare a variable pageTracker and we initialize the page tracker object using the method _getTracker, which has as parameter the web property ID (Account to track). Subsequently we call the method _trackPageview which extracts the cookie values from the URL, and create or update the document object.

In the asynchronous tracking snippet we create a global variable _gaq, which will call the method push but with different parameters. The mothod push is used in the new tracking snippet to execute the commands passed as parameters, where the each parameter is an array of commands. The first time we call push we pass the array ['_setAccount','UA-XXXXX-YY'] to set the account, and the second time we call push we pass the array ['_trackPageview']. What we can see until here? well, comparing the traditional and asynchronous snippets we can figure out that in each array passed as parameter to the function push, the first element of the command array is the method we want to execute and the rest are the parameters for that method. For instance, UA-XXXXX-YY is the parameter for _setAccount and_trackPageview in the standard mode doesn't have any parameters.

The methods used above are for the simplest or standard use of the tracking code; however, all the functions available in the traditional tracking code can be implemented with the asynchronous snippet. You only need to pass to the method 'push' the right command arrays. For example, if you are using cross-domain or tracking multiple domains you could pass as parameter to the push method ['_setDomain', 'none'] and ['_setAllowLinker', true], which would be equivalent to pageTracker._setDomainName('none') and pageTracker._setAllowLinker(true) in the traditional snippet.

We know that most of you are already using the GA with other tools such as Website Optimizer. Don't worry you can continue using them with asynchronous snippet. The next is an example of Asynchronous GATC with GWO for a multivariate experiment.



Although we could show you hundred of examples showing the equivalent functions between the traditional and the asynchronous snippets, we have decided to give you a brief description and idea of the benefits you will get with the asynchronous tracking code as well as some tips in case you decide to install it.

By experience, the easiest scenario is if you don't have installed any Google Analytics Tracking Code (GACT). In that situation you just have to put the asynchronous tracking snippet shown above at the bottom of the head tag in your website. However, if you have installed GACT already, we suggest to follow the next recommendations or tips to be sure that the migration is performed successfully.
  1. Choose a simple page or website where you want to try the asynchronous tracking code by first time.
  2. Take a backup of the pages you will modify with the new snippet and then remove any existing tracking code you have in them.
  3. Forget about placing the GACT at the end of your web page (before closing the tag) because the Asynchronous will be installed at the top of the page, just after the head tag. If you have more calls to scripts included in the head section, put the tracking code as the last script in that section.
  4. Because of the function push is used all the time, you could simplify the code, passing several command arrays in the same call to the push function. e.g _gaq.push(['_setAccount', 'UA-XXXXX-X'],['_setDomain', 'example.com'],['_trackPageview']);
  5. If you want to use event tracking and e-commerce visit the Asynchronous Tracking Usage Guide for more information.
I hope you can start using the asynchronous tracking code, and enjoying the benefits of this.

Wednesday, January 6, 2010

2009: A Year To Remember?

After all, yes. 2009 it's a year we will not forget specially for those like me that became immersed in the world of Web Analytics. Different vendors were really busy during 2009 trying to provide the best for their clients and to beat competition. I recog the hard work done for most of them bearing in mind the fast changes in Web Analytics trends.

Let's see which features where launched in 2009 from some of the biggest vendors.

Google Analytics
  • Track Google Site
  • Integration of AdSense and GA
  • Integration of Google Ad Planner and GA
  • Share custom reports and advanced segments
  • Advanced Segments for Event Tracking
  • Google Analytics Export API
  • Increase number of Goals and new Goal Types
  • Expanded Mobile Reporting
  • Advanced Table Filtering
  • Unique Visitor Metric
  • Multiple Custom Variables
  • Analytics Intelligence Report
  • New Asynchronous Tracking Code
  • Annotations
To see more information about it, last 31st of December the Official Google Analytics Blog posted a month by month breakdown of new features launches from 2009, being the last quarter of the year the one with more significant features launched.

WebTrends
  • Social Media Measurement
  • Multivariate Testing
  • Analytics 9 that came with Annotations, real-time update for key metrics, and streamlined graphics.
  • WebTrends Self Service Access and Collection API
  • Mobile Measurement
Coremetrics
  • Campaign Cloning feature
Omniture
  • Social Media Measurement with the SiteCatalyst Extension
  • Twitter tracking application
  • Omniture SiteSearch
After a complete year of changes and introduction of great features, what most of the vendors coincide is that 2010 comes with new needs to measure our online marketing and websites performance based on Social Media and Mobile Tracking.