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

xtcModified Shop on multiple domains: Tracking only on one; double code tracks once on all)

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi,

To start with: I am really confused as to what is happening or not happening at all here. On a client's website using xtc Modified shop with 4 domains (.com, .net, .es, .fr) we found the code (numbers replaced):

 

<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');
  ga('create', 'UA-111111-1', 'domain.com');
  ga('require', 'displayfeatures');
  ga('set', 'anonymizeIp', true);
  ga('send', 'pageview');
</script>

This code has apparently been hardcoded but looked fine.

However, we found that it was only tracking for domain.com, not for the other 3. When we added the code on a completey unrealted and unconnected site, it was tracking fine as well.

 

Eventually I went through the shop an switched its internal "activate GA" button to true. This added the following Code to all sites:

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-111111-1']);
  _gaq.push(['_gat._anonymizeIp']);
  _gaq.push(['_trackPageview']);
  (function() {
    var ga = document . createElement('script');
    ga.type = 'text/javascript';
    ga.async = true;
    ga.src=('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0];
    s . parentNode . insertBefore(ga, s);
  })();
</script>

Very old, aye. Surprisingly: This code worked. The tracking now seems to be absolutely correct, for all domains/language versions. I have no clue as to what is the difference between the two.

 

I would be thankful for any hint on what I am missing and how I can maybe fix this with a single code.

Thanks!

 

 

 

Re: xtcModified Shop on multiple domains: Tracking only on one; double code tracks once on all)

Follower ✭ ☆ ☆
# 2
Follower ✭ ☆ ☆

Hi Marc,

 

Could it be that the cookie domain on the other domains (.fr, .net, .es) is still set to domain.com?

 

For each domain, the cookie domain needs to either match the domain exactly, or it needs to be set to 'auto'. So on each domain you would need to modify the code to reflect the domain it is currently on.

 

Here are the 4 "create" methods you would need to use:

 

ga('create', 'UA-111111-1', 'domain.com');
ga('create', 'UA-111111-1', 'domain.net');
ga('create', 'UA-111111-1', 'domain.es');
ga('create', 'UA-111111-1', 'domain.fr');

Hope this helps!

 

Cheers,

 

Bogdan

Re: xtcModified Shop on multiple domains: Tracking only on one; double code tracks once on all)

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Hi Bogdan,

Evidence (i.e. direct tests) points to that being not necessary and hence not the real problem. We copied the exact code

&lt;script&gt;
(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-111111-1', 'domain.com');
ga('require', 'displayfeatures');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
&lt;/script&gt;

and put it on completely unrelated domains, say alt.some-sportsclub.de for testing. Visit was immediately visible with the right url (Testpage.html) and hostname (alt.some-sportsclub.de) despite domain.com set in the create. The analytics help even warns that this can happen if somebody else includes the wrong code accidentally.

Incidentally, m.domain.com (with the exact same code as stated originally) has always been tracked absolutely fine. (And we do NOT need cross-domain tracking at this point either.)

Re: xtcModified Shop on multiple domains: Tracking only on one; double code tracks once on all)

[ Edited ]
Follower ✭ ☆ ☆
# 4
Follower ✭ ☆ ☆

Hi Marc,

 

This is an interesting problem. How are you running these tests (in the browser console, adding code on page, tag manager, etc)?

 

I just ran a test in my browser console to create a tracker on one domain somepage.test.com and set it's cookie domain to domain.com and was not able to see it working. Then, I reloaded the test page, and set the cookie domain to somepage.test.com and was able to see the pageview working correctly. Then, I reloaded the page again, set the cookie domain to auto, and was able to see the pageview correctly.

 

What I suspect is happening here, is that your browser already has a GA cookie present, which is why you are able to see pageviews coming through correctly when running tests.

 

Since cross domain tracking is not needed at this time, could you please try just setting the cookie domain to 'auto' as such:

 

ga('create', 'UA-111111-1', 'auto');

 

Let me know if this works!

 

Cheers,

 

Bogdan