By now I'm sure we've all read and thought about Ilya Grigorik's Script-injected "async scripts" considered harmful. This post walks through a synthesis of that information on the default Universal Analytics snippet:
<!-- Google Analytics -->
<script>
(function(e,t){e.GoogleAnalyticsObject=t;e[t]=e[t]||function(){
(e[t].q=e[t].q||[]).push(arguments)};e[t].l=1*new Date})(t,"ga");
ga('create', 'UA-XXXX-Y'); // REPLACE UA-XXXX-Y w/ YOUR ACCOUNT
ga('send', 'pageview');
</script>
<script async src='//www.google-analytics.com/analytics.js'></script>
<!-- End Google Analytics -->- 1.default.html - Pulled from Introduction to Analytics.js / Tracking Code Quick Start
- 2.jsniced.html - Pulled from Optimizing the Google Analytics Snippet
- 3.refactored.html - Removes async injected parts + dead variables.