Where does all the data get stored in the Cookie Consent widget?

Hi there, @Hugh :wave:

Thank you so much for the feedback!

While our widget doesn’t process cookies, I am happy to say that it’s possible to decline cookies, using a Google Analytics code and JS script to meet new cookie policy requirements.

Here are the scripts :slightly_smiling_face:

Please add this part of the code to your website <head>:

<script async src="https://www.googletagmanager.com/gtag/js?id=G-ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-ID');
gtag('consent', 'default', {
  'ad_storage': 'denied',
  'analytics_storage': 'denied',
  'ad_user_data': 'denied',
  'ad_personalization': 'denied',
  'wait_for_update': 3000
});
</script>

In the code above, in the 1st and 6th lines you need to replace G-ID with your actual website ID for Google Analytics. This article will help you find your ID - Find your Google tag ID.

Also, you can insert additional permissions (if required) after 11th line of the script above after ‘ad_personalization’: ‘denied’. Please make sure you’ve added them in this format:
‘your_permission’: ‘denied’

And then add the rest of the script to the Custom JS section on the Appearance tab in the widget editor:

const consents = ['ad_storage', 'analytics_storage', 'ad_user_data', 'ad_personalization'];

function sendEvent(config) {
    if (typeof gtag !== "undefined") {
        gtag('consent', config.action, {
            ...config.consents
        });
    }
}

function eappsDispatchAnalyticsEvent(event, selector, config) {
    function isHitClass(e, selector) {
        return e.target && e.target.closest(selector);
    }
    if (isHitClass(event, selector)) {
        sendEvent(config);
    }
}

const getConfig = (status) => ({
    action: 'update',
    consents: {
        ...consents.reduce((res, consent) => {
            res[consent] = status;
            return res;
        }, {})
    }
});

const answer = JSON.parse(localStorage.getItem("cookie-consent.answer"));
switch (answer) {
    case 'allow':
        sendEvent(getConfig('granted'));
        break;
    case 'decline':
        sendEvent(getConfig('denied'));
        break;
    default:
        document.addEventListener('click', function (event) {
            eappsDispatchAnalyticsEvent(event, '.eapp-cookie-consent-actions-accept', getConfig('granted'));
            eappsDispatchAnalyticsEvent(event, '.eapp-cookie-consent-actions-decline', getConfig('denied'));
        });
        break;
}
In the script above you can insert additional permissions in the first line after ‘ad_personalization’:
const consents = ['ad_storage', 'analytics_storage', 'ad_user_data', 'ad_personalization', 'your_permission'];

Note: it may take 48 hours for those updates to show up on Google Analytics.

Also, just a kindly reminder that our Cookie Consent widget should be installed on every page of your website to work correctly.

Test it out and let us know how it worked :slightly_smiling_face:


By the way, we have a Wishlist request for the Cookie Consent with actual blocker. You can upvote this idea here - Cookie consent with actual cookie blocker on decline