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]: Since 3.0.0-rc.17, CookieConsent.acceptService() does not work #602

Closed
Striffly opened this issue Nov 30, 2023 · 7 comments
Closed
Labels
bug:confirmed bug Something isn't working
Milestone

Comments

@Striffly
Copy link

Striffly commented Nov 30, 2023

Expected Behavior

  • When using CookieConsent.acceptService(), service must be accepted.

Current Behavior

image

Steps to reproduce

  • Install 3.0.0-rc.17 (previous versions works well)
  • Simply call CookieConsent.acceptService() (with parameters, eg. : CookieConsent.acceptService('youtube', 'features'))

Proposed fix or additional info.

No response

Version

3.0.0-rc.17

On which browser do you see the issue?

Chrome

@Striffly Striffly added the bug Something isn't working label Nov 30, 2023
@github-actions github-actions bot added the triage yet to be reviewed label Nov 30, 2023
@orestbida orestbida removed the triage yet to be reviewed label Nov 30, 2023
@orestbida
Copy link
Owner

.acceptService() with no parameters doesn't do anything (other than returning false). I'm not sure how to replicate the issue.

@Striffly
Copy link
Author

Striffly commented Nov 30, 2023

I'my sorry, I forgot to add parameters

In my case it was CookieConsent.acceptService('youtube', 'features');

This is my config :

const config = {
    "disablePageInteraction": false,
    "cookie": {
        "name": "cookies_consent"
    },
    "guiOptions": {
        "consentModal": {
            "layout": "box wide",
            "position": "bottom right",
            "flipButtons": false
        },
        "preferencesModal": {
            "layout": "box",
            "position": "left",
            "equalWeightButtons": false,
            "flipButtons": false
        }
    },
    onFirstConsent() {},

    onConsent({ cookie }) {
      if (cookie.categories.includes('ads')) {
        if (window.gtag) window.gtag('consent', 'update', { ads_storage: 'granted' });
      }

      if (cookie.categories.includes('analytics')) {
        if (window.gtag) {
          window.gtag('consent', 'update', { analytics_storage: 'granted' });
          window.gtag('send', 'pageview');
        }
      }
    },

    onChange: ({ changedCategories, changedServices, cookie }) => {
      const { categories, services } = cookie;

      for (const category in changedServices) {
        if (changedCategories.includes(category)) !categories.includes(category) && location.reload();

        for (const service of changedServices[category]) !services[category].includes(service) && location.reload();
      }
    },

    onModalShow: ({ modalName }) => {
      if (modalName !== 'preferencesModal') return;

      const modal = document.querySelector('#cc-main .pm.pm--box');
      modal.dataset.lenisPrevent = true;
    },

    "categories": {
        "necessary": {
            "readOnly": true,
            "enabled": true,
            "services": {
                "wordpress": {
                    "label": "Wordpress",
                    "Se": false
                },
                "recaptcha": {
                    "label": "reCAPTCHA",
                    "Se": false
                }
            }
        },
        "features": [],
        "analytics": {
            "autoClear": {
                "cookies": [
                    {
                        "name": {}
                    }
                ]
            }
        },
        "ads": []
    },
    "language": {
        "default": "en",
        "autoDetect": "document",
        "translations": {
            "fr-FR": {
                "consentModal": {
                    "title": "It's cookie time ! 🍪",
                    "description": "Notre site utilises des cookies pour mieux comprendre comment vous interagissez avec. Ce tracking ne sera activé que si vous l'acceptez explicitement. <a href=\"#privacy-policy\" data-cc=\"show-preferencesModal\" class=\"cc__link\">Gérer les préférences</a>",
                    "acceptAllBtn": "Accepter tout",
                    "acceptNecessaryBtn": "Accepter les cookies nécessaires",
                    "showPreferencesBtn": "Voir les préférences",
                    "closeIconLabel": "Fermer"
                },
                "preferencesModal": {
                    "title": "Préférences des cookies",
                    "acceptAllBtn": "Accepter tout",
                    "acceptNecessaryBtn": "Accepter les cookies nécessaires",
                    "savePreferencesBtn": "Enregistrer les préférences",
                    "closeIconLabel": "Fermer",
                    "sections": [
                        {
                            "description": "Notre site utilises des cookies pour mieux comprendre comment vous interagissez avec. Ce tracking ne sera activé que si vous l'acceptez explicitement."
                        },
                        {
                            "title": "Cookies strictement nécessaires",
                            "description": "Ces cookies sont essentiels au fonctionnement du site.",
                            "linkedCategory": "necessary",
                            "cookieTable": {
                                "headers": {
                                    "name": "Service",
                                    "description": "Description"
                                },
                                "body": [
                                    {
                                        "name": "Wordpress",
                                        "description": "Wordpress dépose des cookies de navigation essentiels au fonctionnement du site."
                                    },
                                    {
                                        "name": "reCAPTCHA",
                                        "description": "reCAPTCHA collecte des informations des utilisateurs pour déterminer si ils sont humains ou non."
                                    }
                                ]
                            }
                        },
                        {
                            "title": "Cookies fonctionnels",
                            "description": "Ces cookies sont déposés par des services tierces intégrés au site.",
                            "linkedCategory": "features",
                            "cookieTable": {
                                "headers": {
                                    "name": "Service",
                                    "description": "Description"
                                },
                                "body": [
                                    {
                                        "name": "Google Maps",
                                        "description": "Google Maps est utilisé pour afficher des cartes interactives."
                                    },
                                    {
                                        "name": "Youtube",
                                        "description": "Youtube est utilisé pour afficher des vidéos sur le site."
                                    }
                                ]
                            }
                        },
                        {
                            "title": "Mesure d'audience",
                            "description": "Analyser l’audience d’un site ou une application, mesurer la performance des contenus, tester des versions différentes en vue d’optimiser les choix éditoriaux.",
                            "linkedCategory": "analytics",
                            "cookieTable": {
                                "headers": {
                                    "name": "Service",
                                    "description": "Description"
                                },
                                "body": [
                                    {
                                        "name": "Google Analytics",
                                        "description": "Nous collectons des données d'utilisation du site pour déterminer comment améliorer votre navigation et celle des autres utilisateurs."
                                    }
                                ]
                            }
                        },
                        {
                            "title": "Publicité",
                            "description": "Ces cookies permettent d’afficher des publicités adaptées aux intérêts et à la navigation des utilisateurs, pour qu’elles soient plus pertinentes et ainsi éviter la diffusion d'annonces que vous avez déjà vues.",
                            "linkedCategory": "ads",
                            "cookieTable": {
                                "headers": {
                                    "name": "Service",
                                    "description": "Description"
                                },
                                "body": [
                                    {
                                        "name": "Google Ads",
                                        "description": "Nous collectons des données d'utilisation du site pour déterminer comment améliorer votre navigation et celle des autres utilisateurs."
                                    }
                                ]
                            }
                        }
                    ]
                }
            },
            "en": {
                "consentModal": {
                    "title": "It's cookie time ! 🍪",
                    "description": "Our site uses cookies to better understand how you interact with it. This tracking will only be activated if you explicitly agree to it.<a href=\"#privacy-policy\" data-cc=\"show-preferencesModal\" class=\"cc__link\">Edit preferences</a>",
                    "acceptAllBtn": "Accept all",
                    "acceptNecessaryBtn": "Aceppt only necessary cookies",
                    "showPreferencesBtn": "See preferences",
                    "closeIconLabel": "Close"
                },
                "preferencesModal": {
                    "title": "Edit cookies",
                    "acceptAllBtn": "Accept all",
                    "acceptNecessaryBtn": "Aceppt only necessary cookies",
                    "savePreferencesBtn": "Accept preferences",
                    "closeIconLabel": "Close",
                    "sections": [
                        {
                            "description": "Our site uses cookies to better understand how you interact with it. This tracking will only be activated if you explicitly agree to it."
                        },
                        {
                            "title": "Necessary cookies",
                            "description": "These cookies  are essential to the operation of the site.",
                            "linkedCategory": "necessary",
                            "cookieTable": {
                                "headers": {
                                    "name": "Service",
                                    "description": "Description"
                                },
                                "body": [
                                    {
                                        "name": "Wordpress",
                                        "description": "Wordpress add navigation cookies necessary to navigate the site."
                                    },
                                    {
                                        "name": "reCAPTCHA",
                                        "description": "reCAPTCHA collects personal information from users to make this determination of whether they're human and not a bot."
                                    }
                                ]
                            }
                        },
                        {
                            "title": "Functional cookies",
                            "description": "These cookies are deposited by third party services integrated into the site.",
                            "linkedCategory": "features",
                            "cookieTable": {
                                "headers": {
                                    "name": "Service",
                                    "description": "Description"
                                },
                                "body": [
                                    {
                                        "name": "Google Maps",
                                        "description": "Google Maps is used for displaying interactive maps."
                                    },
                                    {
                                        "name": "Youtube",
                                        "description": "Youtube is used for displaying videos."
                                    }
                                ]
                            }
                        },
                        {
                            "title": "Audience measurement",
                            "description": "Analyze the audience of a site or an application, measure the performance of content, test different versions in order to optimize editorial choices.",
                            "linkedCategory": "analytics",
                            "cookieTable": {
                                "headers": {
                                    "name": "Service",
                                    "description": "Description"
                                },
                                "body": [
                                    {
                                        "name": "Google Analytics",
                                        "description": "We collect data on how you use our website so we can understand how to make it better for you, and our other visitors."
                                    }
                                ]
                            }
                        },
                        {
                            "title": "Ads",
                            "description": "These cookies allow us to display ads that are tailored to the interests and browsing habits of our users, so that they are more relevant and avoid showing ads that you have already seen.",
                            "linkedCategory": "ads",
                            "cookieTable": {
                                "headers": {
                                    "name": "Service",
                                    "description": "Description"
                                },
                                "body": [
                                    {
                                        "name": "Google Ads",
                                        "description": "We collect data on how you use our website so we can understand how to make it better for you, and our other visitors."
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        }
    }
}

@fmarencic
Copy link

Happens to me as well. The problem is in this new batch of code:

if(!categories){
    enabledCategories = _acceptedCategories;
    //{{START: GUI}}
    enabledCategories = _preferencesModalExists && retrieveCategoriesFromModal();
    //{{END: GUI}}
} else{
    .
    .
    .
}

// Remove invalid and excluded categories
enabledCategories = enabledCategories.filter(category =>
    !elContains(_allCategoryNames, category) ||
    !elContains(excludedCategories, category)
);

When !categories resolves to true, the first line gets immediately overwritten with a value false in my case, I assume in OP's case as well, because _preferencesModalExists is false. Couple of lines below, a .filter function is called on it and it fails.

@orestbida
Copy link
Owner

@fmarencic you're spot on!

@orestbida orestbida added this to the v3.0.0 milestone Dec 10, 2023
@ifConditionTrue
Copy link

So is this the reason I randomly get the following error:

cookieconsent.js:7 Uncaught TypeError: i.filter is not a function
at cookieconsent.js:7:15139
at He (cookieconsent.js:7:15188)
at e.acceptService (cookieconsent.js:7:18484)
at onChange (cookieconsent-config.js:32:23)
at W (iframemanager.js:6:4136)
at Object.acceptService (iframemanager.js:6:4408)
at HTMLButtonElement. (iframemanager.js:6:2440)
(anonymous) @ cookieconsent.js:7
He @ cookieconsent.js:7
e.acceptService @ cookieconsent.js:7
onChange @ cookieconsent-config.js:32
W @ iframemanager.js:6
acceptService @ iframemanager.js:6
(anonymous) @ iframemanager.js:6

Iframes still load, category toggles are still set in the consent modal, but the service toggle does not change. im_cookie is set, cc_cookie is not updated. I thought my setup was wrong, but it does not fail consistently. I can confirm the promblem is not present in CookieConsent 3.0.0-rc.15. I can provide my code but it works fine besides this.

I love the cookieconsent/iframemanager plugins you are building, thanks a lot!
This one had me struggling for a while though.

Do these plugins have to be integrated separately or could the iframemanager and cookieconsent files be combined, since they interact and basically make up one great tool? I would prefer running one script file, one configuration file and one css file.

Thanks

@fmarencic
Copy link

@ifConditionTrue your are correct, this bug is happening to you as well. My solution for now was to downgrade to rc.16 version.

I'm installing both CookieConsent and iframemanager through package manager and I'm loading them in one JS file (CSS and JS) where they're connected and integrated. So from my perspective, they are indeed one script file.

@orestbida
Copy link
Owner

fixed in baf6380

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug:confirmed bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants