We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Cookie Consent Simple Implementation?

Development and Programming

NikiW's avatar
NikiW
36 posts
about 3 weeks ago
NikiW's avatar NikiW

consent module primer

       
User BULfYYMv's avatar
User BULfYYMv
59 posts
about 3 weeks ago
User BULfYYMv's avatar User BULfYYMv

Oh nice. That should help.

       
User BULfYYMv's avatar
User BULfYYMv
59 posts
about 3 weeks ago
User BULfYYMv's avatar User BULfYYMv

Thank you

       
NikiW's avatar
NikiW
36 posts
about 3 weeks ago
NikiW's avatar NikiW

np! 🙂

       
User z9NVFGOr's avatar
User z9NVFGOr
13 posts
about 3 weeks ago
User z9NVFGOr's avatar User z9NVFGOr

I have a snippet of JS that might help too? - to tie into a cookie banner so the page doesn’t need to be reloaded with accept/deny.

       
User z9NVFGOr's avatar
User z9NVFGOr
13 posts
about 3 weeks ago
User z9NVFGOr's avatar User z9NVFGOr
const submitForm = (e) => {
    e.preventDefault();
    const cookieConsentForm = e.target;
    const formData = new FormData(cookieConsentForm);
    const action = cookieConsentForm.action = '/';
    fetch(cookieConsentForm.action, {
     method: 'POST',
     body: formData
    })
    // if the response is not a 200 OK, reject the promise
    .then(response => {
    if (!response.ok) {
     throw new Error('Network response was not ok');
     }
    // if the response is ok remove the cookie consent bar
     document.querySelector('.cookiebar').classList.add('remove');
    })
};

document.addEventListener('DOMContentLoaded', function() {
    let cookieConsentBar = document.querySelector('.cookiebar');
    let allForms = document.querySelectorAll('.cookieConsentForm');
    allForms.forEach(form => {
     form.addEventListener('submit', submitForm);
     // do ui stuff like set button to pointer events none + loading
     cookieConsentButton.addEventListener('click', function() {
      cookieConsentButton.classList.add('btn_loading');
     });
    });
});

console.log〈'i: Cookies: requested'〉;
       
User z9NVFGOr's avatar
User z9NVFGOr
13 posts
about 3 weeks ago
User z9NVFGOr's avatar User z9NVFGOr

That’s it paraphrased. You can also then remove the cookie bar programatically on full refresh with if consent granted .

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.