Get Free Quote

Google Analytics Tracking Code and Page Speed

by Sean James, August 16, 2010

For years, webmasters were concerned that the Google Analytics tracking code (known as ga.js) was slowing down their websites. As we know, on the Web, time is money. Improving your page load time is becoming a vital factor in the ROI of your website. Bounce rate, time on site, rankings, operating costs and conversions have all been cited as factors that can be affected positively by reducing your site load time. Speed, in general, is a driving force behind Web 2.0 and the rising number of media-rich websites.

Google's recent push to speed up the Internet via Caffeine and algorithm updates placed page load time at the forefront when making improvements to its Analytics tracking code. We are now on the third generation of tracking code for Google Analytics, with the release of the asynchronous tracking code in May.

To understand more about the new Google asynchronous tracking code versus the old ga.js code, let's take a look at how they both work. You'll also find out how to perform the new Google Analytics setup and install Google Analytics' new code.

Former Google Analytics Tracking Code: ga.js

Google Analytics logo

Webmasters' concerns about the former Google Analytics tracking code were legitimate; the traditional ga.js code was proven to slow page load times. It worked by downloading a fairly large JavaScript library, and while the library downloaded, nothing else could happen on the page. Think of the initial download and JavaScript execution on a Web page as a data pipeline. The user can't interact with the page until that the data is read completely (reaching the end of the pipeline).

Under the old system, the Google Analytics tracking code could block that pipeline from fully executing; therefore, inaccurate Analytics data was commonplace. That's why it was considered a best practice to install the old tracking code at the bottom of the HTML code. At the bottom, it was the last thing to load and it would not slow down the rest of the page.

New Google Analytics Tracking Code: Asynchronous

The new asynchronous tracking code for Google Analytics takes advantage of the modern browser's AJAX capability (AJAX is shorthand for asynchronous JavaScript and XML, and allows scripts to run asynchronously on the Web). The new tracking code runs in a separate pipeline, therefore maintaining an open channel.

This means there isn't a "blocking" period between the time a link is selected and the time it's ready for a user to start interacting with it. So there isn't any download latency when the tracking code is executed.

With the release of the new Google asynchronous tracking code in May, best practices now call for the tracking code to be inserted closer to the top of the page. By placing the code higher in the page, it can decrease bounce rate because the script executes faster. The new asynchronous execution of JavaScript coupled with the recommendations for placement has proven to decrease data inaccuracies by as much as 5 percent in some tests by Google Analytics-certified partners.

Install Google Analytics' Asynchronous Tracking Code

Sitewide improvement of page load times is a compelling reason to make the switch from the old Google Analytics tracking code to the new code. For the Google Analytics setup of the new asynchronous tracking code, follow these steps to install Google Analytics' snippet below:

  • Remove the existing tracking code and customizations from your site.
  • Install the code. Google suggests most installations of the asynchronous tracking code be at the bottom of the Head section, just before the </head> tag. Although, some reports suggest page load time varies with the placement of the code. Search and social media company, Position², posted test results in April that showed variations in page load times with placement either inside the Head tags, just after the <body> tag or just before the </body> tag. [Source]
  • Then, change the _setAccount method to your Web property ID.
  • Reinstall customizations back in the asynchronous syntax.

The following snippet is the JavaScript code for the new Google Analytics tracking code. For more detail on how to install the code, see migration instructions and installation instructions on Google's website:

<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>

Full Speed Ahead

Site speed optimization cannot be considered an afterthought anymore; it has to be a priority. Google is on a mission, and if you're not with 'em, essentially, you're against 'em. In other words, if you're not willing to be a part of Google's initiative to make the Internet faster for its users, then eventually, your website may not reap the rewards from Google.

Every little bit you can do to improve your site's speed is important. Google officially stated that page load time is now one of more than 200 variables that influence ranking in the search engine. In addition to implementing the Google asynchronous tracking code, tap into free tools such as the Google Page Speed tool to improve the latency of your websites.

A word of advice: Pay close attention to what Google is saying, not just in its official statements but also its casual mentions, its services, its patents on potential services and so on. Learn to decipher the elusive Google speak and you'll have a better understanding of where search is headed and how to prepare your site for the future.


For permission to reprint or reuse any materials, please contact us. To learn more about our authors, please visit the Bruce Clay Authors page. Copyright © 2010 Bruce Clay, Inc.