This script will hide empty cookie categories in the banner. It attaches to an event, so it can be placed anywhere on the page. Hidden categories are toggled off, so the visitor will not consent to the hidden categories.
If you are using a Swift banner template, you can use the following script:
<script type="text/javascript">
window.addEventListener("CookiebotOnDialogDisplay", e => {
const detailCategories = ["Preference", "Statistics", "Advertising", "Unclassified"],
toggleCategories = ["Preferences", "Statistics", "Marketing"];
detailCategories.forEach(e => {
if (CookieConsentDialog[`cookieTable${e}Count`] === 0)
document.getElementById(
`CybotCookiebotDialogDetailBodyContentCookieContainer${e}Card`
).parentNode.style.display = "none";
});
for (let i = 0; i < 3; i++)
if (CookieConsentDialog[`cookieTable${detailCategories[i]}Count`] === 0)
document.querySelector(
`label[for=CybotCookiebotDialogBodyLevelButton${toggleCategories[i]}]`
).parentNode.style.display = "none";
}, !1)
</script>
For Elemental banner templates, use the script below:
window.addEventListener('CookiebotOnDialogDisplay', function() {
const categories = ['Preference','Statistics','Advertising','Unclassified'],
categoryMap = new Map([['Preference','Preferences'],['Advertising','Marketing']]);
for (const category of categories) {
if (CookieConsentDialog[`cookieTable${category}Count`] == 0) {
document.getElementById(
`CybotCookiebotDialogDetailBodyContentCookieContainer${category}`
).style.display ='none';
if (category != 'Unclassified') {
document.getElementById(
`CybotCookiebotDialogBodyLevelButton${categoryMap.get(category) || category}`
).parentNode.style.display = 'none';
document.getElementById(
`CybotCookiebotDialogBodyLevelButton${categoryMap.get(category) || category}`
).checked = '';
}
}
}
});
Comments
0 comments
Please sign in to leave a comment.