Solve common issues and get Extended Cookie Consent working perfectly.
Symptoms: No popup appears on page load
cookieconsent.extended.init() is called// Debug: Check if library loaded
console.log('cookieconsent available:', typeof cookieconsent);
console.log('extended available:', typeof cookieconsent.extended);
// Force clear and reinitialize
localStorage.clear();
document.cookie.split(";").forEach(function(c) {
document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/");
});
location.reload();
Symptoms: Popup shows but looks unstyled or wrong
ui: { theme: null }/* Fix z-index issues */
.cc-popup-extended {
z-index: 999999 !important;
}
/* Override conflicting styles */
.cc-popup-extended * {
box-sizing: border-box !important;
}
Symptoms: User choices aren't saved between sessions
<!-- Test if CDN is accessible -->
<script>
fetch('https://cdn.jsdelivr.net/gh/casjay-templates/cookieconsent@main/dist/cookieconsent.min.js')
.then(response => console.log('CDN accessible:', response.ok))
.catch(error => console.error('CDN error:', error));
</script>
<!-- Fallback to local files -->
<link rel="stylesheet" href="/assets/css/cookieconsent.min.css">
<script src="/assets/js/cookieconsent.min.js"></script>
// If using module bundlers, try:
import cookieconsent from './path/to/cookieconsent.js';
// Or for ES modules:
import('./cookieconsent.min.js')
.then(module => {
// Initialize here
window.cookieconsent.extended.init();
});
Common configuration mistakes and fixes:
// â Wrong: Missing nested structure
cookieconsent.extended.init({
theme: 'dracula', // Should be ui.theme
position: 'center' // Should be ui.position
});
// â
Correct: Proper nesting
cookieconsent.extended.init({
ui: {
theme: 'dracula',
position: 'center'
},
content: {
header: 'Cookie Notice',
message: 'We use cookies...'
}
});
// â Wrong: Missing required properties
categories: {
analytics: {
name: 'Analytics' // Missing enabled, locked, description
}
}
// â
Correct: Complete category configuration
categories: {
analytics: {
enabled: false, // Required
locked: false, // Required
name: 'Analytics', // Required
description: 'Help us improve our website.' // Required
}
}
// Debug: Check available themes
console.log('Available themes:', cookieconsent.extended.getAvailableThemes());
// Test with a simple theme
cookieconsent.extended.init({
ui: { theme: 'github-light' } // Try a basic theme first
});
/* Create custom theme with CSS variables */
.cc-popup-extended.cc-theme-custom {
--cc-primary-color: #your-color;
--cc-background: #your-background;
--cc-text-primary: #your-text;
}
/* Then use it */
cookieconsent.extended.init({
ui: { theme: 'custom' }
});
// â Wrong: GA initialized with granted consent
gtag('config', 'GA_MEASUREMENT_ID');
// â
Correct: Initialize with denied, update on consent
gtag('consent', 'default', {
'analytics_storage': 'denied',
'ad_storage': 'denied'
});
gtag('config', 'GA_MEASUREMENT_ID');
// Update when user consents
cookieconsent.extended.init({
callbacks: {
onAcceptAll: function(categories) {
gtag('consent', 'update', {
'analytics_storage': 'granted',
'ad_storage': 'granted'
});
}
}
});
// Push consent data to GTM dataLayer
window.addEventListener('cookieConsentChange', function(event) {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'cookie_consent_update',
'analytics_consent': event.detail.categories.analytics,
'marketing_consent': event.detail.categories.marketing
});
});
bottom-bar for mobile<!-- Ensure proper viewport -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
// Responsive positioning
const isMobile = window.innerWidth <= 768;
cookieconsent.extended.init({
ui: {
position: isMobile ? 'bottom-bar' : 'bottom-right',
theme: 'material-light'
}
});
/* Fix iOS Safari scrolling issues */
.cc-popup-extended {
-webkit-overflow-scrolling: touch;
}
/* Fix position fixed issues */
.cc-popup-container.bottom-bar {
position: absolute;
bottom: 0;
}
.min.css and .min.js<!-- Defer loading for better performance -->
<script defer src="cookieconsent.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
cookieconsent.extended.init({
ui: {
showPreferences: false, // Reduce complexity
animationType: 'fade' // Lighter animation
}
});
});
</script>
// Proper cleanup in SPAs
function cleanupCookieConsent() {
// Remove event listeners
window.removeEventListener('cookieConsentChange', yourHandler);
// Clear any intervals/timeouts
// Remove DOM elements if needed
}
// Call cleanup when navigating in SPAs
window.addEventListener('beforeunload', cleanupCookieConsent);
Copy and paste these commands in your browser console:
// Check if library is loaded
console.log('Cookie Consent Library Check:');
console.log('- Main library:', typeof cookieconsent !== 'undefined');
console.log('- Extended API:', typeof cookieconsent?.extended !== 'undefined');
console.log('- Version info:', cookieconsent?.version || 'Unknown');
// Check current consent status
console.log('\nCurrent Consent Status:');
console.log('- Categories:', cookieconsent.extended.getConsent());
console.log('- Timestamp:', localStorage.getItem('cc_timestamp'));
console.log('- Action:', localStorage.getItem('cc_action'));
// Check available themes
console.log('\nAvailable Themes:');
console.log('- All themes:', Object.keys(cookieconsent.extended.getAvailableThemes()));
console.log('- Light themes:', Object.keys(cookieconsent.extended.getThemesByType('light')));
console.log('- Dark themes:', Object.keys(cookieconsent.extended.getThemesByType('dark')));
// Check DOM elements
console.log('\nDOM Check:');
console.log('- Popup element:', document.querySelector('.cc-popup-extended'));
console.log('- Original element:', document.querySelector('.cc-window'));
// Check localStorage
console.log('\nLocalStorage:');
Object.keys(localStorage).filter(key => key.startsWith('cc_')).forEach(key => {
console.log(`- ${key}:`, localStorage.getItem(key));
});
// Test CDN accessibility
async function testCDN() {
const files = [
'https://cdn.jsdelivr.net/gh/casjay-templates/cookieconsent@main/dist/cookieconsent.min.css',
'https://cdn.jsdelivr.net/gh/casjay-templates/cookieconsent@main/dist/cookieconsent.min.js'
];
for (const file of files) {
try {
const response = await fetch(file, { method: 'HEAD' });
console.log(`${file}: ${response.ok ? 'â
OK' : 'â Failed'}`);
} catch (error) {
console.log(`${file}: â Error - ${error.message}`);
}
}
}
testCDN();
// Test all themes quickly
function testAllThemes() {
const themes = cookieconsent.extended.getAvailableThemes();
let index = 0;
const themeKeys = Object.keys(themes);
function showNextTheme() {
if (index >= themeKeys.length) {
console.log('Theme testing complete!');
return;
}
const theme = themeKeys[index];
console.log(`Testing theme: ${theme}`);
// Clear existing
localStorage.clear();
const existing = document.querySelector('.cc-popup-extended');
if (existing) existing.remove();
// Show new theme
setTimeout(() => {
cookieconsent.extended.init({
ui: { theme: theme, position: 'center' },
content: { header: `Testing: ${theme}` }
});
setTimeout(() => {
index++;
showNextTheme();
}, 2000);
}, 100);
}
showNextTheme();
}
// Run theme test
// testAllThemes();
When reporting issues, include: