18F / analytics-standards

WIP: Team standards for implementing website and API analytics.
Other
9 stars 12 forks source link

Javascript snippet is incomplete - discuss how to fix? #27

Closed jackiekazil closed 9 years ago

jackiekazil commented 9 years ago

This snippet is not incomplete.

Here is a sample default of what google analytics provides:

<script>
  (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-48605964-28', 'auto');
  ga('send', 'pageview');

</script>

Here is what we are asking people to add to that...

ga('set', 'anonymizeIp', true);
ga('set', 'forceSSL', true);

I am thinking we should update it, so that is show an image of what google analytics provides and how to navigate to it, then ask folks to add the items in the second block listed above.

OR

I am thinking that we should update it to show a sample snippet that is complete without the UA code, then tell people where to find the UA code.

Discuss... how should we update?

geramirez commented 9 years ago

This might just be me, but I would rather have something that I can copy easily. So the complete block with the setting we're asking works for me.

konklone commented 9 years ago

That's not quite right -- the README as it stands right now asks people to use this snippet:

(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','https://www.google-analytics.com/analytics.js','ga');

ga('create', '<<UA-CODE>>', 'auto');
ga('set', 'anonymizeIp', true);
ga('set', 'forceSSL', true);
ga('send', 'pageview');

This also includes a tweak to change //www.google-analytics.com/analytics.js to https://www.google-analytics.com/analytics.js.

So @jackiekazil, given that we're changing something about the guts of the snippet, I agree that we should be giving people something to copy and paste. It looks like we are? Or do you recommend we add <script> and <script/> tags around it as well?

konklone commented 9 years ago

I'll also note that it's crucial that ga('send', 'pageview') come last, so just giving people a couple of lines to paste in somewhere is bound to increase the chance of error.

From what I can tell though, I'm already fine with the state of the README.

jackiekazil commented 9 years ago

This is superseded by #28.

konklone commented 9 years ago

Nice!