Last active
February 28, 2019 03:54
-
-
Save mundry/11085164 to your computer and use it in GitHub Desktop.
Mathias Bynens' optimized Google Universal Analytics snippet. (See http://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
// Mathias Bynens' optimized Google Universal Analytics snippet. | |
// http://mathiasbynens.be/notes/async-analytics-snippet | |
(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', 'auto'); | |
ga('send', 'pageview'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment