Skip to content

Commit

Permalink
Add auto to the GA tracker create method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
philipwalton authored and alrra committed Jul 17, 2014
1 parent 01c5a07 commit c399373
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
### HEAD

* Add `auto` to the Google Universal Analytics tracker create method
([#1562](https://github.com/h5bp/html5-boilerplate/issues/1562)).
* Add `timeline` and `timelineEnd` to the list of `console` methods
([#1559](https://github.com/h5bp/html5-boilerplate/issues/1559)).
* Update to Apache Server Configs 2.6.0.
Expand Down
4 changes: 2 additions & 2 deletions doc/extend.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ snippet](http://mathiasbynens.be/notes/async-analytics-snippet#universal-analyti
included with HTML5 Boilerplate includes something like this:

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

To customize further, see Google's [Advanced
Expand All @@ -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');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
```
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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');
</script>
</body>
</html>

0 comments on commit c399373

Please sign in to comment.