GA Code is Slowing Down Website

GA Code is Slowing Down WebsiteFast page load times are vital for websites. Internet users have a notoriously short attention span, and will leave if a site takes more than a few seconds to load. Before placing additional code onto a website, it’s important to determine whether that will effect page load times negatively.

If Google Analytics tracking code doesn’t load before a visitor leaves the site or clicks away from the page, the page data won’t show up in Google Analytics. You can compensate for this scenario by running web log analysis software in conjunction with Google Analytics.

Does Google Analytics Code Slow Down My Site?
There are two components to consider: the amount of time it takes to download external files (connection speed) and the amount of time it takes for your browser to process JavaScript (processor speed).

The Google Analytics tracking code works by first requesting a file named ga.js from Google’s servers. This file defines a series of JavaScript methods, grabs visitor data and creates cookies on the user’s machine. This file doesn’t change very often, so browsers cache it. In other words, it isn’t requested with every visit to every site, let alone with every pageview.

Next, the code requests a 1×1 transparent image named __utm.gif. It attaches information in the query string of this file, and that’s how it sends information to Google Analytics. This file is requested with every pageview, but it is 35 bytes. Small enough to be insignificant, regardless of what speed your Internet connection is. It might take 1/100 or 1/50 of a second to load.

With previous versions of Google Analytics, Google recommended placing the tracking code at the very end of the body just before the closing tag. This way, in the chance that there were any delays with Google’s servers or (more likely) with the visitors’ device, the rest of the page would still display normally. This has been alleviated with asynchronous tracking code.

“Waiting for”
Some have noticed on slow-loading pages that the status message in their browser sometimes says “Waiting for”. This only happens on sites that run an ancient version of the Google Analytics tracking code!

If you are still concerned that Google’s tracking code that is slowing down your pageload times, you can try a few things to test its impact:

  • Use Google Webmaster Tools to identify and fix slow-loading components of your website
  • Make sure you’re using the current version of the ga.js snippet
  • Move the code to the very bottom of the page, if you haven’t already
  • Move another code just after the tracking code to see if it shows up in the status bar instead
  • Delete or optimize other large files, like css files and images, to see what impact they are having
  • Host the ga.js and __utm.gif file locally and execute the _setLocalServerMode() method. This goes through the same process as normal, except it requests the __utm.gif file locally instead of from Google’s servers. (This also means that no data will be sent to your Google Analytics account during the test.)