Zach
Zach

Reputation: 1185

GA Universal Analytics: Multiple Domains

Using the Universal GA tracking code, I'd like to be able to setup multiple domains for tracking, but only have the main "domain" actually stored/created in GA, as the other domains will be completely variable based on what is pointing to my application. So, based on what I understand from the docs, I have the following:

<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');

  @if ($custom_domain)
    ga('create', 'UA-XXXXXXXX-1', {
      'cookieDomain': '{{ $custom_domain }}'
    });
  @else
    ga('create', 'UA-XXXXXXXX-1', 'auto');
  @endif
  ga('send', 'pageview');

</script>

What I'd like to know is if in the dashboard I'll be able to filter by these separate cookieDomain values so I can get accurate stats based on that domain only. Similarly, I have subdomains as well, which I'll want to make sure I can also poll in the dashboard, but I believe the auto param on the fallback send should take care of that. Thanks for any clarification!

Upvotes: 1

Views: 142

Answers (1)

Eike Pierstorff
Eike Pierstorff

Reputation: 32760

You cannot filter by the cookie domain parameter. That merely determines, well, the cookie domain (i.e. if it's set wrong GA cannot set a cookie an will not track). "auto" already takes care of your use case (it means "set the cookie at the highest possible level of the domain". The best use case is if you want to isolate tracking in a domain from it's subdomains, else "auto" will do fine).

The domain name is automatically captured in the "host name" data field and you can filter using that - you do not need to change the tracking code.

Upvotes: 1

Related Questions