MistUnleashed
MistUnleashed

Reputation: 309

Multi-Domain Tracking for Google Analytics

I've looked through the website and i am unable to find an answer.

Basically: I am using Google Analytics to track views and other stuff on my website, but i have 2 domains, both have the same root folder and are identical in name but one ends in ".com" and the other in ".co.uk"

Currently Google Analytics is only tracking the ".com" domain but i was wondering if i could manipulate the code to track from the ".co.uk" domain as well?

Here's the code:

<script type="text/javascript">

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

  ga('create', 'UA-XXXXXXXX-X', 'XXXXXXXXXXX.com');
  ga('send', 'pageview');

</script>

Upvotes: 0

Views: 253

Answers (2)

Mujtaba Haider
Mujtaba Haider

Reputation: 1650

I think you do not need to mention site url in create script

ga('create', 'UA-XXXXXXXX-X');

And to avoid being tracked twice while switching between your own sites you just need to put following in your links On site a where you have the site b link

onclick="_gaq.push(['_link','http://site-b.co.uk']);"

On site b where you have the site a link

onclick="_gaq.push(['_link','http://site-a.com']);"

See the link for further explanation

Upvotes: 0

Avi
Avi

Reputation: 2383

You could technically just change the create code to:

ga('create', 'UA-XXXXXXXX-X', 'XXXXXXXXXXX.co.uk');

or

ga('create', 'UA-XXXXXXXX-X');

to track visitors on the other domain. There are some issues with this solution though. If a visitor visits co.uk site and then goes to .com site, she will be counted twice(two unique visitors).

You could have co.uk serve pages with iframe from .com page and have the iframe do the tracking but it is kind of hackish and probably not a good idea.

Also, are the two websites serving different content? if not, you should probably redirect one of the domains to the other for all kinds of reasons (seo, simplicity etc). If they are serving different content and you don't care about the unique visitor count, the solution above will work for you.

Upvotes: 1

Related Questions