开发者

Subdomain overwriting the google analytics cookie values

I am stuck here. What I am trying to attain is: Suppose someone searches for my website on google and then he is redirected to my site via google. So in the utmz cookie the source, medium etc are saved as organic, google.com and the keyword by which the user has found my domain.

Now mydomain.com has a page listing my products. If the visitor wishes to purchase it, he is first redirected to paypal and then in paypal return url is a page on one of my subdomain say subdomain.mydomain.com/thankyou.php.

As soon as paypal redirects the visitor to my subdomain, the cookie values get overwrite by "direct, direct" etc. I want the cookies to not overwrite, but instead appear as if the user had appeared from google via the keyword search which were the values from main site.

Here is my code which I have put on subdomain pages:

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXX-X']);
_gaq.push(['_setDomainName', '.mydomain.com']);
_gaq.push(['_addIgnoredRef', 'mydomain.com']);
_gaq.push(['_trackPageview']);
_gaq.push(['_addTrans','', '', '', '0.00', '0.00', '', '', '']);
_gaq.push(['_addItem','', '', '', ' ', '', '']);
_gaq.push(['_trackTrans']);
(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开发者_StackOverflow';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

On main domain the code is same except that _addIgnoredRef parameter is not present on main domain


You need to turn off the hash function for this to work: _gaq.push(['_setAllowHash', false]);. Put it after the _setDomainName call.


It depends on what code you have on your main domain, could you add this information ?

What usually happens is that you should use the following instead

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXX-X']);
_gaq.push(['_setDomainName', 'mydomain.com']); // leading dot removed to have the same cookie HASH value on domain and sub-domain
_gaq.push(['_addIgnoredRef', 'paypal.com']); // better ignore paypal
_gaq.push(['_trackPageview']);
_gaq.push(['_addTrans','', '', '', '0.00', '0.00', '', '', '']);
_gaq.push(['_addItem','', '', '', ' ', '', '']);
_gaq.push(['_trackTrans']);
(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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜