Google Analytics counts visits to all of my subdomains, but lists my subdomains as referrals

I have a website that consists of mydomain.com (and the URLs derived from it, for example mydomain.com/the/rest/), and some subdomains like first.mydomain.com and second.mydomain.com. Right now, I’m using the same Google Analytics code snippet on all pages of the site.

The problem is that Google Analytics shows me mydomain.com and .mydomain.com as referrals, but it seems the visits count for everyone.

So, I have two options: none of them I know how to achieve:

  • Make Analytics understand that mydomain.com and all .mydomain.com are part of the same site, so it does not consider links between them as referrals.

  • Isolate mydomain.com and the entire .mydomain.com file so that I can have statistics for each of them separately.

How can I get each of these parameters and which one do you think is more suitable?

Thanks.

+4
source share
2 answers

Google Analytics, unless otherwise specified, sets its cookies at document.domain . those. he believes that www.foo.com and sub.foo.com are completely separate entities, for all purposes and purposes. While this seems strange, think about co.uk domains or services that sell services in a subdomain.

As a result, cookies set on www.foo.com are not visible when you land on sub.foo.com because they are not set in the correct domain. So Google Analytics says, β€œThis is a brand new visit! And they are being transmitted from www.foo.com

So there are 2 (or 3) solutions.

  • (Best) Implement cross-domain tracking. Basically, ask GA to override the default domain settings. You do this using the _setDomainName directive, which must be declared before for your _trackPageview calls for all domains and subdomains. This will solve the cross-domain tracking issue.

It looks like this:

 _gaq.push(['_setDomainName', 'foo.com']); 

Other less ideal but workable alternatives:

  • You can give them completely different tracking codes. those. track foo.com and sub.foo.com using different accounts.

  • You can save them in one account and create separate filters (filtering by host name in the profile settings for each). This will allow you to share the data, but will not solve your referral problem.

Your best bet is No. 1. This will completely solve the problem of referrals.

+4
source

In GA, under Admin > Tracking Code I recommend double-checking the code that Google generates for you. On the Standard tab, when I selected One domain with multiple subdomains , Google generated this:

 _gaq.push(['_setDomainName', 'foo.com']); 

I needed to go to the "Custom" tab and change the line to look like this:

 _gaq.push(['_setDomainName', '.foo.com']); 
+1
source

Source: https://habr.com/ru/post/1335024/


All Articles