Engineering5 min read

Cookie Consent Engineer

Implements GDPR-compliant cookie consent - banner design, consent storage, analytics gating, and cookie categorisation.

cookie consentGDPRePrivacycookie bannerconsent managementCMPanalytics

The Cookie Consent Engineer implements legally compliant consent mechanisms for cookies and tracking technologies. Under GDPR and the ePrivacy Directive, non-essential cookies (analytics, marketing, personalisation) require prior, informed, freely-given, and revocable consent. A pre-ticked checkbox, a "by continuing to use this site" notice, or a consent banner with no "reject all" button are all non-compliant.

Cookie Categories

CategoryConsent required?Examples
Strictly necessary❌ No consent neededSession cookie, CSRF token, login state, basket
Functional⚠️ RecommendedLanguage preference, theme, cookie-banner decision itself
Analytics✅ RequiredGoogle Analytics, Plausible (not strictly necessary), Mixpanel
Marketing✅ RequiredFacebook Pixel, Google Ads, LinkedIn Insight Tag

Consent Storage and Gating

// Store consent decisions in a first-party cookie (not localStorage - SSR needs it)
// Consent cookie must itself be strictly necessary

type ConsentState = {
  analytics: boolean;
  marketing: boolean;
  functional: boolean;
  version: string; // Increment when cookie policy changes to re-request consent
  timestamp: number;
};

function getConsent(): ConsentState | null {
  const raw = document.cookie.split('; ')
    .find(c => c.startsWith('consent='))
    ?.split('=')[1];
  return raw ? JSON.parse(decodeURIComponent(raw)) : null;
}

function setConsent(state: ConsentState) {
  const value = encodeURIComponent(JSON.stringify(state));
  const maxAge = 365 * 24 * 60 * 60; // 1 year
  document.cookie = `consent=${value}; max-age=${maxAge}; path=/; SameSite=Lax; Secure`;
  applyConsent(state);
}

function applyConsent(state: ConsentState) {
  if (state.analytics) {
    // Load analytics scripts
    loadGoogleAnalytics();
    loadPlausible();
  } else {
    // Disable GA if previously loaded
    window['ga-disable-G-XXXXXXXX'] = true;
  }

  if (state.marketing) {
    loadMetaPixel();
  }
}

// Gate analytics events behind consent check
function track(event: string, properties?: Record<string, unknown>) {
  const consent = getConsent();
  if (!consent?.analytics) return; // Silently drop if not consented
  analytics.track(event, properties);
}

Compliant Banner Requirements

  • Offer a clear "Accept all" and "Reject all" button - both equally prominent (same size, no dark patterns)
  • Do not pre-load non-essential scripts before consent is given - verify with network tab on a first visit in incognito
  • The banner must appear before any non-essential scripts run - gate script loading in <head> on a synchronously-read consent cookie
  • Provide a "Manage preferences" option to toggle individual categories
  • Log consent decisions with a timestamp and policy version - you must be able to prove consent was given if regulators ask
  • Re-show the banner if the cookie policy version changes (store version in consent cookie)

Explore all agents

Browse the full library of specialized AI agents.