admin管理员组文章数量:1220937
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 ,
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).
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:
foreach ($_COOKIE as $key => $value) {
setcookie($key, '', time()-1000,'/','.mydomain');
}
But without success! (I inserted this code after the GA monitoring JavaScript) GA cookies are ever on my browser.
So, Can I delete GA cookies?
Or Is enough blocking GA tracking for EU e-Privacy Directive?
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 ,
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).
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:
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.
So, Can I delete GA cookies?
Or Is enough blocking GA tracking for EU e-Privacy Directive?
Share Improve this question edited Aug 19, 2016 at 9:00 mtb 1,37016 silver badges32 bronze badges asked Jun 1, 2015 at 16:31 Marco MirabileMarco Mirabile 2651 gold badge5 silver badges14 bronze badges 2 |2 Answers
Reset to default 8Yes, you can delete the cookies. You just have to match the exact Path
and Domain
parameters as the ones used in those cookies. 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. The extension outputs the data sent to Google Analytics to the JavaScript Console Window.
Below is an example how to remove analytics.js
defaults using js-cookie
after disabling the default tracker.
// 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
本文标签: javascriptDelete Google Analytics Cookies and EU eprivacy lawStack Overflow
版权声明:本文标题:javascript - Delete Google Analytics Cookies and EU e-privacy law - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739329696a2158421.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
window['ga-disable-UA-XXXXXX-X'] = true;
BEFORE you load the tracking script. More info: stackoverflow.com/questions/10668292/… – Tom Commented Jun 1, 2015 at 18:33window['ga-disable-UA-XXXXX-Y'] = true
works but can I delete existing __utm and _ga cookies? – Marco Mirabile Commented Jun 1, 2015 at 22:00