How To Set Up Google Analytics Asynchronous Tracking Code For Faster Page Load Time

Google Analytics Asynchronous Tracking Code is an improved snippet of JavaScript that loads the ga.js tracking code in the background while other scripts and content continue loading on your website pages.  With the asynchronous snippet, you will have the following benefits:

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

Copy and paste the snippet below to just before the closing </head> tag section of your web page:

<script type=”text/javascript”> 
 
  var _gaq = _gaq || []; 
  _gaq.push(['_setAccount', 'UA-XXXXX-X']); 
  _gaq.push(['_trackPageview']); 
 
  (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’; 
    var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s); 
  })(); 
 
</script>

You should replace UA-XXXXX-X in the code above with your own Google Analytics web property ID e.g. ‘UA-4711878-1′. Login to your Google Analytics account to check the tracking status of your website. If it is receiving data, then it works. If it is not receiving data, then you should check your code again.

Google Analytics Tracking Status

Google Analytics Tracking Status

For existing web pages, first remove the older tracking snippet at the bottom of your page, just before the closing </body> tag  and replace it with the asynchronous snippet at just before the closing </head> tag section of your web page.

This entry was posted in Analytics, SEO and tagged , . Bookmark the permalink.

Leave a Reply