代码之家  ›  专栏  ›  技术社区  ›  jonboy

GDPR Cookie符合性Javascript回调

  •  0
  • jonboy  · 技术社区  · 6 年前

    这与在Joomla 3.9.13网站上实现GDPR合规性有关,但我相信无论平台如何,它都是类似的。

    我一直在看 https://github.com/osano/cookieconsent 而且它似乎符合所有的法律要求,而且看起来也不错。他们有一个 configuration wizard 可在他们的网站上,这是非常容易使用的,问题是有额外的代码需要,以便使弹出实际上做任何事情除了弹出。

    他们的文件包括 callback hooks 为了禁用cookies需要实现的。。一些我没有经验的东西。

    我的理解是 全部的 应在页面上阻止Cookie 直到用户明确同意 . 因此,在“页面加载”上查看浏览器控制台“cookies”时,它应该为空,直到单击“接受”,cookies才会出现。我不能让这部分工作。每当我的页面加载这样做所有的饼干,我已经尝试,我的代码如下;

    <script>
    window.addEventListener("load", function() {
        window.cookieconsent.initialise({
            "palette": {
                "popup": {
                    "background": "#000"
                },
                "button": {
                    "background": "#f1d600"
                }
            },
            "position": "bottom-left",
            "type": "opt-out",
            "content": {
                "href": "cookie-policy.html"
            },
            onInitialise: function(status) {
                var type = this.options.type;
                var didConsent = this.hasConsented();
                if (type == 'opt-in' && didConsent) {
                    // enable cookies
                    window['ga-disable-GA_TRACKING_ID'] = false;
                }
                if (type == 'opt-out' && !didConsent) {
                    // disable cookies
                    console.log('cookies disabled');
                    window['ga-disable-GA_TRACKING_ID'] = true;
                }
            },
            onStatusChange: function(status, chosenBefore) {
                var type = this.options.type;
                var didConsent = this.hasConsented();
                if (type == 'opt-in' && didConsent) {
                    window['ga-disable-GA_TRACKING_ID'] = false;
                }
                if (type == 'opt-out' && !didConsent) {
                    // disable cookies
                    window['ga-disable-GA_TRACKING_ID'] = true;
                }
            },
            onRevokeChoice: function() {
                var type = this.options.type;
                if (type == 'opt-in') {
                    // disable cookies
                    window['ga-disable-GA_TRACKING_ID'] = true;
                }
                if (type == 'opt-out') {
                    // enable cookies
                    window['ga-disable-GA_TRACKING_ID'] = false;
                }
            },
        })
    });
    </script>
    

    除了用上面设置的文本/颜色显示弹出窗口外,此代码实际上什么也做不了。

    我需要改变什么才能让它工作?

    任何建议都将不胜感激。

    0 回复  |  直到 6 年前