简体   繁体   English

删除 Google Analytics Cookies 和欧盟电子隐私法

[英]Delete Google Analytics Cookies and EU e-privacy law

On my site, if user refuses to use cookies (according to the EU e-privacy directive), I block tracking of Google Analytics using the JavaScript ,在我的网站上,如果用户拒绝使用 cookie(根据欧盟电子隐私指令),我会使用 JavaScript 阻止对 Google Analytics 的跟踪,

window['ga-disable-UA-XXXXXX-X'] = true;

With this command tracking is disabled and seems to work (if I surf on the site, Google Analytics doesn't see any activity).使用此命令跟踪被禁用并且似乎可以工作(如果我在网站上冲浪,Google Analytics 看不到任何活动)。

But I notice that __utma , __utmb ,.... cookies are still on my browser (in Chrome), so I tried to delete them with setcookie function of php:但是我注意到__utma__utmb ,.... cookie 仍然在我的浏览器上(在 Chrome 中),所以我尝试使用 php 的setcookie功能删除它们:

foreach ($_COOKIE as $key => $value) {
setcookie($key, '', time()-1000,'/','.mydomain.com');
}

But without success!但没有成功! (I inserted this code after the GA monitoring JavaScript) GA cookies are ever on my browser. (我在 GA 监控 JavaScript 之后插入了这段代码)GA cookie 一直在我的浏览器上。

So, Can I delete GA cookies?那么,我可以删除 GA cookie 吗?

Or Is enough blocking GA tracking for EU e-Privacy Directive?或者是否足以阻止欧盟电子隐私指令的 GA 跟踪?

Yes, you can delete the cookies.是的,您可以删除 cookie。 You just have to match the exact Path and Domain parameters as the ones used in those cookies.您只需要匹配那些 cookie 中使用的确切PathDomain参数。 You can use this code and replace the parameters with yours:您可以使用此代码并将参数替换为您的:

function deleteCookie(name) {
    document.cookie = name + '=; Path=/; Domain=.example.com; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}

The Google Analytics Debugger Chrome Extension is very helpful in testing Google Analytics code. Google Analytics Debugger Chrome 扩展程序对于测试 Google Analytics 代码非常有帮助。 The extension outputs the data sent to Google Analytics to the JavaScript Console Window.该扩展程序将发送到 Google Analytics 的数据输出到 JavaScript 控制台窗口。

Below is an example how to remove analytics.js defaults using js-cookie after disabling the default tracker.下面是如何在禁用默认跟踪器后使用js-cookie删除analytics.js默认值的示例。

// https://github.com/js-cookie/js-cookie
import Cookies from 'js-cookie';

const disableDefaultTracker = () => {
  // Remove the default tracker.
  if (window.ga) window.ga('remove');
  // Remove the default cookies
  // _ga is used to distinguish users.
  Cookies.remove('_ga', { path: '/', domain: document.domain });
  // _gid is used to distinguish users.
  Cookies.remove('_gid', { path: '/', domain: document.domain });
  // _gat is used to throttle request rate.
  Cookies.remove('_gat', { path: '/', domain: document.domain });
}

See https://developers.google.com/analytics/devguides/collection/analyticsjs/cookie-usage请参阅https://developers.google.com/analytics/devguides/collection/analyticsjs/cookie-usage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM