Written by Brian Cray on December 20th, 2009
What happens to your Google Analytics if someone leaves the page before it has fully loaded? The page view doesn't get recorded and Google Analytics fails as an accurate source of user data.
Asynchronous Tracking for Google Analytics
"Even if [a] button is clicked before the browser has finished loading ga.js, the event will be captured and eventually executed. Using traditional tracking, the browser might throw an exception in this situation."
While this quote refers to event tracking, I believe it applies to any of Google Analytics' tracking methods, including page views.
Google Analytics Asynchronous Tracking works by queuing up tracking commands for execution when the analytics script finishes loading. Since the Asynchronous Tracking code is put in the <head> of an HTML document, it will always finish loading in time.
Comparing traditional vs. Asynchronous Tracking code
Traditional tracking code for Google Analytics
- Goes at the end of an HTML document, before
document.writeto insert script
- Doesn't capture events before page load
Asynchronous Tracking code for Google Analytics
- Goes at the beginning of an HTML document, before
- Uses a DOM injection to insert script (geeks should like that one)
- Captures events prior to page load
Begin using Google Analytics Asynchronous Tracking today
I became aware of Asynchronous Tracking thanks to this article on Web Resources Depot, and I've been using it since. So far there have been no issues with tracking or loading times. In fact, there seems to be improvements in load times and reporting.