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.
The six combinations were:
- Traditional/ Synchronous code placed just before the </head> tag.
- Traditional/ Synchronous code placed just after the <body> tag.
- Traditional/ Synchronous code placed just before the </body> tag.
- Asynchronous code placed just before the </head> tag.
- Asynchronous code placed just after the <body> tag.
- 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.
|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, the asynchronous version of the Google Analytics code is faster than Traditional/ Synchronous code by 17.03%.
- Placing the asynchronous version in any part of the file, does not significantly change the load time unlike the synchronous version.
- 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.
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