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

Banner triggering in both Accept and Deny cases #13

Open
toktor opened this issue Sep 19, 2024 · 0 comments
Open

Banner triggering in both Accept and Deny cases #13

toktor opened this issue Sep 19, 2024 · 0 comments

Comments

@toktor
Copy link

toktor commented Sep 19, 2024

if ( !denied_time && cmplz_get_banner_status() === 'dismissed' ) {

It seems that complianz has changed the cookie flow and "dismissed" status is given on both approve and deny choices, therefore this code will trigger on either case, regardless has user accepted or denied the consent.

We created a way where we read the cookie state itself, and only run this code when either permission cookies itself are set or denied. If needed I can try to create a pull request here.

Example code here:

        function cmplzMarketingCookieStatus() {
            let cookie_name = "cmplz_rt_marketing=";
            let cArr = document.cookie.split(';');
            let marketing_status=false;
            for (let i = 0; i < cArr.length; i++) {
                let c = cArr[i].trim();
                if (c.indexOf(cookie_name) == 0)
                    marketing_status = c.substring(cookie_name.length, c.length);
            }
            return marketing_status;
        }
        function checkMarketingCookieExists() {
            const cookieName = "cmplz_rt_marketing";
            const cookies = document.cookie.split(';');
            
            for (let i = 0; i < cookies.length; i++) {
                let cookie = cookies[i].trim();
                if (cookie.startsWith(cookieName + "=")) {
                    return true
                }
            }
            
            return false;
        }
        document.addEventListener("cmplz_cookie_warning_loaded", function() {

            console.log("run function");
            if (!checkMarketingCookieExists() && cmplz_get_banner_status() === 'dismissed') {
                console.log("no marketing cookie, trigger code");

                    let denied_time = get_denied_time();
                    console.log(denied_time);
                    if ( !denied_time && cmplz_get_banner_status() === 'dismissed') {
                        set_denied_cookie();
                    } else {
                        let date = new Date();
                        let current_time = date.getTime();

                        let expire_on = parseInt(denied_time);

                        if ( current_time > expire_on ){
                            console.log("expired");
                            cmplz_set_banner_status('show');
                            set_denied_cookie();
                        } else {
                            console.log("not expired");
                        }
                    }
                    
                }

        });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant