5.9K members online now
5.9K 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

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



(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

<? $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>