orestbida / cookieconsent

:cookie: Simple cross-browser cookie-consent plugin written in vanilla js
https://playground.cookieconsent.orestbida.com/
MIT License
4k stars 410 forks source link

Google tag manager - Cookies not being removed #81

Closed sadeghmirkis closed 2 years ago

sadeghmirkis commented 3 years ago

I have put in google tag manager script that only triggers when third party cookies is enabled. And in google tag manager I got third party scripts like google analytics and some other scripts.

Everything seems to be working fine, except when the user disables third party script in the cookie settings after they have accepted third part cookies.

The cookies that tag manager has set (google analytics and others) still remains. Google analytics stops tracking but the cookies still remain in the browser. Should the cookies not be removed when disabling?

I have set the cookies that google tag manager gives in the cookie tables.

orestbida commented 3 years ago

Hi @webicient,

could you share your configuration?

sadeghmirkis commented 3 years ago

Hi @orestbida

I have set this up on our WordPress website and the server settings are down below:

Apache-version | 2.4.48 PHP-version | 5.6.40 MySQL-version | 10.3.31-MariaDB-cll-lve Architecture | x86_64 Operating system | linux Kernelversion | 3.10.0-962.3.2.lve1.5.44.3.el7.x86_64

It seems to remove some of the cookies like ga , gat and gid_ cookies but some other cookies like _li_id.b85f and _li_ses.b85f does not get removed.

Below is the code that is used:

  // obtain cookieconsent plugin
  var cc = initCookieConsent();

  // run plugin with config object
  cc.run({
    force_consent: true,
    autorun: true,
    delay: 0,
    cookie_name: "cc_cookient",
    current_lang: "sv",
    theme_css: "/wp-content/themes/css/cookieconsent.css",
    autoclear_cookies: true,
    cookie_expiration: 365,

    gui_options: {
      consent_modal: {
        layout: "box",
        position: "bottom",
        transition: "slide",
      },
      settings_modal: {
        layout: "box",
        transition: "slide",
      },
    },

    onAccept: function (cookies) {
      if (cc.allowedCategory("analytics_cookies")) {
        (function (w, d, s, l, i) {
          w[l] = w[l] || [];
          w[l].push({ "gtm.start": new Date().getTime(), event: "gtm.js" });
          var f = d.getElementsByTagName(s)[0],
            j = d.createElement(s),
            dl = l != "dataLayer" ? "&l=" + l : "";
          j.async = true;
          j.src = "https://www.googletagmanager.com/gtm.js?id=" + i + dl;
          f.parentNode.insertBefore(j, f);
        })(window, document, "script", "dataLayer", "-");
      }
    },

    languages: {
      sv: {
        consent_modal: {
          title: "Vi använder Cookies",
          description:
            "Vi använder cookies för att säkerställa att webbplatsens fungerar som den ska och för att förbättra din onlineupplevelse. All data är anonymiserad och kan inte användas för att identifiera dig.",
          primary_btn: {
            text: "Acceptera",
            role: "accept_all", //'accept_selected' or 'accept_all'
          },
          secondary_btn: {
            text: "Inställningar",
            role: "settings", //'settings' or 'accept_necessary'
          },
        },
        settings_modal: {
          title: "Cookie inställningar",
          save_settings_btn: "Spara inställningar",
          accept_all_btn: "Acceptera alla", // optional, [v.2.5.0 +]
          cookie_table_headers: [
            { col1: "Namn" },
            { col2: "Domän" },
            { col3: "Utgång" },
            { col4: "Beskrivning" },
          ],
          blocks: [
            {
              title: "Cookie användning",
              description:
                "Vi  använder cookies för att säkerställa att webbplatsens fungerar som den ska och för att förbättra din onlineupplevelse.",
            },
            {
              title: "Nödvändiga Cookies",
              description:
                "Dessa cookies är viktiga för att webbplatsen ska fungera korrekt.",
              toggle: {
                value: "necessary_cookies",
                enabled: true,
                readonly: true,
              },
            },
            {
              title: "Tredjeparts Cookies",
              description:
                "Dessa cookies samlar in information om hur du använder webbplatsen, vilka sidor du besökte och vilka länkar du klickade på. All data är anonymiserad och kan inte användas för att identifiera dig.",
              toggle: {
                value: "analytics_cookies",
                enabled: false,
                readonly: false,
              },
              cookie_table: [
                {
                  col1: "_ga",
                  col2: "google.com",
                  col3: "2 år",
                  col4: "Google analytics, _ga används för att förstå hur besökaren navigerar runt på webbplatsen",
                },
                {
                  col1: "_gat",
                  col2: "google.com",
                  col3: "1 dag",
                  col4: "Används av Google Analytics för att begränsa begäran",
                },
                {
                  col1: "_gid",
                  col2: "google.com",
                  col3: "1 dag",
                  col4: "Google analytics, _gid används för att förstå hur besökaren navigerar runt på webbplatsen",
                },
                {
                  col1: "_li_id",
                  col2: "leadinfo.com",
                  col3: "2 år",
                  col4: "Leadinfo",
                },
                {
                  col1: "_li_ses",
                  col2: "leadinfo.com",
                  col3: "Session",
                  col4: "Leadinfo",
                },
              ],
            },
          ],
        },
      },
    },
  });
orestbida commented 3 years ago

Cookie names need to match in order for them to be deleted properly, and since _li_id.b85f is different than _li_id the plugin very likely skips it entirely since it can't find it.

If you don't know what the rest of the cookie name will be, you can try and enable the is_regex option which will allow the plugin to delete all of the cookies starting with _li_ses and _li_id strings:


{
    col1: "^_li_id",
    col2: "leadinfo.com",
    col3: "2 år",
    col4: "Leadinfo",
    is_regex: true
},
{
    col1: "^_li_ses",
    col2: "leadinfo.com",
    col3: "Session",
    col4: "Leadinfo",
    is_regex: true
}
sadeghmirkis commented 3 years ago

I have added the code snippet but still the cookies remains.

cookie

orestbida commented 3 years ago

Either the cookies are not being deleted (due to mismatch in domain/path) or they are somehow re-created right after they've been deleted!

Is it possible to know the domain where this issue occurs so that I can personally check?

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.