使用子域名的Cookie排除我的流量在Google Analytics中的记录

6

当我没有指定域名时,我的排除流量的cookie方法能够正常工作。现在我已经指定了域名,但它不再起作用。似乎会设置两个cookie,我创建的exclude.html页面会设置一个"mydomain.com"的cookie,而Google Analytics则会设置一个"www.mydomain.com"的cookie。

这是我exclude.html页面的代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Exclude Me</title>
    <script type="text/javascript">

        var _gaq = _gaq || [];
        _gaq.push(['_setVar', 'exclude_me']);
        _gaq.push(['_setDomainName', 'www.mydomain.com']);
        _gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);
        _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>
</head>
<body>
    <p>
        This computer now has a cookie placed on it to exclude it from any Google Analytics reports.</p>
    <p>
        If you delete your cookies, you will need to revisit/reload this page again.</p>
</body>
</html>

我尝试添加了_gaq.push(['_setDomainName', 'www.mydomain.com']);来使其工作,但似乎没有任何作用。这是我为所有其他页面设置的方式,使用的是www.mydomain.com。


1
当我在输入这个时,我意识到'_gaq.push(['_setDomainName', 'www.mydomain.com']);'可能应该放在'_gaq.push(['_setVar', 'exclude_me']);'之前。所以我交换了它们的位置,现在不再创建两个不同的cookie了,希望这样可以解决问题。 - Casey
将其放在你的问题答案中并接受它,因为它解决了问题。 - Eduardo
2个回答

2

当我输入这个内容时,我发现'_gaq.push(['_setDomainName', 'www.mydomain.com']);'应该放在'_gaq.push(['_setVar', 'exclude_me']);'之前。所以我交换了它们的位置,现在不再创建两个不同的cookie了,希望这样可以解决问题。


0
在设置“setDomainName”时,应该从.mydomain.com中排除www。同时,需要注意(.mydomain.com)和(mydomain.com)是两个不同的域名,因此会有两个不同的Cookie(它们都是有效的,但您应该选择其中一个使用)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接