Somebody follows a blog link(say http://blog) to come to my site (say http://mysite/a.php).
So now she is on page http://mysite/a.php and referer is set to http://blog
Now there is JavaScript on the page http://mysite/a.php which does the following redirection:
document.location = "http://mysite/b.php; //This is executed before any Google Analytics script.
Now in the request to http://mysite/b.php, referer is set as http://mysite/a.php.
Because of which (I think so) my Google Analytics is showing all the traffic coming from http://mysite/a.php.
Suggest a solution please.
Note: JavaScript redirection is critical, can't get rid of it.
Also I tried sending 302 code from server, but no success.
Google Analytics now has a special URL parameter, utm_referrer
, where you can pass the referer to the page you're redirecting to; doing so will simulate the same behavior as below without any need to mess with cookies or functions.
In your example, you'd make your code say:
document.location = "http://mysite/b.php?utm_referrer=" + encodeURIComponent(location.href); ;
Google Analytics has a function called setRefererOverride(). If you set it, it will override the referrer value that it tracks to whatever value you set.
The best way to do this is to, prior to the redirect, store the real referrer in a cookie, like so:
document.cookie = "realreferrer="+encodeURIComponent(document.referrer)+"; path=/";
Then, read the cookie value on the page. If the cookie is set, call that function before your pageview.
var realreferrer = readCookie("realreferrer"); //using a readCookie function of some kind
if (realreferrer) {
_gaq.push(['_setReferrerOverride', realreferrer ]);
//if using the old code, use pageTracker._setReferrerOverride(realreferrer);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With