Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I need to setup a Google Analytics code for one website with multiple domains, but they are in form of

subdomain.**foo**.com
subdomain.**bar**.com

Subdomain is the same (it doesn't really matter that much), but main domains are differents. So now I use:

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

and

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

is this correct?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

On foo.com you use

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

and on bar.com you use

_gaq.push(['_setDomainName', 'bar.com']);
_gaq.push(['_setAllowLinker', true]);

This includes Subdomains (whatever).foo.com and (whatever).bar.com.

If you want to link from ().foo.com to (.).bar.com or vice versa, between the different domains, then the _setAllowLinker set to true comes into play and you have to add additional code to your link (see the first tracking example in the mentioned documentation). You don't need this if you link, e.g., from a.foo.com to xyz.foo.com.

It's explained in the documentation:

A session from one domain can only be transferred to another domain via a properly configured click or form submission, or via _getLinkerURL.

The setDomainName:

This method sets the domain field of the cookie to the string provided in the parameter. With this method, you can control the domain name used by the cookie. You will ONLY have to set up linking between top-level domains because sub-domains will share the same cookies with their parents.

share|improve this answer
    
Thanks, this seems to work. –  Deniss Kozlovs Feb 14 '13 at 14:28

As per defined in the doc it seems to be the right method:

_setDomainName('yourDomainName')

What it does.
This method sets the domain field of the cookie to the string provided in the parameter. With this method, you can control the domain name used by the cookie. You will ONLY have to set up linking between top-level domains because sub-domains will share the same cookies with their parents.

When to use it.
Use this when you want to treat top- and sub-domains as one entity and track in the same profile. Also use this when you want to track across multiple top-level domains AND their sub-domains. In this case, you will need to using linking between the top-level domains, but not between the top-level domains and their sub-domains.

When not to use it.
If you are tracking a single domain, you do not need to explicitly set the domain name.

I also recommend you to read this part of the documentation: Tracking Multiple Domains - Web Tracking (ga.js).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.