orestbida / cookieconsent

:cookie: Simple cross-browser cookie-consent plugin written in vanilla js

Home Page:https://playground.cookieconsent.orestbida.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: Callbacks are not triggered in individually togglable services.

handplant opened this issue · comments

Expected Behavior

The onAccept callbacks should be triggered for all services, including Personio, when the user accepts the corresponding category/service.

Current Behavior

The onAccept callbacks are triggered for YouTube and Vimeo services, but not for the Personio service.

Steps to reproduce

Set up a web application with my categories/services functionality.

Here are my categories/services.

  categories: {
    necessary: {
      readOnly: true,
      enabled: true,
    },
    videos: {
      services: {
        youtube: {
          label: 'Youtube Embed',
          onAccept: () => {
            console.log('accept youtube');
          }
        },
        vimeo: {
          label: 'Vimeo Embed',
          onAccept: () => {
            console.log('accept vimeo');
          }
        },
      },
    },
    personio: {
      label: 'Personio',
      onAccept: () => {
        console.log('accept personio');
      }
    }
  },

Proposed fix or additional info.

No response

Version

3.0.0

On which browser do you see the issue?

Chrome

You have declared personio outside services, as a category: [necessary, videos, personio]

I would like it to be visually and functionally like this!

Bildschirmfoto 2024-02-13 um 08 54 14

If I only have one service, then the following doesn't make sense, right? Or am I misunderstanding something?

Bildschirmfoto 2024-02-13 um 08 57 06

Am I correct in understanding that categories themselves don't have callbacks?
Thank you!

Okay, I'm now solving it through the CookieConsent onChange callback!

  onChange: ({ cookie, changedCategories, changedServices }) => {
    if (cookie.categories.includes('personio')) {
      im.acceptService('personio');
    } else {
      im.rejectService('personio')
    }
  },

Thank you very much for this first-class consent management tool!