【发布时间】:2018-04-05 11:55:17
【问题描述】:
我正在设置 google opt-out cookie,如此处所述,并且设置了 ga-disable cookie。 https://developers.google.com/analytics/devguides/collection/gajs/#disable
不幸的是,cookie 仅针对 /example.com 设置,并且在任何子域(如 xy.example.com)上无法识别 ga-disable cookie。
我希望选择退出 cookie 对所有子域都有效。
我该如何做到这一点?
正在运行和设置 Google 退出 cookie 的代码:
// Set to the same value as the web property used on the site
var gaProperty = 'UA-yyyyyy';
// Disable tracking if the opt-out cookie exists.
var disableStr = 'ga-disable-' + gaProperty;
if (document.cookie.indexOf(disableStr + '=true') > -1) {
window[disableStr] = true;
}
// Opt-out function
function gaOptout() {
document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
window[disableStr] = true;
}
</script>
非常感谢!
【问题讨论】:
标签: javascript cookies google-analytics