Non-essential scripts only load after consent is granted for their category
Why it matters
ePrivacy Art. 5(3) prohibits accessing or storing information on a device without prior consent. GDPR Art. 6(1)(a) requires a lawful basis — and for non-essential tracking, consent is the only available basis. When GA4, Facebook Pixel, or Segment loads via a static <script> tag or an unconditional strategy='afterInteractive' Next.js <Script>, it fires before any user interaction, collecting device identifiers and behavioral data without a lawful basis. CCPA §1798.135 imposes the parallel obligation for California residents' right to opt out of sale/sharing of personal information, which ad pixels facilitate. This is the most commonly litigated technical failure in DPA enforcement actions.
Severity rationale
Critical because a static or unconditionally loaded analytics script fires on every page view, collecting personal data without any lawful basis under GDPR Art. 6(1)(a) and ePrivacy Art. 5(3) — the core violation regulators fine for.
Remediation
Either use GA4 Consent Mode v2 with analytics_storage: 'denied' as the default (the only pattern that allows GA4 in the static layout), or move all other non-essential scripts into a loadApprovedScripts() function called only after the user saves consent.
// GA4 Consent Mode v2 — set the denied default BEFORE the gtag script tag
<Script id="consent-defaults" strategy="beforeInteractive">{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('consent', 'default', {
analytics_storage: 'denied',
ad_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied',
});
`}</Script>
<Script src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXX" strategy="afterInteractive" />
For scripts without Consent Mode support (Segment, Hotjar, Facebook Pixel), inject them into the DOM only inside the consent callback in src/lib/consent-scripts.ts. Never place them as static <Script> tags with strategy='afterInteractive' — that strategy is not consent-aware.
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 — no non-essential cookie before consent
- gdpr · Art. 6(1)(a) — GDPR — lawful basis: processing only after consent is granted
- ccpa · §1798.135 — CCPA — data collection must respect opt-out signals
- cwe · CWE-284 — Improper Access Control — scripts bypass consent gate
Taxons
History
- 2026-04-18·v1.0.0·Initial import from cookie-consent-compliance·automated