Tuesday, January 26, 2010

Google Analytics - Faster new Asynchronous Analytics Tracking

Google have announced a new Asynchronous Tracking script for Analytics. The new snippet decreases a webpage's loading time over the previous urchin/script as it is inserted higher up the page source thus not slowing down the page load on the client side (rendering). This is a nice feature as the Google Analytics code can add significantly to the time between page download (request) and the time it takes for the user to see the page (rendered).

New Script example:

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);

(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';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);


Read more here: http://code.google.com/apis/analytics/docs/tracking/asyncTracking.html

No comments:

Post a Comment