-
Notifications
You must be signed in to change notification settings - Fork 12.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to Google Universal Analytics #1369
Conversation
This is an optimized version of the official Google Universal Analytics snippet, based on http://mathiasbynens.be/notes/async-analytics-snippet. The only difference is that this version still uses `document.getElementsByTagName('script')[0]` instead of `document.scripts[0]` for Firefox < 9 support. Unminified, optimized code: (function(window, document, script, 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.getElementsByTagName(script)[0]; scriptElement.src = '//www.google-analytics.com/analytics.js'; firstScript.parentNode.insertBefore(scriptElement, firstScript) }(window, document, 'script', 'ga')); ga('create', 'UA-XXXX-Y'); ga('send', 'pageview'); Minified: (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;e=o.createElement(i);r=o.getElementsByTagName(i)[0];e.src='//www.google-analytics.com/analytics.js';r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));ga('create','UA-XXXX-Y');ga('send','pageview'); Closes #1347 and #1369.
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0]; | ||
g.src='//www.google-analytics.com/ga.js'; | ||
s.parentNode.insertBefore(g,s)}(document,'script')); | ||
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]= |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
#shipit from me |
Integrated and tested with CSS Modal. Works great for me. |
This is an optimized version of the official Google Universal Analytics snippet, based on http://mathiasbynens.be/notes/async-analytics-snippet. The only difference is that this version still uses `document.getElementsByTagName('script')[0]` instead of `document.scripts[0]` for Firefox < 9 support. Unminified, optimized code: (function(window, document, script, 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.getElementsByTagName(script)[0]; scriptElement.src = '//www.google-analytics.com/analytics.js'; firstScript.parentNode.insertBefore(scriptElement, firstScript) }(window, document, 'script', 'ga')); ga('create', 'UA-XXXX-Y'); ga('send', 'pageview'); Minified: (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;e=o.createElement(i);r=o.getElementsByTagName(i)[0];e.src='//www.google-analytics.com/analytics.js';r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));ga('create','UA-XXXX-Y');ga('send','pageview'); Closes #1347 and #1369.
Merged. Thanks for reviewing! |
Hey guys, I'm having issues with this new snippet. Google's beta page for this says
What does it mean to create a new web property? Should existing users be using both the old and now current GA code? |
@asuh It means create a completely new property for your site from within Google Analytics admin tab, it'll then give you the option of using the analytics.js as the script. You'll receive a new property ID to use too (probably the same as your previous ID but with -2 affix instead of -1) So the option is there to also keep your old property running untouched on the older ga.js and old property ID - for historic reasons - if you want. |
@philwareham Thank you for explaining this to me. It wasn't obvious and I was left confused. Considering this new technique, is there any reason why someone should run both the current and beta code at the same time for tracking? Essentially, creating a new property ID and implementing this code abandons the GA with all the stats and info and starts the new one from scratch. Or am I missing something? |
This is an optimized version of the official Google Universal Analytics snippet, based on http://mathiasbynens.be/notes/async-analytics-snippet#universal-analytics. The only difference is that this version still uses
document.getElementsByTagName('script')[0]
instead ofdocument.scripts[0]
for Firefox < 9 support.Unminified, optimized code:
Minified:
Closes #1347 and #1369.