Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Autoclear Not Working with Subdomains #568

Closed
daleharrison opened this issue Sep 21, 2023 · 2 comments · Fixed by #571
Closed

[Bug]: Autoclear Not Working with Subdomains #568

daleharrison opened this issue Sep 21, 2023 · 2 comments · Fixed by #571
Labels
documentation Improvements or additions to documentation

Comments

@daleharrison
Copy link

Expected Behavior

On a subdomain (e.g. my-site.example.com), the Meta Pixel _fbp cookie should be deleted when rejecting cookies after previously accepting them.

Current Behavior

The _fbp cookie is not deleted despite being defined in the cookie_table and autoclear_cookies being set to true.

Steps to reproduce

  • run the script on a subdomain with a Meta Pixel tracking code included
  • accept all cookies
  • change your settings to reject all cookies
  • review the Cookies pane in Developer Tools

Proposed fix or additional info.

I don't have a proposed fix but I'm looking to determine if this is an issue with the script, a browser limitation, or a problem with how the Meta Pixel cookie itself is set.

I notice that when I visit my site at e.g. my-site.example.com, the _fbp cookie's domain is .example.com. I suspect this might be the cause of the issue.

The only way I've found that seems to make it work as desired is to change my cookie_domain configuration explicitly to example.com instead of letting it use the default location.hostname, but I'm not sure if this is intentional or a fluke, as my understanding is that this is to control the domain of the consent settings cookie.

Below is the configuration I'm currently using, without cookie_domain included. I've omitted some identifying information to protect my client's privacy.

I have also added type="text/plain" data-cookiecategory="analytics" to my Meta Pixel script tag.

I do not experience this issue on sites that aren't using subdomains, e.g. example.com works perfectly.

var cc = initCookieConsent();

cc.run({
  current_lang: 'en',
  autoclear_cookies: true,
  page_scripts: true,
  mode: 'opt-in',
  remove_cookie_tables: true,
  cookie_expiration: 30,
  revision: 1,
  gui_options: {
    consent_modal: {
      layout: 'cloud',
      position: 'bottom center',
      transition: 'slide',
      swap_buttons: false
    }
  },
  languages: {
    'en': {
      consent_modal: {
        title: '[REDACTED]',
        description: '[REDACTED]',
        primary_btn: {
          text: 'Allow All',
          role: 'accept_all'
        }
      },
      settings_modal: {
        title: 'Cookie Preferences',
        save_settings_btn: 'Save Settings',
        accept_all_btn: 'Allow All',
        close_btn_label: 'Close',
        cookie_table_headers: [
          {
            col1: 'Name'
          }
        ],
        blocks: [
          {
            title: 'Strictly Necessary Cookies',
            description: 'These cookies are essential for the proper functioning of our website. Without these cookies, the website would not work properly',
            toggle: {
              value: 'necessary',
              enabled: true,
              readonly: true
            }
          },
          {
            title: 'Performance and Analytics Cookies',
            description: 'These cookies allow the website to remember the choices you have made in the past',
            toggle: {
              value: 'analytics',
              enabled: false,
              readonly: false
            },
            cookie_table: [
              {
                col1: '_fbp',
              }
            ]
          }
        ]
      }
    }
  }
});

Version

2.9.2

On which browser do you see the issue?

Chrome

@daleharrison daleharrison added the bug Something isn't working label Sep 21, 2023
@github-actions github-actions bot added the triage yet to be reviewed label Sep 21, 2023
@orestbida orestbida added documentation Improvements or additions to documentation and removed bug Something isn't working triage yet to be reviewed labels Sep 21, 2023
@orestbida
Copy link
Owner

Hi @daleharrison,

I notice that when I visit my site at e.g. my-site.example.com, the _fbp cookie's domain is .example.com. I suspect this might be the cause of the issue.

This is precisely the issue since the plugin only looks for cookies in the current domain (a subdomain, in your case), unless told otherwise.

You can specify a path and/or domain option in the cookie table item:

cookie_table: [
    {
        col1: '_fbp',
        domain: 'example.com'
    }
]

Looks like these 2 options are missing from the docs; I will add a dedicated section with an example for future users.

@daleharrison
Copy link
Author

@orestbida Thanks for the quick response, just what I was looking for!

@daleharrison daleharrison changed the title [Bug]: [Bug]: Autoclear Not Working with Subdomains Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants