Complete GDPR compliance in just 30 lines of code!
This demo shows how easy it is to respect user privacy.
// Check if user has given consent
let hasTracking = localStorage.getItem('tracking') === 'yes';
// Update UI based on consent
function updateUI() {
const btn = document.getElementById('privacyBtn');
const status = document.getElementById('status');
if (hasTracking) {
btn.textContent = '📊 Tracking ON';
btn.className = 'privacy-btn enabled';
status.innerHTML = '📊 Tracking enabled';
// Enable your analytics here
console.log('Analytics would be enabled here');
} else {
btn.textContent = '🛡️ Enable tracking?';
btn.className = 'privacy-btn';
status.innerHTML = '🛡️ Privacy protected!';
// No tracking - site works perfectly!
console.log('Privacy mode - no tracking');
}
}
// Toggle tracking on button click
function toggleTracking() {
if (!hasTracking) {
if (confirm('Enable tracking to help us improve?')) {
localStorage.setItem('tracking', 'yes');
hasTracking = true;
alert('Thank you! You can disable anytime.');
} else {
alert('Great choice! Your privacy is protected! 🎉');
}
} else {
if (confirm('Disable tracking?')) {
localStorage.removeItem('tracking');
hasTracking = false;
alert('Privacy mode enabled! 🛡️');
}
}
updateUI();
}
// Initialize on page load
updateUI();
Click the button below to see the consent flow in action:
GDPR doesn't require complex consent management systems. It requires:
That's it! This simple implementation covers all the basics.
The fancy version in index.html just adds nice UI and features,
but the core principle remains this simple.
🎉 Privacy-first is easy!
Copy this code and make the web more privacy-friendly.