homepage-banner

Google Analytics Asynchronous Code Helps Website Tracking & Improves Page Load Time

Google Analytics introduced asynchronous tracking in Dec 2009 as an “alternate way to track your website”. According to Google, this code is processed separately and can execute without blocking other code or content. This allows the Analytics code to be placed higher in the page, unlike the traditional code.

The asynchronous tracking snippet is said to offer the following benefits:

  • Faster overall page load time
  • Improved data collection for short visits to rich media or script-heavy pages
  • Collecting (and retaining) user clicks that occur before the tracking code loads

We decided to test Google’s claim that the new code snippet improves page load time. Here’s what we found.

Problem: To study the effect of using the asynchronous code as against the traditional code on page load time.

Hypothesis: Page load time with the traditional code will be higher (i.e. the page will take longer to load) than with the asynchronous code in all possible placements of the codes.

Limitation: The experiment does not attempt to study the effect of the codes on script-heavy or rich media pages. It also does not attempt to study tracking errors when the script has not fully loaded.

Methodology: Six simple HTML pages were created and tested on a local Apache server. Each page consisted of a single line of text and a Google Analytics code. The only difference between the pages was the version of Google Analytics Code being used and its placement.
Asynchronous Code Experimental Results
The six combinations were:

  1. Traditional/ Synchronous code placed just before the </head> tag.
  2. Traditional/ Synchronous code placed just after the <body> tag.
  3. Traditional/ Synchronous code placed just before the </body> tag.
  4. Asynchronous code placed just before the </head> tag.
  5. Asynchronous code placed just after the <body> tag.
  6. Asynchronous code placed just before the </body> tag.

Ten readings of “page load time” were taken for each page using the Firebug add-on. Browser cache was cleared prior to each reading to ensure that page was not loaded from the cache.

Experimental Results

Code Placement Sync Code Async Code % Improvement
Page Avg Page Load Time (in sec) Page Avg Page Load Time (in sec)
Inside <head></head> Tags S1.html 1.05 A1.html 0.855 18.53%
Just After <body> Tag S2.html 1.175 A2.html 0.847 27.93%
Just Before </body> Tag S3.html 0.838 A3.html 0.839 -0.12%
Overall 1.021 0.847 17.03%

Observations:

  1. Overall, the asynchronous version of the Google Analytics code is faster than Traditional/ Synchronous code by 17.03%.
  2. Placing the asynchronous version in any part of the file, does not significantly change the load time unlike the synchronous version.
  3. Putting the code on top of the page no longer slows the page. This is very important if tracking the click is as important as loading contents of the page. Incomplete page load is a major reason for disparity between GA visits and Google AdWords clicks.

Conclusion:

The overall results support Google’s claim that asynchronous Google Analytics code improves page load time. We recommend that the traditional synchronous code be slowly phased out and the asynchronous code be adopted

This is especially important in paid campaigns where cost per click is being analyzed and where the Google Analytics code should be placed in the header. In today’s internet scenario where users expect to see instant page loads, this is a welcome move by Google

We’ll be testing the other claims that Google makes about its asynchronous page tracking code. Watch out for the next one!

Contributed by Ravi Shukla, Analytics Team

Team Position²

Team Position²

Position2 is an innovative digital marketing agency that accelerates demand through integrated Content Marketing, Paid Acquisition, and Marketing Technology solutions. Our demand acceleration solutions map the buyer’s journey across multiple touch points such as search, social, mobile, media, and email. These integrated campaigns are powered by cutting-edge content creation, digital advertising, web design/development, marketing automation, and analytics. We serve hundreds of clients ranging from VC funded startups to Fortune 500 multinational firms. Our 200-member team is based in Silicon Valley and Bangalore and consists of marketing gurus, engineers, data scientists, writers, and designers. Founded in 2006, Position2 is backed by Accel Partners.