- GPC (gpc.ts): read in the browser before the first paint (consentBannerScript) and in the consent store; pages stay static. 'honour' (default): no banner, analytics and marketing off, no request to Google or a pixel; an explicit choice on the site wins; a grant made without the signal gives way when it appears. 'ask' and false as opt-outs. - equalChoice defaults to true; a development warning when the banner has no 'reject'. - Withdrawal: Meta / TikTok / Clarity told at once, listed localStorage / sessionStorage keys removed. - Clarity gets consentv2 when it loads; ads_data_redaction with the Consent Mode default. - consentLog on by default (consentLog: false turns it off); SiteProviders posts to it by itself; a missing SQL table answers 503 with one log line. - Default banner text: one sentence on changing the choice and browser settings; the GPC line (PL / EN). - Doctor: consent-log-migration, consent-banner rules. - Stats: Sec-GPC over a choice made without it keeps the visitor id out. Co-Authored-By: Claude Opus 5.5 <[email protected]>
148 lines
6.2 KiB
TypeScript
148 lines
6.2 KiB
TypeScript
import type { ReactNode } from 'react'
|
|
|
|
import type { AnalyticsProps } from '../analytics/Analytics.js'
|
|
import type { GpcMode } from '../consent/gpc.js'
|
|
import type { ConsentCookieMap } from '../consent/useConsent.js'
|
|
import type { LightboxProviderProps } from '../lightbox/LightboxProvider.js'
|
|
import type { PageStatsProps } from '../stats/PageStats.js'
|
|
import type { SiteShell } from './createContentHelpers.js'
|
|
|
|
import { Analytics } from '../analytics/Analytics.js'
|
|
import { ConsentProvider } from '../consent/ConsentContext.js'
|
|
import { CookieBanner } from '../consent/CookieBanner.js'
|
|
import { CookieButton } from '../consent/CookieButton.js'
|
|
import { LightboxProvider } from '../lightbox/LightboxProvider.js'
|
|
import { JsonLdGraph } from '../seo/JsonLdGraph.js'
|
|
import { PageStats } from '../stats/PageStats.js'
|
|
import { MediaPreconnect } from '../storage/MediaPreconnect.js'
|
|
import { ThemeScript } from '../theme/ThemeScript.js'
|
|
import { TurnstileProvider } from '../turnstile/TurnstileProvider.js'
|
|
|
|
export type SiteProvidersProps = {
|
|
/** `defer` etc. for <Analytics>; `false` = no analytics tags at all. */
|
|
analytics?: false | Omit<AnalyticsProps, keyof SiteShell['analytics']>
|
|
/** The cookie banner. Default `<CookieBanner />`; pass your own configured one (`settings`, classNames) or `false`. */
|
|
banner?: false | ReactNode
|
|
children: ReactNode
|
|
/**
|
|
* Optional server read of the consent cookie: `(await cookies()).get(CONSENT_COOKIE)?.value ?? null`. The HTML
|
|
* then has no banner for a visitor who already decided, and the page becomes dynamic (no static / ISR copy).
|
|
* Leave out (default) to keep pages static: the banner decides before the first paint with an inline script.
|
|
*/
|
|
consentCookie?: null | string
|
|
/** The "cookie settings" button. Default `<CookieButton />`; your own or `false`. */
|
|
cookieButton?: false | ReactNode
|
|
/** Extra cookies per category to delete when consent is withdrawn. */
|
|
cookieMap?: ConsentCookieMap
|
|
/**
|
|
* Global Privacy Control: `'honour'` (default), `'ask'` or `false`. See ConsentProvider `gpc` and
|
|
* docs/consent.md → Global Privacy Control.
|
|
*/
|
|
gpc?: GpcMode
|
|
/** More site-wide JSON-LD nodes next to shell.jsonLd (e.g. buildNavigationJsonLd). */
|
|
jsonLd?: (null | Record<string, unknown> | undefined)[]
|
|
/**
|
|
* One shared image lightbox for the site: mounts <LightboxProvider> around the
|
|
* page, so every <LightboxTrigger> and `RenderRichText lightbox` uses it.
|
|
* `true` (texts from shell.lightboxTexts = Notifications → Lightbox) or
|
|
* `{ texts, classNames, icons, loop, unstyled }`. Default off. For renderImage / renderDialog (functions) mount the provider
|
|
* yourself in a client component.
|
|
*/
|
|
lightbox?: boolean | Omit<LightboxProviderProps, 'children' | 'renderDialog' | 'renderImage'>
|
|
/**
|
|
* Consent log endpoint. Default: the site shell's (`shell.consentLogEndpoint`, '/api/ipal/consent' whenever the
|
|
* plugin's consent log is on — the default since 1.17.0). `false` = decisions are not posted.
|
|
*/
|
|
logEndpoint?: false | string
|
|
/** Days a choice is kept before the banner asks again. Default 180. */
|
|
maxAgeDays?: number
|
|
/**
|
|
* CSP nonce for a nonce-based policy (createProxy `csp`): read it in the layout
|
|
* with `(await headers()).get('x-nonce')`. Goes on the theme script, the cookie
|
|
* banner's first-paint script and the analytics tags the plugin injects (GTM
|
|
* passes it on to its own tags).
|
|
*/
|
|
nonce?: null | string
|
|
/** <link rel=preconnect> to the media origin (R2_PUBLIC_URL). Default true. */
|
|
preconnect?: boolean
|
|
/** getSiteShell(locale) from lib/content. */
|
|
shell: SiteShell
|
|
/**
|
|
* Built-in statistics (iapl stats: true): mounts <PageStats>. `true` or
|
|
* `{ locale, endpoint }`. Default off.
|
|
*/
|
|
stats?: boolean | PageStatsProps
|
|
/**
|
|
* Light / dark theme from Site Settings → Theme: renders <ThemeScript> first,
|
|
* so the theme is on <html> before the first paint. Put <SiteProviders> first in
|
|
* <body> and add `suppressHydrationWarning` to <html>. Default false.
|
|
*/
|
|
theme?: boolean
|
|
}
|
|
|
|
/**
|
|
* The wiring every [locale] layout repeats — consent, Turnstile, analytics,
|
|
* site JSON-LD, media preconnect — in the right order (Analytics inside the
|
|
* consent provider, forms inside Turnstile). Renders no markup of its own:
|
|
* <html>, <body>, header, footer and <main> stay in the layout.
|
|
*
|
|
* const shell = await getSiteShell(locale)
|
|
* <body>
|
|
* <SiteProviders shell={shell} banner={<CookieBanner settings="detailed" />}>
|
|
* <Header … /><main>{children}</main><Footer … />
|
|
* </SiteProviders>
|
|
* </body>
|
|
*
|
|
* Every part is replaceable or switchable off; for a fully custom tree use the
|
|
* providers themselves (consent.md, turnstile.md) — the shell data still fits.
|
|
*/
|
|
export function SiteProviders({
|
|
analytics,
|
|
banner,
|
|
children,
|
|
consentCookie,
|
|
cookieButton,
|
|
cookieMap,
|
|
gpc,
|
|
jsonLd = [],
|
|
lightbox = false,
|
|
logEndpoint,
|
|
maxAgeDays,
|
|
nonce,
|
|
preconnect = true,
|
|
shell,
|
|
stats = false,
|
|
theme = false,
|
|
}: SiteProvidersProps) {
|
|
return (
|
|
<>
|
|
{theme ? <ThemeScript {...shell.theme} nonce={nonce ?? undefined} /> : null}
|
|
{preconnect ? <MediaPreconnect /> : null}
|
|
<JsonLdGraph schemas={[...shell.jsonLd, ...jsonLd]} />
|
|
<ConsentProvider
|
|
cookieMap={cookieMap}
|
|
cookieValue={consentCookie}
|
|
gpc={gpc}
|
|
logEndpoint={logEndpoint === false ? undefined : (logEndpoint ?? shell.consentLogEndpoint ?? undefined)}
|
|
maxAgeDays={maxAgeDays}
|
|
nonce={nonce}
|
|
texts={shell.consent}
|
|
>
|
|
<TurnstileProvider siteKey={shell.turnstileSiteKey}>
|
|
{lightbox ? (
|
|
<LightboxProvider texts={shell.lightboxTexts} {...(lightbox === true ? {} : lightbox)}>
|
|
{children}
|
|
</LightboxProvider>
|
|
) : (
|
|
children
|
|
)}
|
|
</TurnstileProvider>
|
|
{banner === undefined ? <CookieBanner /> : banner || null}
|
|
{cookieButton === undefined ? <CookieButton /> : cookieButton || null}
|
|
{analytics === false ? null : <Analytics {...shell.analytics} nonce={nonce ?? undefined} {...analytics} />}
|
|
{stats ? <PageStats {...(stats === true ? {} : stats)} /> : null}
|
|
</ConsentProvider>
|
|
</>
|
|
)
|
|
}
|