# consent
Cookie consent banner (GDPR): 4 categories (necessary / functional /
analytics / marketing), stored in a versioned cookie, Google Consent Mode,
content from the CookieSettings global. A settings window in three modes to pick
from (`settings`: in the bar, small window, large window with cookie details).
Default look in plain Tailwind, overridable.
## Dependency
The banner uses an icon from `lucide-react` — a regular `dependencies` entry of
the package (`^0.400.0`), installed together with IAPL; you add nothing in the
project.
## Config
The **CookieSettings** global — **Cookies** in the admin (slug `cookie-settings`, group *Privacy*) — is always
built. Tabs: *Banner*, *Settings window*, *Categories*, *Cookie list*; with the cookie scanner also
*Review and approve* and *Site check* (one entry for everything about cookies — see
[cookie-scanner.md → Admin layout](./cookie-scanner.md#admin-layout)). Public read (`read: () => true` — the banner reads it for anonymous
visitors); `update` is limited to the `admin` and `editor` roles (`adminOrEditor` —
consent texts are legal copy, not for plain `user` accounts). To change it:
`iapl({ globalOverrides: { 'cookie-settings': { access: { update } } } })`.
The only plugin option in this module is `consentLog` (below). The editor manages
the banner content (message, buttons, categories, settingsTitle) in the panel,
localized. The privacy policy link comes from system pages (`privacyPolicy`), not
from a separate field.
**Privacy policy link in the banner (since 1.7.12)** — zero code:
| What | Where from |
|---|---|
| Where it leads | Site settings → System pages → Privacy Policy |
| Link text | Cookies → `privacyLinkLabel` (per language) |
| When the text is empty | title of the policy page in that language |
`privacyPolicy` options in `getConsentTexts`: omit (automatic), `false` (no
link), `{ page }` (your own page, read with `locale: 'all'`). The `label`
parameter is **deprecated** — text hard-coded in code breaks A0 with several
languages; it works only when the panel field is empty. Remove it from projects
when you update them.
## Front — Provider + banner
Usually one line in the layout (PROGRAMISTA §2.8) — `SiteProviders` (`/rsc`) wires the provider,
banner, button and `Analytics` in the right order, with texts from `getSiteShell(locale).consent`:
```tsx
}>{children}
```
`SiteProviders` also takes `cookieMap`, `banner={false}`, `cookieButton={false}`
(or your own element) and `analytics={false | { consentMode, defer, deferTimeoutMs }}`
(`consentMode: 'basic'` = no Google request before consent — see [analytics.md](./analytics.md)).
By hand (your own layout) — the same from the individual parts:
The provider wraps the app; the banner and the button render themselves. Import from
`@intecion/ipal-kit/client`:
```tsx
// app/(frontend)/[locale]/layout.tsx
import { ConsentProvider, CookieBanner, CookieButton } from '@intecion/ipal-kit/client'
import { getConsentTexts } from '@intecion/ipal-kit'
export default async function Layout({ children, params }) {
const { locale } = await params
const payload = await getPayload({ config })
// texts from Cookie banner; the policy link is automatic:
// target = System pages → Privacy Policy, text = Cookies → privacyLinkLabel
const texts = await getConsentTexts({ payload, config: i18nConfig, locale })
return (
{children}
)
}
```
`ConsentProvider` — props: `texts` (required, `ConsentTexts` from `getConsentTexts`),
`cookieMap` (extra cookies to delete on withdrawal), `logEndpoint`
(consent log), `nonce` (CSP nonce for the banner's first-paint script), `cookieValue` (optional
server-read cookie — [First paint](#first-paint-the-banner-is-part-of-the-first-render-1170)).
`CookieBanner` does not render after a decision, `CookieButton` —
the opposite (it shows only after a decision and reopens the banner). Since 1.17.0 the banner is in
the server HTML and painted with the page, not after hydration (next section).
Built-in banner texts follow the page language: `consentFallback(locale)` → `CONSENT_FALLBACK_PL` on `pl`,
`CONSENT_FALLBACK` (English) otherwise; panel values always win. Category names for your own selects:
`CONSENT_CATEGORY_LABELS` (`{ en, pl }` per category), `consentCategoryOptions()`. ``
takes `locale` and optional `labels`; defaults: `COOKIE_TABLE_LABELS` (`@intecion/ipal-kit/rsc`).
`getConsentTexts({ payload, config, locale, privacyPolicy?, settingsSlug? })` —
`settingsSlug` is the SiteSettings slug for the automatic link (default
`'site-settings'`). Empty fields in the panel → English fallback.
| `CookieBanner` prop | Default | Description |
|---|---|---|
| `classNames` | — | slots (table below) — a given one replaces the default |
| `equalChoice` | `false` | "Reject" styled as the primary button |
| `firstPaint` | `true` | banner in the server HTML, decided before the first paint; `false` = nothing until the page has hydrated (as before 1.17.0) |
| `nonce` | provider's | CSP nonce for the first-paint script; default: the one given to `ConsentProvider` / `SiteProviders` |
| `icon` | `true` | cookie icon |
| `order` | `['settings', 'reject', 'accept']` | banner buttons |
| `settings` | `'inline'` | `'inline' \| 'modal' \| 'detailed'` |
| `controls` | `'checkbox'` | `'checkbox' \| 'switch'` |
| `settingsActions` | `['back', 'save']` | buttons under the categories (`'accept' \| 'back' \| 'reject' \| 'save'`) |
`CookieButton` props: `className` (replaces the default classes; position is then yours too),
`side` (`'left'` default or `'right'`), `avoid` (CSS selector, default `COOKIE_BUTTON_AVOID` =
`'footer, [role="contentinfo"]'`; `false` = never move). While the footer is on screen the button
moves up by its visible part (`bottomOverlap`), so it never covers footer links. Position tokens:
`--ipal-cookie-button-offset` (from the bottom, default `1rem`), `--ipal-cookie-button-inset` (from the
side, default `1rem`); z-index `--ipal-z-header`. Type `CookieButtonProps`.
## First paint: the banner is part of the first render (1.17.0)
Before 1.17.0 the banner rendered nothing until React had hydrated the page and an effect had read the
cookie. On a first visit its text appeared seconds after the page (measured on the reference site,
mobile profile with 4x CPU and slow 4G: page painted at 1.0 s, banner at 2.7 s) and on a text page it
became the **LCP element**. Now it is in the HTML and painted with the page (banner at 1.0 s, LCP 1.0 s).
An existing site gets this by updating: no edit, pages stay static.
**How (default, pages stay static / ISR / CDN-cached).** The HTML is the same for every visitor, so it
cannot know the visitor's cookie. The server renders the banner with the `hidden` attribute and, right
after it, one small inline script (`consentBannerScript`, about 0.6 kB). The script runs while the HTML is
parsed, before the browser paints:
| Visitor | Before the first paint | After hydration |
|---|---|---|
| no decision; decision under an older **Policy version**; unreadable or foreign `cookie-consent` | `hidden` removed → banner painted with the page | the same element becomes live (no re-render, no shift: the bar is `position: fixed`) |
| current decision | `display: none` on the banner → never painted | React removes it; `CookieButton` appears |
| JavaScript off, or a CSP refused the script | banner stays hidden | with JS: appears after hydration, as before 1.17.0; without JS: no banner (and no tag: every tag is loaded by JS) |
The script decides exactly as `readConsentRecord` does, reads only the consent cookie, stores nothing and
loads nothing. A click on a banner button **before** hydration is not lost: the script notes the button
(`data-ipal-pending`), and the banner carries the click out when it becomes live (the decision, the cookie
and the consent log entry are made then, by the same code as any click). There is no hydration warning:
React hydrates with "no decision" (what the server rendered) and switches to the browser's own value
before the next paint (`useSyncExternalStore`).
What does **not** change: what counts as consent, when tags load (nothing earlier), the Consent Mode
default (still pushed first), the cookie (`cookie-consent`, `{ id, state, timestamp, version }`), the
consent log, withdrawal, `CookieButton`, the settings window in all three modes, texts per language.
**CSP.** With the header-only policy (`buildSecurityHeaders`, `'unsafe-inline'` for scripts — what
static pages need anyway) nothing is to be done. With a nonce policy (`createProxy({ csp })`) the script
needs the nonce: `` passes it on (a site that already passes `nonce` for the
theme script is done); by hand: `` or ``.
Without the nonce the script is refused and the banner appears after hydration, as before.
**Your own `classNames.root`.** The banner is hidden with the `hidden` attribute. Tailwind 4 makes
`[hidden]` win over every utility; with Tailwind 3 (or other CSS) a root class that sets `display`
(`flex`, `grid`) overrides it: add `[data-ipal="banner"][hidden] { display: none !important }` to the
site's CSS.
**Turn it off:** `` — nothing in the HTML, the banner appears after
hydration (before 1.17.0).
**Option: read the cookie on the server (exact HTML, dynamic pages).** Pass the request's cookie and the
server render already knows the decision — no banner in the HTML for a visitor who decided (the
`CookieButton` instead), the banner without `hidden` and without a script for one who has not:
```tsx
import { CONSENT_COOKIE } from '@intecion/ipal-kit'
import { cookies } from 'next/headers'
const consentCookie = (await cookies()).get(CONSENT_COOKIE)?.value ?? null // null = read, none sent
… // by hand:
```
The price: `cookies()` makes every page under that layout **dynamic** — rendered per request, no static
or ISR copy, and a CDN must not share one HTML between visitors. Choose it only for a site that is
dynamic anyway (a nonce CSP, signed-in pages). `undefined` (the prop left out) = static mode.
| | Static (default) | Server read (`consentCookie`) |
|---|---|---|
| Public pages | static / ISR, one HTML for all, CDN-cacheable | dynamic, per request |
| Banner in the HTML of a visitor who decided | yes, hidden before paint | no |
| Inline script | one (needs the nonce under a nonce CSP) | none |
| Banner at first paint for a new visitor | yes | yes |
**Your own banner** (AGENT.md §7 says: don't; when you must): `consentBannerScript({ version })` from
`@intecion/ipal-kit` (options: `ConsentBannerScriptOptions` — `version`, `cookieName`) is the same script — put `hidden` and `suppressHydrationWarning` on your banner's root and
the script in a `