Reputation: 8604
We started the A/B experiments on our site. Homepage is the tracking site and it redirects to 3 other versions. Since the google analytics script (ga.js) is loaded just after the site is redirected, we are loosing the referrals data. The referral is always the original homepage.
I was not successful in searching for the clear and right solution.
How can I provide the referral to analytics? Thanks in advance.
EDIT:
So I tried _setReferrerOverride method, but didn't help.
This code is before the control script (the enter page for visitors, i'm lookinf for referrer here). I'm setting the cookie.
if($_COOKIE[abtestRef]) $_SERVER[HTTP_REFERER] = $_COOKIE[abtestRef];
if($_SERVER[REQUEST_URI]=='/'):
setcookie('abtestRef',$_SERVER[HTTP_REFERER],time()+300,'/','cloudee.eu');
<!-- Google Website Optimizer Control Script -->
<script ....
And here is the tracking script on page which the control script redirects to. So I'm setting referrer from cookie here ... but there is no change in GA, so probably I'm doing something wrong.
<!-- Google Website Optimizer Tracking Script -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['gwo._setAccount', 'UA-27591323-1']);
_gaq.push(['_setReferrerOverride','<?=$_COOKIE[abtestRef]?>']);
_gaq.push(['gwo._trackPageview', '/2713975509/test']);
(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>
Upvotes: 0
Views: 654
Reputation: 26
Crayon is right. Here's an example snippet that works on my site:
_gaq.push(['gwo._setAccount', 'UA-XXXXXXXX-2']);
if (window.location.href.indexOf('ref=lowcost') >= 0) {
_gaq.push(['_setReferrerOverride', 'http://www.lowcostairlines.nl/']);
}
_gaq.push(['gwo._trackPageview', '/1794361722/test']);
Upvotes: 1
Reputation: 32532
To sum up, you will need to pass the original referring URL to the test page, and then manually set the referring URL on the test page.
You can do this by setting a cookie on the redirect page and then looking for it on the test pages, or pass via URL param. You will then need to use _setReferrerOverride() in your GA code to override the default (document.referrer) with the original referring URL.
You will also need to make sure you are passing all other URL params to the test pages as well, so you don't lose your campaign codes, etc.. if you use those.
Upvotes: 1