'; cPrompt.innerHTML = cPromptContent; cPrompt.setAttribute('id', 'gdprConsentPrompt'); document.body.appendChild(cPrompt); document.getElementById('gdpr_consent').addEventListener('click', function(){ addGDPRConsent(); document.getElementById('gdprConsentPrompt').outerHTML = ''; }); }, {once: true}); } // add the consent cookie, run all queued scripts, send a GA event if/when GA is enabled function addGDPRConsent (){ try { var d = new Date(); d.setDate(d.getDate() + 90); document.cookie = 'gdpr=true;expires=' + d.toUTCString() + ';path=/'; window.gdpr = true; for (var s in scriptQueue){ var v = scriptQueue[s]; runGDPRConsented(v.src, v.complete); } if(typeof ga === 'function') { ga('send', 'event', { eventCategory: 'gdpr', eventAction: 'consent', transport: 'beacon', nonInteraction: true }); } return true; } catch (e){ console.error('GDPR: we failed to save the cookie.\nError:', e.message); return false; } } // check if file should be run immediately or if it should wait for consent function runGDPRConsented(src, complete){ if(!src){ return false; } if(window.gdpr === true) { let type = typeof src, tag; try { switch (type) { case 'string': tag = document.createElement('script'); tag.setAttribute('type', 'text/javascript'); if (complete) { tag.onload = function () { if (typeof complete === 'function') { complete(); } else { console.log(complete); } }; } tag.src = src; document.head.appendChild(tag); break; case 'function': src(); if (complete && typeof complete === 'function') { complete(); } else if (complete) { console.log(complete); } break; default: return false; } } catch(e){ console.error('GDPR: we failed to run the requested script: '+src+'\nError:', e.message); } } else { scriptQueue.push({'src': src, 'complete': complete}); } } Boycott - Shared