Last active
December 18, 2015 05:59
-
-
Save lilianchisca/5736441 to your computer and use it in GitHub Desktop.
Optimizing the asynchronous Google Analytics snippet: mathiasbynens.be/notes/async-analytics-snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
(function(window, document, variableName, scriptElement, firstScript) { | |
window['GoogleAnalyticsObject'] = variableName; | |
window[variableName] || (window[variableName] = function() { | |
(window[variableName].q = window[variableName].q || []).push(arguments) | |
}); | |
window[variableName].l = +new Date; | |
scriptElement = document.createElement('script'), | |
firstScript = document.scripts[0]; | |
scriptElement.src = '//www.google-analytics.com/analytics.js'; | |
firstScript.parentNode.insertBefore(scriptElement, firstScript) | |
}(window, document, 'ga')); | |
ga('create', 'UA-XXXX-Y'); | |
ga('send', 'pageview'); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(G,o,O,g,l){G.GoogleAnalyticsObject=O;G[O]||(G[O]=function(){(G[O].q=G[O].q||[]).push(arguments)});G[O].l=+new Date;g=o.createElement('script'),l=o.scripts[0];g.src='//www.google-analytics.com/analytics.js';l.parentNode.insertBefore(g,l)}(this,document,'ga'));ga('create','UA-XXXX-Y');ga('send','pageview') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment