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

Show consent modal every load until all cookies accepted #58

Closed danieltvaz closed 3 years ago

danieltvaz commented 3 years ago

HI there! Amazing script for first, ty for that ;)

For now i need my users to accept all cookies, even optionally ones, and for that i'm thinking, is possible to show the consent modal every time my users load on my page, if they do not accept ALL cookies? I mean. I have 3 cookies on modal. One is mandatory (readonly) and the other two are optionally. So if they accept just the mandatory one, next time they load my page the consent screen doesnt show up, i need a differently behavior, i need this consent modal show everytime if they do not accept all other cookies, i see this a way to "force" then to accept all. Is there a builtin option for that ?

orestbida commented 3 years ago

Hi @danieltvaz,

yes, you can achieve this, although not with the current API. It would look something like this:


// using as example 4 categories in total
onAccept: function(preferences){

    // if not all 4 categories are accepted ...
    if(preferences.level.length < 4){
        // delete cookieconsent's own cookie, so that 
        // the next time they visit the page, the consent modal appears again
        cc.eraseCookies(['cc_cookie']);
    }
}

Note: .eraseCookies() will be available in the upcoming v2.5 version, so as of now you should use something like this proposed function to erase cookies.

danieltvaz commented 3 years ago

Thx for fast reply! This is exactly what i'm doing right now to solve this =))) Ty again!

orestbida commented 3 years ago

@danieltvaz ,

just released v2.5.0, you can now use the proposed cc.eraseCookies(['cc_cookie']);

danieltvaz commented 3 years ago

nice!! thx in advance