- 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.
- Choose a simple page or website where you want to try the asynchronous tracking code by first time.
- Take a backup of the pages you will modify with the new snippet and then remove any existing tracking code you have in them.
- 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.
- 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']);
- If you want to use event tracking and e-commerce visit the Asynchronous Tracking Usage Guide for more information.