Cookie consent banner displays on first visit before non-essential cookies are set
Why it matters
ePrivacy Art. 5(3) prohibits storing information on a user's device without prior informed consent. When analytics and ad pixels fire on page load before a consent banner appears, every first visit becomes an unlawful data collection event. Regulators — the CNIL, ICO, and Austrian DSB — have each issued fines specifically for this ordering failure, not for lacking a banner entirely. The business risk is not theoretical: a single DPA complaint can trigger an investigation across an entire platform.
Severity rationale
Critical because a mis-ordered load sequence violates ePrivacy Art. 5(3) on every first page view, exposing the operator to per-visit regulatory liability before any user interaction occurs.
Remediation
Render the consent component at the top of the root layout and move all non-essential scripts into its post-consent callback. In Next.js App Router, no <Script> tag for GA4, Facebook Pixel, or Hotjar should appear in app/layout.tsx unless it is inside a consent gate or using GA4 Consent Mode v2 with analytics_storage: 'denied' as the default.
// app/layout.tsx — correct ordering
import { CookieConsent } from '@/components/CookieConsent'
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>{/* no third-party scripts here */}</head>
<body>
<CookieConsent /> {/* shows banner first; loads approved scripts after */}
{children}
</body>
</html>
)
}
The CookieConsent component reads localStorage.getItem('cookie_consent') in a useEffect; if nothing is stored, it shows the banner. Non-essential scripts are injected into the DOM only inside the loadApprovedScripts() callback that fires after the user saves a preference.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Cookie & Consent Compliance Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- eprivacy · Art. 5(3) — ePrivacy Directive — consent before setting non-essential cookies
- gdpr · Art. 7 — GDPR — conditions for valid consent
- ccpa · §1798.135 — CCPA — opt-out of sale / right to opt-in for minors
Taxons
History
- 2026-04-18·v1.0.0·Initial import from cookie-consent-compliance·automated