Asynchronous Google Analytics snippets (v15)

Revision 15 of this benchmark created on


Description

Test case which measures the speed difference between the default asynchronous Google Analytics snippet and the optimized version.

Note that I commented out the s.parentNode.insertBefore(g, s); line in both scripts, since otherwise the <script> element gets inserted a few thousand times every time you run the tests. Since this code is the same in both scripts, it shouldn’t have an influence on the results.

Test runner

Ready to run.

Testing in
TestOps/sec
Default snippet
<script src="astracker.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-38055826-3']);
  _gaq.push(['_setDomainName', 'cuongvumarketingseo.com']);
  _gaq.push(['_setAllowLinker', true]);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
<script type="text/javascript">
window.google_analytics_uacct = "UA-38055826-3";
</script>
<!--TagGoogle  Tracking Code -->
<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') + 
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>

<div id="adcontainer1"></div>
<script src="http://www.google.com/adsense/search/ads.js" type="text/javascript"></script> 
<script type="text/javascript" charset="utf-8"> 
var pageOptions = { 
  'pubId': 'pub-0165032035117805',
  'query': 's',
  'adstyle': 'hm',
  'hl': 'en'
};

var adblock1 = { 
  'container': 'adcontainer1',
  'width': '700px'
};

new google.ads.search.Ads(pageOptions, adblock1);
</script>

<!-- Yahoo! Web Analytics - All rights reserved -->
<script type="text/javascript" src="http://d.yimg.com/mi/ywa.js"></script>
<script type="text/javascript">
/*globals YWA*/
/*globals window*/
try {
var YWATracker = YWA.getTracker("10001802432762", "US");
//YWATracker.setDocumentName("");
//YWATracker.setDocumentGroup("");
YWATracker.submit();
} catch (eYWATCUnavailable) {
if (window.console && window.console.warn) {
window.console.warn(eYWATCUnavailable.message || "Unknown error");
}
}
</script>
<noscript>
<div><img src="http://a.analytics.yahoo.com/p.pl?a=10001802432762&js=no" width="1" height="1" alt="" /></div>
</noscript>
<script type="text/javascript">
  GS_googleAddAdSenseService("ca-pub-0165032035117805");
  GS_googleEnableAllServices();
</script>
<script type="text/javascript">
  GA_googleAddSlot("ca-pub-0165032035117805", "ads_pages-468x60");
  GA_googleAddSlot("ca-pub-0165032035117805", "adsense right-300x250");
  GA_googleAddSlot("ca-pub-0165032035117805", "Large Right Page-300x600");
  GA_googleAddSlot("ca-pub-0165032035117805", "Leaderboard (728 x 90) banner-728x90");
  </script>
<script type="text/javascript">
  GA_googleFetchAds();
</script>
ready
Optimized snippet
var _gaq = [['_setAccount', 'UA-XXXXX-X'], ['_trackPageview']];
(function(d, t) {
 var g = d.createElement(t),
     s = d.getElementsByTagName(t)[0];
 g.async = 1;
 g.src = '//www.google-analytics.com/ga.js';
 // s.parentNode.insertBefore(g, s);
}(document, 'script'));
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.