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

Add 'auto' to the Google Analytics tracker create method. #1562

Closed
wants to merge 1 commit into from

Conversation

philipwalton
Copy link
Contributor

Google Analytics supports automatic cookie domain configuration, and this is now officially part of the recommended GA code snippet.

When this parameter is omitted (as it was prior to this pull request), Google Analytics will default to using location.hostname, which will include the subdomain. This prevents websites with multiple subdomains from being able to automatically track unique users across those subdomains.

@@ -159,7 +159,7 @@ parameter](https://developers.google.com/analytics/devguides/collection/analytic
before sending any events/pagviews. In use it looks like this:

```js
ga('create','UA-XXXXX-X');
ga('create','UA-XXXXX-X','auto');

This comment was marked as abuse.

@alrra
Copy link
Member

alrra commented Jul 16, 2014

Cc: @mathiasbynens

@philipwalton
Copy link
Contributor Author

@alrra I can, but it wasn't there before and the space wasn't in any of the other code in the snippet.

@alrra
Copy link
Member

alrra commented Jul 16, 2014

@alrra I can, but it wasn't there before and the space wasn't in any of the other code in the snippet.

@philipwalton The code examples in the docs aren't quite consistent at the moment, so might as well fix that. Thanks!

@philipwalton
Copy link
Contributor Author

@alrra Sure, no problem. Updated.

@@ -33,7 +33,7 @@
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-XXXXX-X');ga('send','pageview');
ga('create', 'UA-XXXXX-X', 'auto'); ga('send', 'pageview');

This comment was marked as abuse.

@alrra
Copy link
Member

alrra commented Jul 16, 2014

Updated.

@philipwalton thanks!

Add 'auto' to the Google Analytics tracker create method

I'm for this addition. :)

@philipwalton
Copy link
Contributor Author

Sorry, yeah I thought that was weird. Updated and squashed to make it easier to compare.

@alrra
Copy link
Member

alrra commented Jul 16, 2014

Updated and squashed to make it easier to compare.

Thank you for being so responsive! 💜

@alrra alrra added this to the 5.0.0 milestone Jul 16, 2014
alrra pushed a commit that referenced this pull request Jul 17, 2014
The Google Universal Analytics now supports automatic cookie domain
configuration simply by adding `auto` to the analytics tracker create
method: `ga('create', 'UA-XXXX-Y', 'auto');`.

From https://developers.google.com/analytics/devguides/collection/analyticsjs/domains#auto:

  "Automatic Cookie Domain Configuration simplifies cross domain
   tracking implementations by automatically writing cookies to the
   highest level domain possible when the auto parameter is used.
   When used on the domain www.example.co.uk, it will try to write
   cookies in the following order:

     1. co.uk
     2. example.co.uk
     3. www.example.co.uk

   Analytics.js will fail to write a cookie on co.uk but will succeed
   on example.co.uk. Since a cookie was succesfully written on a higher
   level domain, www.example.co.uk will be skipped"

So, when this parameter is omitted (as it was prior to this commit),
Google Universal Analytics will default to using `location.hostname`,
which will include the subdomain, preventing websites with multiple
subdomains from being able to automatically track unique users across
those subdomains.

Note: The `auto` parameter is now officially part of the recommended
Google Universal Analytics snippet.
https://developers.google.com/analytics/devguides/collection/analyticsjs/

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Ref: https://developers.google.com/analytics/devguides/collection/analyticsjs/domains#auto
Close: #1562.
@alrra
Copy link
Member

alrra commented Jul 17, 2014

Merged in 4fca586. Thanks again @philipwalton!

@alrra alrra closed this Jul 17, 2014
@philipwalton
Copy link
Contributor Author

You're welcome!

alrra added a commit to use-init/init that referenced this pull request Jul 19, 2014
The Google Universal Analytics now supports automatic cookie domain
configuration simply by adding `auto` to the analytics tracker create
method: `ga('create', 'UA-XXXX-Y', 'auto');`.

From https://developers.google.com/analytics/devguides/collection/analyticsjs/domains#auto:

  "Automatic Cookie Domain Configuration simplifies cross domain
   tracking implementations by automatically writing cookies to the
   highest level domain possible when the auto parameter is used.
   When used on the domain www.example.co.uk, it will try to write
   cookies in the following order:

     1. co.uk
     2. example.co.uk
     3. www.example.co.uk

   Analytics.js will fail to write a cookie on co.uk but will succeed
   on example.co.uk. Since a cookie was succesfully written on a higher
   level domain, www.example.co.uk will be skipped"

So, when this parameter is omitted (as it was prior to this commit),
Google Universal Analytics will default to using `location.hostname`,
which will include the subdomain, preventing websites with multiple
subdomains from being able to automatically track unique users across
those subdomains.

Note: The `auto` parameter is now officially part of the recommended
Google Universal Analytics snippet.
https://developers.google.com/analytics/devguides/collection/analyticsjs/

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Ref: https://developers.google.com/analytics/devguides/collection/analyticsjs/domains#auto
     h5bp/html5-boilerplate#1562
michaelthorne added a commit to michaelthorne/timeline that referenced this pull request Jul 21, 2014
michaelthorne added a commit to michaelthorne/boilerplate that referenced this pull request Jul 21, 2014
eleanor-byhook pushed a commit to eleanor-byhook/html5-boilerplate that referenced this pull request Feb 29, 2016
The Google Universal Analytics now supports automatic cookie domain
configuration simply by adding `auto` to the analytics tracker create
method: `ga('create', 'UA-XXXX-Y', 'auto');`.

From https://developers.google.com/analytics/devguides/collection/analyticsjs/domains#auto:

  "Automatic Cookie Domain Configuration simplifies cross domain
   tracking implementations by automatically writing cookies to the
   highest level domain possible when the auto parameter is used.
   When used on the domain www.example.co.uk, it will try to write
   cookies in the following order:

     1. co.uk
     2. example.co.uk
     3. www.example.co.uk

   Analytics.js will fail to write a cookie on co.uk but will succeed
   on example.co.uk. Since a cookie was succesfully written on a higher
   level domain, www.example.co.uk will be skipped"

So, when this parameter is omitted (as it was prior to this commit),
Google Universal Analytics will default to using `location.hostname`,
which will include the subdomain, preventing websites with multiple
subdomains from being able to automatically track unique users across
those subdomains.

Note: The `auto` parameter is now officially part of the recommended
Google Universal Analytics snippet.
https://developers.google.com/analytics/devguides/collection/analyticsjs/

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Ref: https://developers.google.com/analytics/devguides/collection/analyticsjs/domains#auto
Close: h5bp/html5-boilerplate#1562.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants