从网站禁用/删除第三方Cookie

时间:2020-02-04 09:58:08

标签: javascript cookies

由于GDPR法律的原因,我需要在我们的网站上添加Cookie同意系统。目前,所有功能都设置为禁用和启用Cookie,但是我似乎无法删除由Google Analytics(分析)或AddThis(某些社交媒体跟踪)创建的第三方Cookie,因为我无法使用document.cookie找到它们

有人知道哪个是最好的选择吗?

  1. 删除第三方Cookie
  2. 防止脚本在启动时运行,并在用户同意后启动脚本
  3. 从头开始运行脚本,但如果用户拒绝使用cookie,则卸载脚本

但是要清楚一点,我知道如何删除常规Cookie,我确实需要找到一种方法来删除第三方Cookie或阻止第三方Cookie加载(但请确保在用户需要时加载第三方Cookie) )

enter image description here

<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-556d15415fgddz4536" async="async"></script>

<script>
function enableCookies() {
    console.log('enable cookies');
}

function disableCookies() {
    console.log('disable cookies');
}

window.cookieconsent.initialise({
    onInitialise: function (status) {
        var type = this.options.type;
        var didConsent = this.hasConsented();
        if (type == 'opt-in' && didConsent) {
            enableCookies();
        }
        if (type == 'opt-out' && !didConsent) {
            disableCookies()
        }
    },
    onStatusChange: function (status, chosenBefore) {
        var type = this.options.type;
        var didConsent = this.hasConsented();
        if (type == 'opt-in' && didConsent) {
            enableCookies();
        }
        if (type == 'opt-out' && !didConsent) {
            disableCookies()
        }
    },
    onRevokeChoice: function () {
        var type = this.options.type;
        if (type == 'opt-in') {
            disableCookies()
        }
        if (type == 'opt-out') {
            enableCookies();
        }
    }
    position: "bottom-left",
    type: "opt-out"
});
</script>

0 个答案:

没有答案