Andy
Andy

Reputation: 1163

Connecting google analytics to multiple top domains

I have 2 domains www.domain1.com and www.domain2.com pointing to the same site.
I want to connect google analytics to them, to track the whole traffic to my site from both domains.
I saw answers to such question here in stackoverflow, that instruct to add the same analytics account ID for all the pages in domain1.com and domain2.com, but in domain1.com use setDomainName(domain1.com) and in domain2 use setDomainName(domain2.com).

That solution confuses me, since I don't understand how google knows that I want to allow summing the statistics from both those domains.
It seems that I can see for example stackoverflow.com's analytics ID and put it in my site, and as a result to add my statistics to stackoverflow's.

What do I miss here?

Upvotes: 0

Views: 242

Answers (2)

TomFuertes
TomFuertes

Reputation: 7270

I have 2 domains www.domain1.com and www.domain2.com pointing to the same site. I want to connect google analytics to them, to track the whole traffic to my site from both domains.

For this use case, I'd also take a look at Google Analytics on Steroids. It's a third party wrapper around Google Analytics that let's you implement other features that come along with this setup like Cross Domain Tracking more easily.

It seems that I can see for example stackoverflow.com's analytics ID and put it in my site, and as a result to add my statistics to stackoverflow's.

Whilst this is true, you can include/exclude traffic by applying Profile Filters. StackOverflow would have one that "includes only traffic to the HostName = StackOverflow.com". You could have a custom one that "inclues only traffic to the HostName regex matching ^(.*\.)?(domain1|domain2)\.com$

If you're interested in learning more, the Videos from Google are a great place to start.

Upvotes: 0

OnenOnlyWalter
OnenOnlyWalter

Reputation: 437

Check the documentation on the Developer's site here.

You are correct with the following set-up:

setDomainName(domain1.com)
setDomainName(domain2.com)

What you're missing is the same Analytics profile ID. This example is from the documentation:

Site #1:

<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setDomainName', 'example-petstore.com']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
</script>

And Site #2:

<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setDomainName', 'my-example-blogsite.com']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
</script>

The profile ID is what ties the 2 domains together.

Upvotes: 0

Related Questions