简体   繁体   中英

Google Analytics: Cross-domain parameters sent in URL but not passing source through reports

Another cross-domain tracking issue here, I can't for the life of me figure out this one.

I have 2 separate domains, and I'm using the _link method between them. I can see the Google Analytics utm parameters get passed from 1 domain to the other but despite that, when I reach the 2nd domain I'm being counted as a new visitor (using Google Analytics debugger I see a new visitor ID and my campaign/source/medium info has been replaced by a referral from domaina).

Code on domaina.com:

<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(["_setAccount", "UA-111111"]);
_gaq.push(["_setDomainName", "none"]);
_gaq.push(["_setAllowLinker", true]);
_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>

And the link looks like so: <a href="https://secure.domainb.com" onClick="_gaq.push(['_link', 'https://secure.domainb.com']); return false;">Donate Now</a>

When I click that link I get taken to secure.domainb.com with all the GA URL parameters attached but like I said, no source data passed through.

Code on secure.domainb.com (I don't have direct control over this, note that there are 2 UA codes on this page, mine being the second listed):

<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(["_setAccount","UA-222222"]);
_gaq.push(["_trackPageview"]);
_gaq.push(["_setAccount","UA-111111"]);
_gaq.push(["_setAllowLinker",true]);
_gaq.push(["_setDomainName","none"]);
_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>

I've successfully implemented cross-domain tracking with this setup before, that's why I'm baffled why this isn't working.

Any thoughts?

Thanks in advance.

You should use a second tracker for the second pageview being generated for secure.domainb.com.

<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(["_setAccount","UA-222222"]);
_gaq.push(["_trackPageview"]);
_gaq.push(["t2._setAccount","UA-111111"]);
_gaq.push(["t2._setAllowLinker",true]);
_gaq.push(["t2._setDomainName","none"]);
_gaq.push(["t2._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>

You should define the domains using the call to setDomainName with:

_gaq.push(["_setDomainName","domaina.com"]);

and

_gaq.push(["t2._setDomainName","domainb.com"]);

Please note that if you are using more than one level of subdomains (ie secure.www.domainb.com), append a . to the setDomainName argument, like this:

_gaq.push(["t2._setDomainName",".domainb.com"]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM