ConsentPixel – Privacy · Verified

Next.js · Gatsby · Astro · SvelteKit ⚡ One Script Tag

Cookie Consent for the
JAMstack — No
Provider Wiring.

On a Next.js, Gatsby, or Astro site, third-party scripts get injected through next/script, gatsby-ssr, Astro layouts, or a tag manager — and they fire during hydration before any React-based consent provider has mounted. ConsentPixel — Privacy · Verified runs as one framework-agnostic script in the document head, blocking tracking before your framework hydrates. No provider to wire up, no hydration race, no SSR/CSR mismatch.

Framework-agnostic — any JS framework
GDPR · CCPA · CIPA · 19 US state laws
Google Consent Mode v2 built in
No hydration race conditions
0 deps
No npm package, no provider, no context wiring
$5,000
Per-visitor CIPA exposure from session-replay on California traffic
€20M
Max GDPR fine — or 4% of global annual revenue
Pre-hydration
Blocks scripts before React/Astro hydrates

Why Consent Is Hard on Next.js, Gatsby, and Astro

JAMstack frameworks render fast and inject scripts in several ways: next/script with its strategy options, gatsby-ssr.js and plugins like gatsby-plugin-google-gtag, Astro layout scripts, or a Google Tag Manager container in the document head. The hard part is timing. Tracking scripts often execute during or immediately after hydration — before a React or Astro-island consent provider has mounted and read the visitor's choice.

The result is a race condition: your consent UI renders a moment after the analytics and pixel scripts have already fired. A consent provider written as a React component cannot reliably gate scripts that the framework injects at or before hydration.

⚠ The Hydration Race Why a React-based consent provider fires too late

A consent provider implemented as a React context lives inside the component tree — it only takes effect after the framework hydrates. But next/script with beforeInteractive, GTM in the head, and many gatsby plugins inject and run scripts before or during hydration.

So the very scripts you most need to gate — GA4, Meta Pixel, GTM — are the ones a component-tree provider is structurally unable to hold. ConsentPixel runs as a plain head script that initialises before the framework boots, closing the race.

✗ next/script beforeInteractive fires early

Scripts with the beforeInteractive strategy run before hydration — a React provider has not mounted to gate them.

✗ GTM in head fires on load

A GTM container in your _document or layout head fires its tags before any provider component exists.

✗ gatsby-plugin-* injects at build

Analytics plugins inject tags into the SSR output that fire on first paint, ahead of client-side consent logic.

✗ SSR/CSR consent mismatch

Reading consent state server-side vs client-side without care produces hydration mismatches and flashes of the wrong UI.

You can solve this in-house — but it means carefully ordering a head script, managing consent state outside the component tree, wiring Google Consent Mode v2 by hand, and maintaining it through every framework upgrade. ConsentPixel does all of that as one script tag and a dashboard.

Trackers Commonly Running on JAMstack Sites

Next.js, Gatsby, and Astro sites are typically product, SaaS, and developer-marketing sites carrying analytics, product-analytics, and advertising stacks. These are the most common integrations and the exposure each creates.

📊
Google Analytics 4
GDPR · CCPA · GCM v2
The most common tracker on JAMstack sites. Sets _ga cookies and transmits to Google on page load. Needs Google Consent Mode v2 default-deny set before GA4 initialises.
🔖
Google Tag Manager
GDPR · GCM v2 Required
Every tag inside a GTM container fires on load — conversion pixels, remarketing, analytics. The GCM v2 default state must be set before GTM loads, not after.
📘
Meta Pixel
GDPR · CCPA · CIPA
Loads from Facebook's CDN and fires on load, sharing browsing behaviour and conversions with Meta's ad network regardless of any banner shown.
🔥
Hotjar / Microsoft Clarity
GDPR · CIPA
PostHog session replay, Hotjar, and Clarity are common on product-led JAMstack sites and run from page load — $5,000/visitor CIPA exposure for California visitors with no consent gate.
🎯
LinkedIn / TikTok Pixels
GDPR · CCPA
External pixels that set identifiers and fire on load. Common on B2B, agency, and creator sites and frequently missed in consent configurations.
📹
YouTube / Vimeo Embeds
GDPR
Embedded players set third-party cookies and load tracking when the page renders — not when the visitor presses play. Must be consent-gated for GDPR.
💬
Live Chat (Intercom, Drift, Crisp)
GDPR · CCPA
Chat widgets set persistent identifiers and load before consent. Common on SaaS, service, and agency sites.
🧪
Product Analytics (PostHog, Amplitude, Mixpanel)
GDPR · CCPA
Common on SaaS JAMstack sites. SDKs initialise on load and capture events and identifiers before consent unless explicitly gated outside the component tree.

React Consent Provider vs. ConsentPixel

A component-tree consent provider and ConsentPixel differ in where they run. The provider runs after hydration; ConsentPixel runs before the framework boots, which is where script blocking has to happen.

CapabilityReact/Astro Consent ProviderConsentPixel
Blocks scripts before hydration✗ Runs after hydration✓ Head script, pre-hydration
Blocks next/script beforeInteractive✗ Too late✓ Yes
Blocks GTM in document head✗ No✓ Yes
Google Consent Mode v2 (all 4 params)⚠ Manual wiring✓ Built in
Global Privacy Control (GPC) detection⚠ Manual✓ Auto-detected
CIPA session-replay blocking⚠ DIY✓ Yes
US state law opt-out (19 states)✗ DIY✓ All plans
Timestamped consent audit log✗ DIY / none✓ Full log, exportable
No framework-upgrade maintenance✗ Breaks with refactors✓ Independent of build
🚫
If your consent logic lives in the component tree, your tracking fires before it. On JAMstack sites the compliance failure is almost always a timing failure: GA4, Meta Pixel, and GTM execute during hydration while the consent provider mounts a beat later. Blocking has to happen in the head, before the framework boots — not inside React.

See what fires during hydration on your JAMstack site

ConsentPixel scans your deployed site in a fresh session and shows every script that fires before consent — including tags injected by next/script, gatsby plugins, and Astro layouts.

Scan My Site →

How to Install ConsentPixel on Next.js, Gatsby, or Astro

ConsentPixel installs as a single script in the document head — framework-agnostic, no npm package, no provider. The key is placing it as the first script so it initialises before your framework hydrates and before any tracking script runs.

1

Create your ConsentPixel account and scan your site

Sign up at consentpixel.com, add your deployed domain, and run the auto-scanner. ConsentPixel maps every tracker across your routes — including tags injected by next/script, gatsby plugins, and Astro layouts. Copy your unique pixel snippet.

2

Next.js — add to the document head (App or Pages Router)

App Router: add ConsentPixel in app/layout.tsx using next/script with the beforeInteractive strategy, or as a raw tag in the head. Pages Router: add it in pages/_document.tsx inside <Head> as the first script.

app/layout.tsx (App Router)
import Script from 'next/script'

export default function RootLayout({ children }) {
  return (
    <html>
      <head>
        <Script
          src="https://pixel.consentpixel.com/YOUR-SITE-ID.js"
          strategy="beforeInteractive"
        />
      </head>
      <body>{children}</body>
    </html>
  )
}
3

Gatsby — add via gatsby-ssr.js onRenderBody

In gatsby-ssr.js, use setHeadComponents to inject ConsentPixel as the first head script, before gatsby-plugin-google-gtag or any analytics plugin output.

gatsby-ssr.js
export const onRenderBody = ({ setHeadComponents }) => {
  setHeadComponents([
    <script
      key="consentpixel"
      src="https://pixel.consentpixel.com/YOUR-SITE-ID.js"
      async
    />,
  ])
}
4

Astro — add to your base layout head

In your base layout (e.g. src/layouts/Base.astro), place the ConsentPixel script as the first element in <head>, before any analytics islands or GTM.

src/layouts/Base.astro
<head>
  <!-- ConsentPixel — first in head -->
  <script src="https://pixel.consentpixel.com/YOUR-SITE-ID.js" async></script>
  <!-- analytics / GTM below -->
</head>
5

Register your scripts and configure GCM v2

In the ConsentPixel dashboard, register each tool by category: Analytics (GA4), Product Analytics (PostHog, Amplitude), Marketing (Meta, LinkedIn), Session Recording (Hotjar, Clarity, PostHog replay). ConsentPixel holds each category until consent.

Enable Google Consent Mode v2 — ConsentPixel sets all four parameters before any Google tag loads, so you don't hand-wire gtag('consent','default',…) yourself.

💡
Verify it loads before hydration. Deploy, then open the site in incognito and check the DevTools Network/Performance tab — ConsentPixel's request must resolve before your framework's main bundle executes and before googletagmanager.com. With next/script, use the beforeInteractive strategy specifically; the default afterInteractive strategy can run after tracking scripts you want to gate.

What ConsentPixel Does for Your JAMstack Site

🛡️

Blocks before the framework boots

Runs as a head script that initialises before React or Astro hydrates — so it gates the next/script, GTM, and plugin-injected tags a component-tree provider cannot reach in time.

📦

Zero dependencies, no provider

No npm package, no context provider, no hooks to wire. One script tag in your layout or _document head. Nothing to refactor when you upgrade the framework.

📡

Google Consent Mode v2 — done for you

Sets all four GCM v2 parameters before any Google tag loads, so you skip the brittle hand-written gtag consent default wiring.

🌐

GPC browser signal detection

Honours the Global Privacy Control signal for California, Colorado, Virginia, and Connecticut visitors automatically — no extra client code.

🔥

CIPA session-replay protection

Blocks Hotjar, Clarity, Lucky Orange, and PostHog session replay before consent — removing the $5,000/visitor CIPA exposure for California traffic.

No hydration mismatch

Because consent state is managed outside the React/Astro tree, you avoid the SSR/CSR mismatches and UI flashes that DIY in-tree consent providers cause.

JAMstack Privacy Compliance Checklist (2026)

📋 Next.js / Gatsby / Astro Compliance Checklist — 2026 11 items
Audit every external script loading on your JAMstack siteCheck GTM tags, embedded code, app/plugin scripts, and any integration that calls a third-party domain
Verify external JavaScript is blocked before consent — not just first-party cookiesTest in your browser's DevTools Network tab in a private/incognito window before accepting anything
Place ConsentPixel as the first head script — before next/script, GTM, or plugin outputOn Next.js use the beforeInteractive strategy; on Gatsby use gatsby-ssr setHeadComponents; on Astro put it first in the base layout head
Configure Google Consent Mode v2 with all four parametersRequired for EEA/UK Google Ads — the default-deny state must fire before GTM or GA4 loads
Block session-replay tools before consent$5,000/visitor CIPA exposure — Hotjar, Clarity, Lucky Orange must never run before explicit consent
Implement GPC browser signal recognitionMandatory in California, Colorado, Virginia, and Connecticut — most native banners do not provide this
Add a "Do Not Sell or Share" opt-out for US visitorsRequired across California and all 19 active US state privacy laws in 2026
Consent-gate all embedded third-party content — maps, video, social widgetsYouTube, Google Maps, and X/Twitter embeds set third-party cookies and must be gated for GDPR
Update your privacy policy to disclose all external integrationsName GA4, GTM, Meta, LinkedIn, Hotjar, and any automation platform as third-party data recipients
Maintain a full timestamped consent audit logRequired under GDPR Article 5(2) accountability — keep an exportable record of every consent choice
Re-test after any JAMstack template, theme, or app changeUpdates can change script load order — confirm ConsentPixel still loads first after any change

Frequently Asked Questions

A React-based consent provider lives in the component tree and only takes effect after the framework hydrates. But next/script with beforeInteractive, a GTM container in the head, and many Gatsby analytics plugins inject and run scripts before or during hydration. So the provider mounts a beat too late to gate the exact scripts that matter. ConsentPixel runs as a head script before the framework boots, which is where script blocking has to happen.
It is one framework-agnostic script in the document head. On Next.js, add it via next/script with the beforeInteractive strategy in app/layout.tsx (App Router) or pages/_document.tsx (Pages Router). On Gatsby, inject it via setHeadComponents in gatsby-ssr.js. On Astro, place it first in your base layout head. No npm package or provider is required.
No — the opposite. ConsentPixel manages consent state outside the React/Astro component tree, so it does not participate in hydration and cannot cause an SSR/CSR mismatch. DIY in-tree consent providers are a common source of hydration warnings and UI flashes; moving consent out of the tree avoids that class of bug entirely.
Yes. Register PostHog, Amplitude, or Mixpanel in the ConsentPixel dashboard under the appropriate category and ConsentPixel holds the SDK until the visitor consents. This includes PostHog's session replay, which carries the same CIPA exposure as Hotjar or Clarity for California visitors.
If your site runs session-replay or replay-capable product analytics and receives California visitors, CIPA applies. These tools record from page load unless gated. California's wiretapping statute carries statutory damages of up to $5,000 per affected visitor with no proof of harm required. ConsentPixel blocks all session-replay scripts before consent.
Yes. Because it is a single head script referencing a file served from Cloudflare's edge — not a dependency in your component tree — framework version bumps, refactors, and router migrations do not affect it. The only thing to verify after a major change is that the script still sits first in the head.
JAMstack Compliance — Block Before Hydration

One head script.
No provider, no race.

ConsentPixel — Privacy · Verified blocks the GA4, GTM, Meta Pixel, and session-replay scripts your Next.js, Gatsby, or Astro site injects — before the framework hydrates. All four GCM v2 parameters and GPC handled for you. Zero dependencies, no hydration mismatch.

Scroll to Top