cookieconsent icon indicating copy to clipboard operation
cookieconsent copied to clipboard

Cumulative delay

Open jelen07 opened this issue 2 years ago • 3 comments

Feature request

As a UX designer I would like to A/B testing user's behavior when getting consent. I would like to not bother the users too much and show the consent modal with a bigger delay.

Proposed solution

Add new settings cumulative_delay (by default false) which will be (if true) counting delay across pages (requests). When a user visits a webpage, the cookie consent starts counting delay (ie. 10s). After 4s user visit another page, and after 6s (page load time does not matter here) the consent modal will appear.

A new key in cookie value should be introduced as a time of the first visit.

jelen07 avatar Nov 20 '21 08:11 jelen07

This is quite a "niche" feature and I don't think it's worth adding it for everyone.

You can still make it work though, since the plugin allows you to read and write data inside the data field of the cookie. Perhaps something like this would work:


var cc = initCookieConsent();

const default_cumulative_delay = 10;
const cookie_data = cc.get('data');
const cookie_delay = cookie_data && cookie_data.cumulative_delay;

let current_delay = typeof cookie_delay === "number" ? cookie_delay : default_cumulative_delay;

if(current_delay > 0){
    var delayedShowModal = setInterval(function(){
        
        // Update cookie's "data" field (every second)
        cc.set('data', {value: { cumulative_delay: --current_delay }});
        
        // Stop interval and show consent modal
        if(current_delay === 0){
            clearInterval(delayedShowModal);
            cc.show();
        }
    
    }, 1000);
}

cc.run({
    // ...
    autorun: current_delay === 0,
    // ...
});

you should also call clearInterval() inside the onAccept() method, just so to avoid any weird behaviours

//...
onAccept: function(){
    clearInterval(delayedShowModal);
},
// ...

orestbida avatar Nov 20 '21 16:11 orestbida

Hi Orest, thanks for the answer. I was wondering, that it could be a nice feature already implemented in this solution, but you're completely right. There should be a specific amount of % of users (resp. implementations) who will use this feature. Let's implement it out of cookie consent 🙂

jelen07 avatar Nov 21 '21 07:11 jelen07

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 21 '21 08:12 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Feb 26 '23 00:02 stale[bot]