This example demonstrates advanced features including granular cookie controls, custom styling, and analytics integration.
This example includes Google Analytics integration that respects user consent choices:
// Advanced configuration with all features
cookieconsent.extended.init({
ui: {
position: 'center',
showPreferences: true,
animationType: 'slide',
backdrop: true
},
categories: {
necessary: {
enabled: true,
locked: true,
name: 'Essential Cookies',
description: 'Required for basic website functionality including security, network management, and accessibility.'
},
analytics: {
enabled: false,
locked: false,
name: 'Analytics Cookies',
description: 'Help us understand how visitors interact with our website by collecting and reporting information anonymously.'
},
marketing: {
enabled: false,
locked: false,
name: 'Marketing Cookies',
description: 'Used to track visitors across websites to display relevant and engaging advertisements.'
},
preferences: {
enabled: false,
locked: false,
name: 'Preference Cookies',
description: 'Enable the website to remember information that changes how it behaves or looks.'
}
},
analytics: {
enabled: true,
gtag: true,
customCallback: function(action, categories) {
console.log('Analytics callback:', action, categories);
}
},
compliance: {
gdprCompliant: true,
recordConsent: true,
auditTrail: true
},
callbacks: {
onAcceptAll: function(categories) {
enableAllTracking();
updateStatus('All categories accepted');
},
onRejectAll: function(categories) {
disableAllTracking();
updateStatus('All non-essential categories rejected');
},
onCategoryToggle: function(category, enabled) {
handleCategoryToggle(category, enabled);
}
}
});