如何以通用方式禁用Cookie,直到用户接受Cookie [英] How to disable cookies in a generic way till cookies are accepted by user

查看:33
本文介绍了如何以通用方式禁用Cookie,直到用户接受Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在用户接受cookie之前,是否有一种禁用cookie的好方法?

Is there a fancy way to disable cookies untill the user accepts them?

以下问题:我有一个网上商店,使用了很多cookie,为了使GDPR保持一致,我们需要禁用" cookie,直到用户接受为止.我不想重写整个商店系统,因此我正在寻找通用解决方案.

Following Problem: I have a webshop which uses quite a lot cookies and in order to be GDPR conform we need to "disable" cookies untill the user has accepted them. I do not want to rewrite the whole shop system and therefore I am searching for a generic solution.

我的方法是:

  • 取消设置我们服务器(通过nginx或php)发送的所有 set-cookie 标头

但是仍然存在一些问题:

But there are still some problems:

  • 如何防止外部站点设置Cookie而没有完全删除它们(bing,google,fb和..)
  • 如何防止 javascript 在不修改所有javascript源的情况下设置cookie(是否有可能覆盖浏览器功能,因此您无法通过JS设置cookie)
  • how can I prevent external sites from setting cookies without completely removing them (bing, google, fb, ..)
  • how can I prevent javascript from setting cookies without modifying all javascript sources (is it possible to override the browser functions so you can't set cookies via JS)

推荐答案

如果您对GDPR的合规性感到担忧,仅删除cookie是不够的.您需要禁用所有收集个人身份信息(PII)的跟踪脚本.

If GDPR compliance is your concern, just removing cookies won't be enough. You need to disable any tracking scripts collecting personally identifiable information (PII).

我建议将所有跟踪脚本移至Google Tag Manger,并使用Simo Ahava概述的方法.指南1 指南2 .他的方法不适用于跟踪非Google的标签,但是通过自定义触发器,您可以停止任何操作.

I recommend moving all tracking scripts to Google Tag Manger, and using the methods outlined by Simo Ahava. Guide 1 and Guide 2. His methods don't work great for tracking tags that aren't Google, but with a custom trigger you can stop anything.

话虽如此,如果您只是想删除Cookie,则应该这样做.

That being said, if you do just want to remove cookies, this should do it.

function deleteCookies() {
    var theCookies = document.cookie.split(';');
    for (var i = 0 ; i < theCookies.length; i++) {
        document.cookie = theCookies[i].split('=')[0] + '=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
    }
}

这篇关于如何以通用方式禁用Cookie,直到用户接受Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆