1

我使用 JS 编写了这个小代码来禁用 cookie:

$(document).ready(function() {
  var cookie_settings = getCookie("cookie-settings"); //Main cookie which contains cookie preferences
  var cookie_selector = document.getElementById("cookie-selector"); //Modal for cookie selection
  var g_recaptcha = document.getElementById("cookie-g-recaptcha"); //Example checkbox cookie
  var g_tag_manager = document.getElementById("cookie-g-tag-manager"); //Example checkbox cookie
  var messenger_plugin = document.getElementById("cookie-fb-mccp"); //Example checkbox cookie
  var g_analytics = document.getElementById("cookie-g-analytics"); //Example checkbox cookie
  var cookie_set = document.getElementById("cookie-set"); //Button to save preferences
  if (cookie_settings == null) { //Check if main cookie exist
    $(cookie_selector).modal({
      backdrop: 'static',
      keyboard: false
    }); //If not exist, open cookie selector modal
  } else {
    var cookie_settings_raw_values = getCookie("cookie-settings"); //read and save main cookie in var
    var cookie_settings_values = cookie_settings_raw_values.split('&'); //save main cookie content in array
    if (cookie_settings_values.includes(g_recaptcha.id)) {
      //If array contains recaptcha example include it
      //for example append in head -> $('head').append('myscript');
    }
    if (cookie_settings_values.includes(g_tag_manager.id)) {
      //same
      //for example append in head -> $('head').append('myscript');
    }
    if (cookie_settings_values.includes(messenger_plugin.id)) {
      //same
      //for example append in head -> $('head').append('myscript');
    }
    if (cookie_settings_values.includes(g_analytics.id)) {
      //same
      //for example append in head -> $('head').append('myscript');
    }
    //or you can remove else condition and manage this part from php
  }
  $(cookie_set).click(function() { //on save preferences click
    var selected_cookies = [g_recaptcha.id, g_tag_manager.id]; //make array and include required cookies
    if (messenger_plugin.checked == true) {
      //if messenger plugin example checkbox is checked push it's reference in array
      selected_cookies.push(messenger_plugin.id);
    }
    if (g_analytics.checked == true) {
      //same for the other optional checkboxes
      selected_cookies.push(g_analytics.id);
    }
    var expiry_date = new Date();
    expiry_date.setMonth(expiry_date.getMonth() + 6); //expiration date 6 months in my case, you can set what you want
    document.cookie = document.cookie = "cookie-settings=" + selected_cookies.join('&') + "; expires=" + expiry_date.toGMTString(); //make main cookie with required and optional selected checkboxes (the deadline is 6 months after the creation of the cookie)
    location.reload(); //reload page
  });
  //get cookie by name
  function getCookie(name) {
    var document_cookie = document.cookie;
    var prefix = name + "=";
    var begin = document_cookie.indexOf("; " + prefix);
    if (begin == -1) {
      begin = document_cookie.indexOf(prefix);
      if (begin != 0) {
        return null;
      }
    } else {
      begin += 2;
      var end = document.cookie.indexOf(";", begin);
      if (end == -1) {
        end = document_cookie.length;
      }
    }
    return decodeURI(document_cookie.substring(begin + prefix.length, end));
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

我的问题是禁用第三方 cookie 就足够了吗?

如果用户不接受cookies,不包括脚本,存储的cookies会变得无用吗?该网站是否符合 GDPR?

如果没有,您是否有任何其他有效的替代方案来提议不使用第三方代码?

4

2 回答 2

2

大多数试图符合 GDPR 的网站在默认情况下都不会加载任何这些脚本(您可能会这样做)。首先,它们会显示一个弹出窗口,如果用户想要加载例如跟踪 cookie,并且如果用户同意它们将被加载。应该加载哪些服务的配置设置/用户选择的内容将存储在 cookie 或例如localStorage中。

所以是的,当我们查看加载外部脚本的方法时,您的网站似乎符合 GDPR。

于 2020-05-10T20:38:18.780 回答
0

如果您要删除它们,请在今天之前的到期日期再次设置它。

于 2020-05-13T07:27:19.993 回答