elleracompany / craft-cookie-consent

GDPR-Compliant cookie consent banner for Craft CMS
Other
6 stars 5 forks source link

Force refresh after preferences have been set #36

Closed jamiewade closed 4 years ago

jamiewade commented 4 years ago

It might be useful to include an option that re-loads the current page once a user has set their cookie preferences? We have lots of Twig code that only runs if certain cookie groups have been enabled:

{% if craft.cookieConsent.getConsent('engb-marketing') %}

So these will not run once a user has set their preferences. It will only run on the next page load.

jamiewade commented 4 years ago

We are using our own custom JavaScript, but I used the plugins JavaScript as a starting point. This is achieving what I need for now:

function submitConsent(event) {
    // Rest of the code is here

    setTimeout(function() {
        location.reload();
    }, 1000);
}

It just refreshes the page with a 1 second delay once the submitConsent function has been run.