我们正在寻求为我们的网站访问者实施禁用跟踪的选项.
我已阅读此页面上的文档,但我仍然不清楚如何执行此操作:https://developers.google.com/analytics/devguides/collection/gtagjs/user-opt-out
仅触发"window ['ga-disable-GA_TRACKING_ID'] = true就足够了;" 单击按钮时?Google Analytics(分析)会记住此用户的设置,还是基于每次访问?如果我有第二个按钮将其设置为"false",用户是否可以重新启用跟踪?
谢谢!
解决了:
将以下代码粘贴到Google Analytics代码之前的标题中.
<script>
// Set to the same value as the web property used on the site
var gaProperty = 'UA-XXXX-Y';
// 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; …
Run Code Online (Sandbox Code Playgroud)