-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d766dd4
commit e8fa80c
Showing
2 changed files
with
102 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,63 @@ | ||
|
||
<div id="cookie-consent-banner" class="cookie-consent-banner"> | ||
<h3>Cookie settings</h3> | ||
<p>We use cookies to provide you with the best possible experience. They also allow us to analyze user behavior in order to constantly improve the website for you.</p> | ||
<button id="btn-accept-all" class="cookie-consent-button btn-success">Accept All</button> | ||
<button id="btn-accept-some" class="cookie-consent-button btn-outline">Accept Selection</button> | ||
<button id="btn-reject-all" class="cookie-consent-button btn-grayscale">Reject All</button> | ||
<div class="cookie-consent-options"> | ||
<label><input id="consent-necessary" type="checkbox" value="Necessary" checked disabled>Necessary</label> | ||
<label><input id="consent-analytics" type="checkbox" value="Analytics" checked>Analytics</label> | ||
<label><input id="consent-preferences" type="checkbox" value="Preferences" checked>Preferences</label> | ||
<label><input id="consent-marketing" type="checkbox" value="Marketing">Marketing</label> | ||
<label><input id="consent-necessary" type="checkbox" value="Necessary" checked disabled>Necessary</label> | ||
<label><input id="consent-analytics" type="checkbox" value="Analytics" checked>Analytics</label> | ||
<label><input id="consent-preferences" type="checkbox" value="Preferences" checked>Preferences</label> | ||
<label><input id="consent-marketing" type="checkbox" value="Marketing">Marketing</label> | ||
</div> | ||
</div> | ||
|
||
<script> | ||
|
||
function hideBanner() { | ||
document.getElementById('cookie-consent-banner').style.display = 'none'; | ||
} | ||
function hideBanner() { | ||
document.getElementById('cookie-consent-banner').style.display = 'none'; | ||
} | ||
|
||
if (localStorage.getItem('consentMode') === null) { | ||
|
||
document.getElementById('btn-accept-all').addEventListener('click', function() { | ||
setConsent({ | ||
necessary: true, | ||
analytics: true, | ||
preferences: true, | ||
marketing: true | ||
}); | ||
hideBanner(); | ||
}); | ||
document.getElementById('btn-accept-some').addEventListener('click', function() { | ||
setConsent({ | ||
necessary: true, | ||
analytics: document.getElementById('consent-analytics').checked, | ||
preferences: document.getElementById('consent-preferences').checked, | ||
marketing: document.getElementById('consent-marketing').checked | ||
}); | ||
hideBanner(); | ||
}); | ||
document.getElementById('btn-reject-all').addEventListener('click', function() { | ||
setConsent({ | ||
necessary: false, | ||
analytics: false, | ||
preferences: false, | ||
marketing: false | ||
}); | ||
hideBanner(); | ||
}); | ||
document.getElementById('cookie-consent-banner').style.display = 'block'; | ||
} | ||
|
||
if(localStorage.getItem('consentMode') === null) { | ||
|
||
document.getElementById('btn-accept-all').addEventListener('click', function() { | ||
setConsent({ | ||
necessary: true, | ||
analytics: true, | ||
preferences: true, | ||
marketing: true | ||
}); | ||
hideBanner(); | ||
}); | ||
document.getElementById('btn-accept-some').addEventListener('click', function() { | ||
setConsent({ | ||
necessary: true, | ||
analytics: document.getElementById('consent-analytics').checked, | ||
preferences: document.getElementById('consent-preferences').checked, | ||
marketing: document.getElementById('consent-marketing').checked | ||
}); | ||
hideBanner(); | ||
}); | ||
document.getElementById('btn-reject-all').addEventListener('click', function() { | ||
setConsent({ | ||
necessary: false, | ||
analytics: false, | ||
preferences: false, | ||
marketing: false | ||
}); | ||
hideBanner(); | ||
}); | ||
document.getElementById('cookie-consent-banner').style.display = 'block'; | ||
} | ||
|
||
function setConsent(consent) { | ||
const consentMode = { | ||
'functionality_storage': consent.necessary ? 'granted' : 'denied', | ||
'security_storage': consent.necessary ? 'granted' : 'denied', | ||
'ad_storage': consent.marketing ? 'granted' : 'denied', | ||
'analytics_storage': consent.analytics ? 'granted' : 'denied', | ||
'personalization': consent.preferences ? 'granted' : 'denied', | ||
}; | ||
gtag('consent', 'update', consentMode); | ||
localStorage.setItem('consentMode', JSON.stringify(consentMode)); | ||
} | ||
|
||
</script> | ||
function setConsent(consent) { | ||
const consentMode = { | ||
'functionality_storage': consent.necessary ? 'granted' : 'denied', | ||
'security_storage': consent.necessary ? 'granted' : 'denied', | ||
'ad_storage': consent.marketing ? 'granted' : 'denied', | ||
'analytics_storage': consent.analytics ? 'granted' : 'denied', | ||
'personalization_storage': consent.preferences ? 'granted' : 'denied', | ||
}; | ||
gtag('consent', 'update', consentMode); | ||
localStorage.setItem('consentMode', JSON.stringify(consentMode)); | ||
} | ||
</script> |
105 changes: 51 additions & 54 deletions
105
tutorials/4-consent-mode/src/public/partials/consent.eta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,63 @@ | ||
|
||
<div id="cookie-consent-banner" class="cookie-consent-banner"> | ||
<h3>Cookie settings</h3> | ||
<p>We use cookies to provide you with the best possible experience. They also allow us to analyze user behavior in order to constantly improve the website for you.</p> | ||
<button id="btn-accept-all" class="cookie-consent-button btn-success">Accept All</button> | ||
<button id="btn-accept-some" class="cookie-consent-button btn-outline">Accept Selection</button> | ||
<button id="btn-reject-all" class="cookie-consent-button btn-grayscale">Reject All</button> | ||
<div class="cookie-consent-options"> | ||
<label><input id="consent-necessary" type="checkbox" value="Necessary" checked disabled>Necessary</label> | ||
<label><input id="consent-analytics" type="checkbox" value="Analytics" checked>Analytics</label> | ||
<label><input id="consent-preferences" type="checkbox" value="Preferences" checked>Preferences</label> | ||
<label><input id="consent-marketing" type="checkbox" value="Marketing">Marketing</label> | ||
<label><input id="consent-necessary" type="checkbox" value="Necessary" checked disabled>Necessary</label> | ||
<label><input id="consent-analytics" type="checkbox" value="Analytics" checked>Analytics</label> | ||
<label><input id="consent-preferences" type="checkbox" value="Preferences" checked>Preferences</label> | ||
<label><input id="consent-marketing" type="checkbox" value="Marketing">Marketing</label> | ||
</div> | ||
</div> | ||
|
||
<script> | ||
|
||
function hideBanner() { | ||
document.getElementById('cookie-consent-banner').style.display = 'none'; | ||
} | ||
function hideBanner() { | ||
document.getElementById('cookie-consent-banner').style.display = 'none'; | ||
} | ||
|
||
if (localStorage.getItem('consentMode') === null) { | ||
|
||
document.getElementById('btn-accept-all').addEventListener('click', function() { | ||
setConsent({ | ||
necessary: true, | ||
analytics: true, | ||
preferences: true, | ||
marketing: true | ||
}); | ||
hideBanner(); | ||
}); | ||
document.getElementById('btn-accept-some').addEventListener('click', function() { | ||
setConsent({ | ||
necessary: true, | ||
analytics: document.getElementById('consent-analytics').checked, | ||
preferences: document.getElementById('consent-preferences').checked, | ||
marketing: document.getElementById('consent-marketing').checked | ||
}); | ||
hideBanner(); | ||
}); | ||
document.getElementById('btn-reject-all').addEventListener('click', function() { | ||
setConsent({ | ||
necessary: false, | ||
analytics: false, | ||
preferences: false, | ||
marketing: false | ||
}); | ||
hideBanner(); | ||
}); | ||
document.getElementById('cookie-consent-banner').style.display = 'block'; | ||
} | ||
|
||
if(localStorage.getItem('consentMode') === null) { | ||
|
||
document.getElementById('btn-accept-all').addEventListener('click', function() { | ||
setConsent({ | ||
necessary: true, | ||
analytics: true, | ||
preferences: true, | ||
marketing: true | ||
}); | ||
hideBanner(); | ||
}); | ||
document.getElementById('btn-accept-some').addEventListener('click', function() { | ||
setConsent({ | ||
necessary: true, | ||
analytics: document.getElementById('consent-analytics').checked, | ||
preferences: document.getElementById('consent-preferences').checked, | ||
marketing: document.getElementById('consent-marketing').checked | ||
}); | ||
hideBanner(); | ||
}); | ||
document.getElementById('btn-reject-all').addEventListener('click', function() { | ||
setConsent({ | ||
necessary: false, | ||
analytics: false, | ||
preferences: false, | ||
marketing: false | ||
}); | ||
hideBanner(); | ||
}); | ||
document.getElementById('cookie-consent-banner').style.display = 'block'; | ||
} | ||
|
||
function setConsent(consent) { | ||
const consentMode = { | ||
'functionality_storage': consent.necessary ? 'granted' : 'denied', | ||
'security_storage': consent.necessary ? 'granted' : 'denied', | ||
'ad_storage': consent.marketing ? 'granted' : 'denied', | ||
'analytics_storage': consent.analytics ? 'granted' : 'denied', | ||
'personalization': consent.preferences ? 'granted' : 'denied', | ||
}; | ||
gtag('consent', 'update', consentMode); | ||
localStorage.setItem('consentMode', JSON.stringify(consentMode)); | ||
} | ||
|
||
</script> | ||
function setConsent(consent) { | ||
const consentMode = { | ||
'functionality_storage': consent.necessary ? 'granted' : 'denied', | ||
'security_storage': consent.necessary ? 'granted' : 'denied', | ||
'ad_storage': consent.marketing ? 'granted' : 'denied', | ||
'analytics_storage': consent.analytics ? 'granted' : 'denied', | ||
'personalization_storage': consent.preferences ? 'granted' : 'denied', | ||
}; | ||
gtag('consent', 'update', consentMode); | ||
localStorage.setItem('consentMode', JSON.stringify(consentMode)); | ||
} | ||
</script> |