Proper consent management for cookies and tracking technologies is a common compliance requirement across multiple privacy frameworks. This guide covers technical implementation considerations.
Important Disclaimer
Consent requirements vary significantly by jurisdiction and the specific tracking technology used — consult qualified legal counsel for your specific requirements; this article covers general technical implementation patterns.
Understanding Different Cookie/Tracking Categories
| Category | Typical Consent Treatment |
|---|---|
| Strictly necessary (session, security) | Generally don't require consent |
| Analytics | Often require consent, varies by jurisdiction and specific implementation |
| Marketing/advertising | Generally require explicit opt-in consent |
Implementing a Consent Banner
<div id="consent-banner">
<p>We use cookies for analytics and marketing.</p>
<button onclick="acceptAll()">Accept All</button>
<button onclick="rejectNonEssential()">Reject Non-Essential</button>
<button onclick="customizeConsent()">Customize</button>
</div>
Provide genuine, meaningful choice — not just an "accept" button with no equally accessible reject option, which several regulators have specifically flagged as inadequate consent design (sometimes called "dark patterns").
Delaying Non-Essential Scripts Until Consent
function loadAnalytics() {
const script = document.createElement('script');
script.src = 'https://analytics-provider.com/script.js';
document.head.appendChild(script);
}
if (hasConsent('analytics')) {
loadAnalytics();
}
Genuinely delay loading non-essential tracking scripts until consent is actually granted — loading the script immediately and only "hiding" its effects doesn't satisfy the actual requirement, since the tracking technology itself shouldn't activate before consent.
Storing and Respecting Consent State
localStorage.setItem('consent_analytics', 'granted');
localStorage.setItem('consent_marketing', 'denied');
Persist the user's consent choice, and consistently respect it across their subsequent visits/pages — a consent banner that doesn't actually persist/respect the choice provides no genuine compliance value.
Providing an Easy Way to Change Consent Later
<a href="#" onclick="openConsentPreferences()">Cookie Preferences</a>
Users should be able to revisit and change their consent choice easily, not just at initial page load — a persistent, accessible way to manage preferences is generally expected, not just a one-time initial prompt.
Handling Consent for Server-Side Tracking
Beyond client-side scripts, consider whether any server-side tracking/logging also needs to respect consent choices — consent management shouldn't only cover client-side JavaScript-based tracking if you have server-side tracking mechanisms too.
Using a Consent Management Platform (CMP)
For more complex consent needs (multiple jurisdictions, many third-party scripts, IAB framework compliance for advertising), a dedicated Consent Management Platform can handle much of this complexity — worth considering versus building fully custom consent handling for genuinely complex requirements.
Documenting Consent Records
Maintain records of when/how consent was obtained — useful both for your own compliance evidence and to respond to any dispute about whether valid consent existed for specific processing.
Testing That Consent Is Genuinely Respected
Verify through actual testing (not just code review) that rejecting consent genuinely prevents the associated tracking from occurring — a consent implementation that looks correct in code but doesn't actually block tracking in practice provides false compliance confidence.
Continue Reading
- GDPR Considerations for VPS Hosting and Data Residency
- CCPA Compliance Basics for VPS-Hosted Applications
- How to Add Analytics to a Static Site Without Hurting Performance
Browse more articles in Compliance & Industry-Specific Hosting.