Improved GDPR compliance
- Add more customization TODO: Update styling
This commit is contained in:
@ -29,6 +29,21 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Show manage preferences button when cookies are already set
|
||||
function showManageButton() {
|
||||
document.getElementById('gdpr-cookie-manage-button').style.display = 'block';
|
||||
}
|
||||
|
||||
// After user consents, hide banner and modal and show the manage button
|
||||
function afterConsent() {
|
||||
// Hide banner and modal
|
||||
hideModal();
|
||||
document.getElementById('gdpr-cookie-banner').style.display = 'none';
|
||||
|
||||
// Show manage button
|
||||
showManageButton();
|
||||
}
|
||||
|
||||
// Check if cookie consent is already set
|
||||
var cookieConsent = getCookie('gdpr_cookie_consent');
|
||||
|
||||
@ -39,6 +54,9 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
// Apply cookie preferences
|
||||
var consentPreferences = JSON.parse(cookieConsent);
|
||||
applyConsentPreferences(consentPreferences);
|
||||
|
||||
// Show the manage button since consent was already given
|
||||
showManageButton();
|
||||
}
|
||||
|
||||
// Banner buttons
|
||||
@ -67,6 +85,11 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
acceptSelectedCookies();
|
||||
});
|
||||
|
||||
// Manage button (for after consent is given)
|
||||
document.getElementById('gdpr-cookie-manage').addEventListener('click', function() {
|
||||
showModal();
|
||||
});
|
||||
|
||||
// Functions
|
||||
function showModal() {
|
||||
document.getElementById('gdpr-cookie-banner').style.display = 'none';
|
||||
@ -103,8 +126,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
setCookie('gdpr_cookie_consent', JSON.stringify(preferences), 365);
|
||||
applyConsentPreferences(preferences);
|
||||
hideModal();
|
||||
document.getElementById('gdpr-cookie-banner').style.display = 'none';
|
||||
afterConsent(); // Use the new function for consistent post-consent behavior
|
||||
}
|
||||
|
||||
function declineAllCookies() {
|
||||
@ -117,8 +139,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
setCookie('gdpr_cookie_consent', JSON.stringify(preferences), 365);
|
||||
applyConsentPreferences(preferences);
|
||||
hideModal();
|
||||
document.getElementById('gdpr-cookie-banner').style.display = 'none';
|
||||
afterConsent(); // Use the new function for consistent post-consent behavior
|
||||
}
|
||||
|
||||
function acceptSelectedCookies() {
|
||||
@ -134,8 +155,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
setCookie('gdpr_cookie_consent', JSON.stringify(preferences), 365);
|
||||
applyConsentPreferences(preferences);
|
||||
hideModal();
|
||||
document.getElementById('gdpr-cookie-banner').style.display = 'none';
|
||||
afterConsent(); // Use the new function for consistent post-consent behavior
|
||||
}
|
||||
|
||||
function applyConsentPreferences(preferences) {
|
||||
@ -179,6 +199,11 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
function disableAnalytics() {
|
||||
// Example: Disable Google Analytics
|
||||
window['ga-disable-UA-XXXXXXXX-X'] = true;
|
||||
|
||||
// Remove existing GA cookies
|
||||
document.cookie = '_ga=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT; Domain=.' + window.location.hostname;
|
||||
document.cookie = '_gid=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT; Domain=.' + window.location.hostname;
|
||||
document.cookie = '_gat=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT; Domain=.' + window.location.hostname;
|
||||
}
|
||||
|
||||
function enableAnalytics() {
|
||||
@ -187,12 +212,20 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
}
|
||||
|
||||
function disableMarketing() {
|
||||
// Example implementation
|
||||
// You would implement according to your specific marketing cookies
|
||||
// Example implementation for common marketing cookies
|
||||
var marketingCookies = ['_fbp', 'fr', 'IDE', 'MUID', 'personalization_id'];
|
||||
var domains = [window.location.hostname, '.' + window.location.hostname];
|
||||
|
||||
marketingCookies.forEach(function(cookie) {
|
||||
domains.forEach(function(domain) {
|
||||
document.cookie = cookie + '=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT; Domain=' + domain;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function enableMarketing() {
|
||||
// Example implementation
|
||||
// You would implement according to your specific marketing cookies
|
||||
// For enabling marketing, we typically don't need to do anything special
|
||||
// The marketing scripts will set their cookies when they load
|
||||
// Just ensure the marketing scripts are loaded after checking consent
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user