orestbida / cookieconsent

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

[3.0.0] - acceptedService example should include object key as parameter #649

Closed frankykubo closed 4 months ago

frankykubo commented 4 months ago

Fixed the example by changing Google analytics to ga on THIS API DOCS page. Like this, I think it is also more intuitive as it does not really make sense why there was Google analytics in the example.

Have a great day and thank you for providing such a great lib.

vercel[bot] commented 4 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **cookieconsent-docs** | ⬜️ Ignored ([Inspect](https://vercel.com/orest/cookieconsent-docs/33p46ZM3wAZxA5AVUjDZYxQbeMUj)) | [Visit Preview](https://cookieconsent-docs-git-fork-frankykubo-update-acce-dfca05-orest.vercel.app) | | Feb 26, 2024 10:25am |
netlify[bot] commented 4 months ago

Deploy Preview for cookieconsentv3-playground canceled.

Name Link
Latest commit 4618b24f3126ea86a5e48d6030b9bc7e9b747b31
Latest deploy log https://app.netlify.com/sites/cookieconsentv3-playground/deploys/65dc6733d9b3560008050adc
frankykubo commented 4 months ago

@orestbida Oh, I now can understand why it is done like this (not using key but rather using label in acceptedService).

But in this case, I found probably another bug - take a look at repro HERE:

Check cookieconsent-config.js and see onConsent, I defined service test with label Test Service, which I used in onConsent:

onConsent: ({ cookie }) => {
    console.log('onConsent fired ...');
    console.log(
      window.CookieConsent.acceptedService('Test Service', 'analytics')
    );
    console.log(window.CookieConsent.acceptedService('test', 'analytics'));
  },

There are 2 console logs, where first is done like in example from docs.

But unexpectedly - first console is false and second is true - so second is working properly and first not. Thats why I assumed that docs are not correct, but I am not using your library with HTML tags but rather using JS.

orestbida commented 4 months ago

I think you misunderstood. The label is just for human intepretation, so that in place of "ga4" you see its label "Google Analytics 4". The label is not evaluated/checked by the .acceptedService method.

The key of a service is defined either using a script tag (in this case "my service"):

<script type="text/plain" data-category="analytics" data-service="my service"></script>

or an internal key in the js config. (in this case "my second service"):

CookieConsent.run({
    categories: {
        analytics: {
            services: {
                "my second service": {
                    label: "Custom tracking service"
                }
            }
        }
    }
});

The only valid field for the first parameter is the key of a service:


CookieConsent.acceptedService("my service", "analytics"); //true/false
CookieConsent.acceptedService("my second service", "analytics"); //true/false
frankykubo commented 4 months ago

Alright, it makes sense. Thank you! In this case, I think we can close this.

Have a great day.