Skip to content
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 Google Analytics snippet to use Universal Analytics (analytics.js) instead of ga.js #1347

Closed
adeelejaz opened this issue Apr 8, 2013 · 23 comments

Comments

Projects
None yet
10 participants
@adeelejaz
Copy link
Contributor

commented Apr 8, 2013

This is probably still open to debate while Google brings analytics.js out of beta but I've tried it on a few websites since it's release and it is pretty amazing in extra info and tools it brings.

It isn't really pretty (may be we can hack it to reduce it's footprint).

More Info: https://developers.google.com/analytics/devguides/collection/analyticsjs/

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXX-Y');
ga('send', 'pageview');
@mathiasbynens

This comment has been minimized.

Copy link
Member

commented Apr 8, 2013

Optimized version here: http://mathiasbynens.be/notes/async-analytics-snippet#universal-analytics (Assumes Firefox ≥ 9)

@necolas

This comment has been minimized.

Copy link
Member

commented Apr 8, 2013

Yeah I saw this over on mathias' blog. Might wait until it's out of beta.

@mathiasbynens We'll probably make sure this works with older versions of Firefox too, so will need to revert the document.scripts change :)

@adeelejaz

This comment has been minimized.

Copy link
Contributor Author

commented Apr 8, 2013

Out of curiosity @necolas, is async issue only with Firefox 3.6 or older versions of Firefox as well?

PS: A few of my clients websites have a significant number of Firefox 2.x and Firefox 3.x users.

@wamatt

This comment has been minimized.

Copy link

commented May 14, 2013

It's well known @paulirish works for Google. IMHO they're a great company, but is it really fair that GA analytics are promoted as default and not Mixpanel, KISSMetrics or other smaller companies etc?

Perhaps there might be an agnostic solution?

@adeelejaz

This comment has been minimized.

Copy link
Contributor Author

commented May 14, 2013

@wamatt The whole idea of boilerplate is to have "most common" piece in place to save time. The second most important element of boilerplate is if you ain't happy with something, rip it out. Feel free to fork the project and change it to your hearts content.

PS: If you haven't noticed, I do not work for Google but I have been using Analytics well before this project came into existence much like thousands out there.

@wamatt

This comment has been minimized.

Copy link

commented May 14, 2013

@adeelejaz sure. I was actually editing my comment to include that acknowledgement. BTW the old "Fork or GTFO" type of dismissal feels somewhat aggressive.

Anyhow, let me explain. There are probably some new users that view the boilerplate as "this is how to get started with HTML5". It's almost has an official context to it, whether that is intended or not.

Where possible it should be corporate agnostic and apolitical, would you not agree?

@roblarsen

This comment has been minimized.

Copy link
Member

commented May 14, 2013

It's true, you've found him out- @paulirish is nothing more than an evil,
money-grubbing corporate shill.

Google Analytics is super popular. Going to something else that no one uses
in order to make a stand that may or may not have any value (I use GA on
about a million sites, so I would vote that moving to something else would
have no value) doesn't really do anyone any good. Instead of adding
appendix code that no one would use and everyone would just delete, the
"take a stand" action would be to have no analytics snippet at all, but
then... we're back to the fact that a lot of people use GA and H5BP should
be doing it's best to help people with common tasks.

On Tue, May 14, 2013 at 7:47 AM, Adeel Ejaz notifications@github.comwrote:

@wamatt https://github.com/wamatt The whole idea of boilerplate is to
have "most common" piece in place to save time. The second most important
element of boilerplate is if you ain't happy with something, rip it out.
Feel free to fork the project and change it to your hearts content.

PS: If you haven't noticed, I do not work for Google but I have been using
Analytics well before this project came into existence much like thousands
out there.


Reply to this email directly or view it on GitHubhttps://github.com//issues/1347#issuecomment-17870956
.

Rob Larsen

DrunkenFist.com http://www.drunkenfist.com/**

HTML + CSS + JavaScript http://htmlcssjavascript.com/**

@adeelejaz

This comment has been minimized.

Copy link
Contributor Author

commented May 14, 2013

@wamatt really? "some new users"? You want to make a point about corporate agnostic and apolitical while taking a stab at @paulirish and his employer?

I have a suggestion for you, next time when you try to raise a point in an open community, please make sure you refrain for personal attacks. We have a lot of contributors on this project. Not all of them get their pay cheques from Google.

As for the "Fork or GTFO", I'm sorry but you just haven't understood the point of this. You fork this project, add a comment above the Analytics snippet about wiki entry explaining alternate options and if you prefer, provide alternate snippets. Once you are happy, send a pull request. Makes sense?

@wamatt

This comment has been minimized.

Copy link

commented May 14, 2013

@roblarsen is the strawman necessary? I don't hold those views about Google or Paul.

@adeelejaz OIC, sorry thought you were suggesting something else. :) Thanks that's a sensible suggestion.

@roblarsen

This comment has been minimized.

Copy link
Member

commented May 14, 2013

c'mon, what else were you insinuating when you said "it's well known Paul works at Google." Anyone with half a brain is going to read that as you insinuating that GA is only in the project because Paul's corporate masters told him to. That's such a "nudge, nudge, wink wink" statement it's laughable. And your feigned ignorance of how people are going to read that is also laughable.

If you don't want people to misinterpret you, don't write in loaded but vaguely conspiratorial terms. Step up and say what you actually mean and then people aren't left to figure it out for themselves (which, as you've seen here, can backfire)

@wamatt

This comment has been minimized.

Copy link

commented May 14, 2013

Furthermore according to Wikipedia, Google Analytics is the most popular analytics program in the world.[1]

If Microsoft Windows happens to be the dominant desktop OS, should software only consider that the use case? Or if Internet Explorer happens to be the most popular browser, should we consider IE specific extensions as sensible? etc.

"Being the most popular" does not seem like a convincing argument.

Sure analytics are useful to beginners, but so is stuff like choosing a webhost or domain registrar. Should we throw that in too?

[1] http://en.wikipedia.org/wiki/Google_Analytics#Popularity

@wamatt

This comment has been minimized.

Copy link

commented May 14, 2013

@roblarsen there was no loading or conspiracy in my language, if you disagree, please feel free to point it out. My only assumption is that it's natural, common and in no way sinister, to have one's company (especially in the tech industry) influence directly or indirectly technology decisions.

I'm friends with a number of Googlers (among other software corporates). They are a great bunch, and often use and promote software that their company makes. For most purposes it's perfectly fine, as it's a cultural thing.

@roblarsen

This comment has been minimized.

Copy link
Member

commented May 14, 2013

I'm clearly not the only one who read it that way. In my reading you couldn't have worded it more provocatively.

FWIW, the GA snippet predates Paul working at Google.

According to Builtwith, GA is on 66% of the top million sites. There's nothing else even close that's also free (most of the other top ten are paid services.) So, as I said, the only viable option if you really believe that having GA here somehow poisons the project is to have no snippet for analytics at all. Adding some random option no one has ever heard of is pointless ("yeah boss, H5BP says use floozylitics, to we're switching from GA") so it's GA (by far the most common and therefore most useful as example code) or nothing. To my mind the nothing option does no one any good. The GA snippet does millions of folks some good as it helps them optimize code they're already using. that's super easy math. Helping millions of people is better than helping no one especially if it's to take a vague (anti-corporate? how does that even work if we then promote some other company?) stand.

@sarukuku

This comment has been minimized.

Copy link

commented May 14, 2013

I don't see how changing from GA to something else or loosing it altogether would benefit most of the boilerplate users. It's simple math as @roblarsen said.

@wamatt

This comment has been minimized.

Copy link

commented May 14, 2013

It's well known @paulirish works for Google. IMHO they're a great company, but is it really fair that GA analytics > are promoted as default and not Mixpanel, KISSMetrics or other smaller companies etc?

Perhaps there might be an agnostic solution?

hmm. Good point. For now GA is by far the largest free analytics suite out there, but I agree in principle that an agnostic solution would be preferable, although it's questionable how that would practically work. Why not submit a pull-request for discussion?

@wamatt

This comment has been minimized.

Copy link

commented May 14, 2013

@roblarsen says:

FWIW, the GA snippet predates Paul working at Google.

I'll take your word on it, so fair enough, that was an assumption on my part.

I do want to point out that it's probably more correct to call GA a freemium service. Heavy usage sites pay a flat rate of $150k per year. Furthermore, an argument can be made that visitor data is used to enhance other commercial product offerings. HTML5 Boilerplate no doubt continues to add to that that popularity.

Also it's quite possible to be prochoice and agnostic, without being "anti-corporate".

Having said all that, there doesn't seem to be an ideal solution. In that case I agree it's probably more useful to have analytics than not, for new users.

@SoonDead

This comment has been minimized.

Copy link

commented May 18, 2013

Google Analytics officially tells you now to use analytics.js if you are setting up a new domain, so it would make sense to include it in the boilerplate instead of ga.js.

(And @paulirish is clearly evil and h5bp is part of a global conspiracy that plays.the whole internet into google's hand by promoting it's analytics script. Pretty diabolical if you ask me.)

@Archie22is

This comment has been minimized.

Copy link

commented May 18, 2013

Guy seriously now, you need to stop it. If you do no like the way the HTML5-boilerplate works, then create your own platform. We can't keep attacking each other like that - it's a free world. If you don't like something that is give to you (for free) then get your own.

#justsaying

@williammalo

This comment has been minimized.

Copy link

commented May 22, 2013

Pro tip: the www isn't required, so you can use "//google-analytics.com/analytics.js" to save 4 bytes!

@mathiasbynens

This comment has been minimized.

@necolas

This comment has been minimized.

Copy link
Member

commented Jun 1, 2013

Does someone feel like putting together a Pull Request for this?

@mathiasbynens

This comment has been minimized.

Copy link
Member

commented Jun 1, 2013

Done in #1369.

mathiasbynens added a commit that referenced this issue Jun 1, 2013

Update to Google Universal Analytics
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.
@alrra

This comment has been minimized.

Copy link
Member

commented Apr 9, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.