I have a website (http://www.accent.jobs) which contains a language selection tool on the www. subdomain.
When choosing a language, a cookie is set, so the user only sees the language selection page once, and automatically get redirected the right way next time.
What I notice in Analytics, is that traffic from the www to a subdomain (be.accent.jobs for instance) is seen as referral traffic.
What I do on the www. subdomain:
- User clicks a link.
- Javascript does an AJAX request to a PHP file which sets the cookie.
- The user gets redirected through JavaScript using
window.location.
When the user goes back to the www. subdomain, the redirect is done through PHP using a 302, without a page rendering.
Any ideas on how I could get the traffic from www. to a subdomain not to be handled as referral traffic in Analytics? I would like to keep the original referrer (the site that referred to http://www.accent.jobs) as the referrer in Analytics.
This is the tracking code on both the www and the be. subdomain:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxx-xx']);
_gaq.push(['_trackPageview']);
_gaq.push(['_setDomainName', 'accent.jobs']);
_gaq.push(['_addIgnoredRef', 'accent.jobs']);
_gaq.push(['_addIgnoredRef', 'be.accent.jobs']);
_gaq.push(['_addIgnoredRef', 'nl.accent.jobs']);
_gaq.push(['_addIgnoredRef', 'ro.accent.jobs']);
_gaq.push(['b._setAccount', 'UA-xxxxxx-x']);
_gaq.push(['b._trackPageview']);
_gaq.push(['b._setDomainName', 'accent.jobs']);
_gaq.push(['b._addIgnoredRef', 'accent.jobs']);
_gaq.push(['b._addIgnoredRef', 'be.accent.jobs']);
_gaq.push(['b._addIgnoredRef', 'nl.accent.jobs']);
_gaq.push(['b._addIgnoredRef', 'ro.accent.jobs']);
(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);
})();
PS: I’m tracking on multiple UA accounts to keep the data in an older account as well, hence the ‘double’ tracking code.
Tries
- Tried replacing the JavaScript redirect by server-side 302 header redirects in PHP, no luck.
- Also tried using only JavaScript redirects, still no luck.
Your
_setDomainNameusage is correct and sufficient.But its value is never send to Analytics : you must use it BEFORE
_trackPageview.Then
_addIgnoredRefis not useful anymore.