AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Analytics
1.7K members online now
1.7K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Getting Analytics of same page from 2 different domains

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Just to be clear on this, I am NOT trying to do cross domain tracking where domain 1 has different webpages than domain 2.

 

In fact Domain 1 and domain 2 use the exact same pages, which means the analytics code is exactly the same. 

 

Domain 1 is the primary domain. Traffic from this domain is recorded properly.  Domain 2 is a second domain that uses .htaccess to redirect to domain 1, but still have the url appear to be from domain 2.  

 

I want traffic from both domains to be recorded, since they are both looking at the same site.

 

Now, I can program in a if/then statement so that it runs the cross domain code depending on what domain it comes from (that is, page "chooses" whether it shows code for domain 1 or code for domain 2)

 

I want to know if there is a better way to accomlish the same result?  Thank you

Re: Getting Analytics of same page from 2 different domains

Visitor ✭ ✭ ✭
# 2
Visitor ✭ ✭ ✭

If the if then coding is the best way to do it, can you assist me by also verifying I did the code correctly below and didnt leave something open? Thanks

 

 

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

<? $domain = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); if($domain == "DOMAIN1") { ?> ga('create', 'UA-XXXXXXXX-Y', 'auto', {'allowLinker': true}); ga('require', 'linker'); ga('linker:autoLink', ['DOMAIN2'] ); <? } else { ?> ga('create', 'UA-XXXXXXXX-Y', 'auto', {'allowLinker': true}); ga('require', 'linker'); ga('linker:autoLink', ['DOMAIN1'] ); <? } ?> ga('send', 'pageview'); </script>