Analytics
2.7K members online now
2.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

GA - Different domains and accounts tracking

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

Hello everyone,

 

I just got a problem in the past few days with cross-domain tracking issues.

 

I have a website with a domain mainsite.com and other website in a completely different domain hotsite.com. The first presents links to the second, while passing the trackingId by the anchor.

 

In the mainsite.com, I have the following code:

 

<script type="text/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-XXXXXXXX-YY', 'auto', {'allowLinker': true});
ga(function(tracker) {
   // just do log the id in the console
   var clientId = tracker.get('clientId');
   console.log(clientId);
});
  
ga('require','linker');
ga('linker:autoLink', ['hotsite.com', 'anyotherdomain.com'], true);
ga('send', 'pageview');

</script>

When I click in one of the page links in mainsite.com that point to hotsite.com, the browser redirects me passing the Tracking Id in the URL. Something like:

 

http://www.hotsite.com#_ga=1.232573855.1802870524.1467314959

 

Then, in the hotsite.com page, it has the following 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-YYYYYYYY-Y', 'auto', {'allowLinker': true);
  ga('require', 'linker');
  ga('linker:autoLink', ['mainsite.com','anyotherdomain.com'],true);
  ga('send', 'pageview');
</script>

Notice that each site has it's own tracking id with different accounts (XXXXXXXX and YYYYYYYY).

 

Then here is my problem:

 

On XXXXXXXX account reports, the Traffic Source to mainsite.com appear like: organic/google, organic/bing, direct/none, and so on.

On YYYYYYYY account reports, the Traffic Source to hotsite.com appear like: direct/none, mainsite.com, organic/google, etc.

 

How can I get rid of the mainsite.com Traffic Source on hotsite.com reports and get the mainsite.com Traffic Source that made the user go to mainsite.com and then to hotsite.com?

 

Regards,

Wiliam.

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Wiliam R
May 2017

Re: GA - Different domains and accounts tracking

[ Edited ]
Participant ✭ ✭ ✭
# 3
Participant ✭ ✭ ✭

Bronwyn is right. Smiley Happy

 

Basically, you should add this kind of tracking code to the mainsite.com:

 

<script type="text/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-XXXXXXXX-YY', 'auto', {'allowLinker': true});
ga(function(tracker) {
   // just do log the id in the console
   var clientId = tracker.get('clientId');
   console.log(clientId);
});
  
ga('require','linker');
ga('linker:autoLink', ['hotsite.com']);
ga('send', 'pageview');
</script>

 

and this kind of tracking code to the hotsite.com:

 

<script type="text/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-XXXXXXXX-YY', 'auto', {'allowLinker': true});
ga(function(tracker) {
   // just do log the id in the console
   var clientId = tracker.get('clientId');
   console.log(clientId);
});
  
ga('require','linker');
ga('linker:autoLink', ['mainsite.com']);
ga('send', 'pageview');
</script>

 

Just replace the mainsite.com/hotsite.com with your own domains and use only one tracking ID "UA-XXXXXXXX-YY" and it should work properly. Smiley Happy

 

Hope this helps.

Taavi

View solution in original post

Re: GA - Different domains and accounts tracking

Top Contributor
# 2
Top Contributor
Hi :-)
For cross domain tracking, both the websites need to be using the same Property
All sites being cross domain tracked also need to be on the Property's Referral Exclusion List
For further instructions/to review the setup:
https://support.google.com/analytics/answer/1034342?hl=en#GA
Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here
Marked as Best Answer.
Solution
Accepted by topic author Wiliam R
May 2017

Re: GA - Different domains and accounts tracking

[ Edited ]
Participant ✭ ✭ ✭
# 3
Participant ✭ ✭ ✭

Bronwyn is right. Smiley Happy

 

Basically, you should add this kind of tracking code to the mainsite.com:

 

<script type="text/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-XXXXXXXX-YY', 'auto', {'allowLinker': true});
ga(function(tracker) {
   // just do log the id in the console
   var clientId = tracker.get('clientId');
   console.log(clientId);
});
  
ga('require','linker');
ga('linker:autoLink', ['hotsite.com']);
ga('send', 'pageview');
</script>

 

and this kind of tracking code to the hotsite.com:

 

<script type="text/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-XXXXXXXX-YY', 'auto', {'allowLinker': true});
ga(function(tracker) {
   // just do log the id in the console
   var clientId = tracker.get('clientId');
   console.log(clientId);
});
  
ga('require','linker');
ga('linker:autoLink', ['mainsite.com']);
ga('send', 'pageview');
</script>

 

Just replace the mainsite.com/hotsite.com with your own domains and use only one tracking ID "UA-XXXXXXXX-YY" and it should work properly. Smiley Happy

 

Hope this helps.

Taavi

Re: GA - Different domains and accounts tracking

Top Contributor
# 4
Top Contributor
Bare in mind the tracking code in your initial question also indicates anyotherdomain.com. If anyotherdomain.com is to be included in cross domain tracking, it too needs to be using tracking code with the same Property ID, included in the autolink fields on the applicable sites that are linking to it.. and include the relevant sites it is linking back in its own code, together with being on the Property's Referral Exclusion List
Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here