Adds a Consent Settings global, a cookie banner with a settings dialog, and script blocking until the visitor agrees. It supports Off, Notice and Opt-in modes, plus Google Consent Mode v2. It also adds a Personal data consent field type to the form builder, validated on the server. Requires Payload 4 and Next.js, and must be listed after the form builder plugin.
Cookie banner and consent control for Payload CMS 4 and Next.js: Consent Settings global, banner, Google Consent Mode v2, personal data consent in forms.
Installation
npm i @serge-pro-dev/payload-plugin-consent0
Stars
0
Forks
0
Open Issues
Yesterday
Last Updated
441
Weekly Downloads
v0.1.0-beta.2
npm Version
123.6 KB
Unpacked Size
1
Dependencies
Trends appear once the first and last snapshots are 7 days apart. Collecting since Nov 29 — 7 daily snapshots so far.
Shared by 6 plugins in serge-pro-dev/payload-plugins.
Trends appear after 7 days of data. Collecting since Dec 4 — 2 daily snapshots so far.
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1479182369-consent)<a href="https://payloaddirectory.dev/plugins/1479182369-consent"><img src="https://payloaddirectory.dev/badge/1479182369-consent.svg" alt="Payload Directory"></a>README
Cookie banner and consent control for a Next.js + Payload 4 site. It adds the Consent Settings global (menu group Analytics), a banner with a settings dialog, and blocks analytics scripts until the visitor agrees. Built for RU/BY sites first (Notice mode); Opt-in mode and Google Consent Mode v2 cover EU/US.
The default texts and the modes are mechanics, not legal advice. Have a lawyer review the texts and your policy.

pnpm add @serge-pro-dev/payload-plugin-consent
// payload.config.ts: after formBuilderPlugin
import { consentPlugin } from '@serge-pro-dev/payload-plugin-consent'
plugins: [formBuilderPlugin(/* ... */), consentPlugin({ defaultLanguage: 'en' })]
// src/app/(frontend)/layout.tsx
import config from '@payload-config'
import { Consent, ConsentHead } from '@serge-pro-dev/payload-plugin-consent/rsc'
<head>
{/* Google Consent Mode defaults, before any Google tag */}
<ConsentHead config={config} />
</head>
<body>
...
{/* banner and runtime */}
<Consent config={config} />
</body>
Then run pnpm payload generate:importmap and pnpm payload generate:types, open
Analytics → Consent Settings, choose a mode and save. Default is Off:
nothing changes until you switch it on.
| Mode | Before a choice | Banner |
|---|---|---|
| Off | everything runs | none |
| Notice | everything runs, Reject stops it | shown until the visitor chooses |
| Opt-in | optional scripts do not run | shown until the visitor chooses |
Categories: necessary (always on), analytics, marketing. Raise Consent version to ask everybody again.
{link} marker (replaced by the policy link), link text and the accept
button. Needs the policy URL for the link; without it the link text is shown
as plain text.<ConsentSettingsLink> in the footer. If both are hidden only Accept is
left, which is not suitable for Opt-in on EU/US sites.Scripts of the analytics plugin
(Google tag, custom JavaScript, UTM writer) have a category and are rendered
inert (type="text/plain" data-consent-category="analytics") while the mode is
Notice or Opt-in; the browser runtime starts them once their category is
allowed. Any script of your own can use the same markup:
<script type="text/plain" data-consent-category="marketing" data-src="https://example.com/pixel.js"></script>
<noscript> pixels cannot wait for consent, so they should not be output
while the mode is Notice or Opt-in.utm_first_touch and
utm_last_touch cookies are removed. Cookies of third-party services cannot
be removed from the page; scripts that already ran keep running until reload.window.__consent.get() // { analytics, marketing, decided }
window.__consent.set({ analytics: true })
window.__consent.acceptAll() / rejectAll() / open()
window.__consent.subscribe((state) => ...)
// events: 'consent:change' (detail = state), 'consent:open'
// dataLayer: { event: 'consent_update', consent_analytics, consent_marketing }
<ConsentSettingsLink>Cookie settings</ConsentSettingsLink> (client component,
@serge-pro-dev/payload-plugin-consent/client) reopens the dialog from the footer.
The plugin adds a field type to the form builder: Personal data consent (a required checkbox with a link). A form has it only if an editor adds it, so it is off by default.
import { PersonalDataConsentField } from '@serge-pro-dev/payload-plugin-consent/client'
export const fields = { /* ... */ personalDataConsent: PersonalDataConsentField }
formBuilderPlugin.consentPlugin({ personalData: { text, linkLabel, linkUrl, errorMessage } }).The visitor cannot send the form without ticking the box. The server checks it again and refuses a submission without consent (message from the field). Every accepted submission gets a read-only Personal data consent record, built on the server from the form itself: consent given, server time, a short hash of the wording (text + link) and a copy of the text and link. Whatever the browser sends for that record is discarded. No IP address is stored.
The plugin provides the mechanics, not the legal documents: the consent text and the page it links to must be prepared for your jurisdiction.
consent = encodeURIComponent(JSON) of
{ v: 1, analytics, marketing, ts, version }, SameSite=Lax, lifetime from the
settings. Readers must treat it as untrusted input: use readConsentFromHeader()
from @serge-pro-dev/payload-plugins-shared/consent.
Plain CSS, imported by the banner itself; colors come from --cc-* variables
that fall back to shadcn-style tokens (--popover, --foreground, --primary,
...), so the banner follows the site theme. Tokens must be complete colors
(oklch(), hsl(), hex). Override any --cc-* variable to restyle it.
The visitor's choice is read in the browser after hydration, so pages stay statically rendered; the banner appears just after load.
Labels and descriptions in the admin are available in English and Russian.
Enable both languages in the project: i18n: { supportedLanguages: { en, ru } }
(from @payloadcms/translations/languages). The texts shown to visitors are
separate (the texts of the global).
New global consent and the personal_data_consent_* columns of form
submissions. Development: schema push. Production: pnpm payload migrate:create
and migrate.
A site-wide consent log, localized banner texts, external CMPs (Klaro, vanilla-cookieconsent) through the browser API.
MIT
plugin consent
Cookie consent managed in the Payload admin: categories, trackers, banner, script gating and consent records.
7044/wk10v3
analytics
Analytics Settings global for Google tags, custom scripts, pixels and UTM cookies on Next.js sites, with consent…
77627/wk0v4
payload plugin age gate
Birth month and year age check at sign-up that stores only a coarse minor-until date per country
66128/wk0v3
payload plugin gtm
Google Tag Manager and GA4 for Payload with automatic dataLayer event discovery and an editable event registry
6031/wk0v3
payload consent
Cookie banner, script gating and cookie declarations managed from collections in the Payload admin
57146/wk3v3
analytics
Event registry and consent-gated routing of analytics events to GTM, GA4 and HubSpot from the Payload admin
4810/wk0v3