The new Analytics Tracking Code has the latest asynchronous syntax. With this version of tracking code, you can place the Analytics snippet higher in the page without delaying subsequent content from rendering.
ga.js into the page. To use this on your pages, copy the code snippet below, replacing
UA-XXXXX-X with your web property ID. Paste this snippet into your website template page so that it appears before the closing
</head> tag. The
_gaq object is the thing that makes the asynchronous syntax possible. It acts as a queue, which is a first-in-first-out data structure that collects API calls until
ga.js is ready to execute them. To add something to the queue, use the
_setAccount method has been added to provide this capability. All the other tracker object methods are the same in both asynchronous and traditional tracking with just the syntax being different.
In addition to command arrays, you can also push function objects onto the
_gaq. This technique is useful for calling the tracking APIs that return values. If you prefer to put the Analytics snippet at the bottom of the page, you should know that you don’t have to put the whole snippet at the bottom. You can still keep most of the benefits of asynchronous loading by splitting the snippet in half and keeping the first half at the top of the page and moving the rest to the bottom. Because the first part of the tracking snippet has little to no effect on page rendering, you can leave that part at the top and put the part of the snippet that inserts
ga.js at the bottom.
This is a simple overview of the newly implemented tracking code and there are still much more in depth descriptions on each function. However, before it is looked over, there are some things to watch out for. There are common mistakes that can occur, such as people forgetting that method names are case-sensitive, entering the wrong method name (possibly due to a typo), not realizing that only strings should be passed with quotes, and not knowing that strings cannot contain leading or trailing whitespace.
The new implemented tracking code is a great bonus to the Analytics page.