GDPR Cookie 同意:拒绝与接受同等显著的横幅、分类、同意记录、ConsentGate 和 Consent Mode v2
代码9 个文件上下文约 743 个 token扫描通过
安装
$
genpm add @core/consent你将获得
- 源代码位于 src/lib/consent/,共 9 个文件。 (22.3 kB)
- AI 规则位于 src/lib/consent/AGENTS.md,另附 IDE 规则文件。
- 添加到 .env.example 的环境变量:CONSENT_POLICY_VERSION, SITE_URL, CONSENT_COOKIE_DOMAIN。
- 自动为你解析 @core/db。
README
此包没有 README。
约 743 个 token→ src/lib/consent/AGENTS.md→ .cursor/rules/genpm-core-consent.mdc
这正是你的 AI 在 src/lib/consent 中工作时读取的内容。不会向其上下文添加其他任何内容。
@core/consent — rules for AI agents
Purpose
Cookie consent that meets GDPR/ePrivacy: categories (necessary always on; analytics, marketing, preferences off by
default), a banner where "Reject all" is as prominent as "Accept all", a preferences center, proof of each decision
(consent_records: choices, policy version, date; no IP), server checks (hasConsent), a client ConsentGate and
Google Consent Mode v2 values. Changing CONSENT_POLICY_VERSION asks everyone again.
Map
index.ts— server API:getConsent,hasConsent,recordConsent,consentModeDefaultsScript,consentHistory,cookieDomain.react.ts— client:ConsentBanner,ConsentGate,CookieSettingsButton,openConsentPreferences,readClientConsent,currentPolicyVersion.adapters/hono.ts—consentRoutes().adapters/next.ts—consentRoute()→{ GET, POST }.
Integration
- Env:
CONSENT_POLICY_VERSION(bump it when the cookie policy changes),SITE_URL(its host gives the registrable domain where third-party tags set their cookies: the last two labels) and, when that guess is wrong (e.g..co.uk),CONSENT_COOKIE_DOMAIN=example.co.uk. Migrations as insrc/lib/db/AGENTS.md. - Mount
/api/consent(passcookiesByCategory, e.g.{ analytics: ['_ga'], marketing: ['_fbp', '_ttp'] }, so withdrawing deletes them, host-only and on the registrable domain). The endpoint only accepts same-origin JSON POSTs (CSRF): a cross-siteOrigin/Sec-Fetch-Sitegets 403 and other content types 415; the banner already posts that way. - Root layout:
<ConsentBanner policyVersion={policyVersion()} policyHref="/cookies" labels={translated} />and in the footer<CookieSettingsButton />(a button that callsopenConsentPreferences()). The banner also renders<meta name="consent-policy-version">: client checks treat a decision made under another version as undecided (everything off) until the visitor decides again. - Wrap every analytics/marketing script:
<ConsentGate category="marketing" policyVersion={policyVersion()}>…</ConsentGate>(policyVersionis optional when the banner is on the page); on the server usehasConsent(cookieHeader, 'analytics'). - With Google tags, render
consentModeDefaultsScript(getConsent(cookieHeader))inline before them. - Verify (browser devtools): before deciding, no request goes to third-party analytics or ad domains.
Conventions
- Labels must be translated (
labelsprop); keep both main buttons equal in style and size. - The consent cookie is first-party, not HttpOnly (scripts must read it), and holds no personal data.
- Keep the cookie policy page listing every cookie per category.
Don't
- Don't pre-check categories, use "scroll means consent" or hide "Reject all" behind extra clicks.
- Don't load analytics/marketing scripts outside
ConsentGate, or send hit data server-side without consent. - Don't block the site behind the banner (cookie walls).
# @core/consent — rules for AI agents
## Purpose
Cookie consent that meets GDPR/ePrivacy: categories (necessary always on; analytics, marketing, preferences off by
default), a banner where "Reject all" is as prominent as "Accept all", a preferences center, proof of each decision
(`consent_records`: choices, policy version, date; no IP), server checks (`hasConsent`), a client `ConsentGate` and
Google Consent Mode v2 values. Changing `CONSENT_POLICY_VERSION` asks everyone again.
## Map
- `index.ts` — server API: `getConsent`, `hasConsent`, `recordConsent`, `consentModeDefaultsScript`, `consentHistory`, `cookieDomain`.
- `react.ts` — client: `ConsentBanner`, `ConsentGate`, `CookieSettingsButton`, `openConsentPreferences`, `readClientConsent`, `currentPolicyVersion`.
- `adapters/hono.ts` — `consentRoutes()`. `adapters/next.ts` — `consentRoute()` → `{ GET, POST }`.
## Integration
1. Env: `CONSENT_POLICY_VERSION` (bump it when the cookie policy changes), `SITE_URL` (its host gives the registrable
domain where third-party tags set their cookies: the last two labels) and, when that guess is wrong (e.g. `.co.uk`),
`CONSENT_COOKIE_DOMAIN=example.co.uk`. Migrations as in `src/lib/db/AGENTS.md`.
2. Mount `/api/consent` (pass `cookiesByCategory`, e.g. `{ analytics: ['_ga'], marketing: ['_fbp', '_ttp'] }`, so withdrawing
deletes them, host-only and on the registrable domain). The endpoint only accepts same-origin JSON POSTs (CSRF):
a cross-site `Origin`/`Sec-Fetch-Site` gets 403 and other content types 415; the banner already posts that way.
3. Root layout: `<ConsentBanner policyVersion={policyVersion()} policyHref="/cookies" labels={translated} />` and in the footer
`<CookieSettingsButton />` (a button that calls `openConsentPreferences()`). The banner also renders `<meta name="consent-policy-version">`: client checks
treat a decision made under another version as undecided (everything off) until the visitor decides again.
4. Wrap every analytics/marketing script: `<ConsentGate category="marketing" policyVersion={policyVersion()}>…</ConsentGate>`
(`policyVersion` is optional when the banner is on the page); on the server use `hasConsent(cookieHeader, 'analytics')`.
5. With Google tags, render `consentModeDefaultsScript(getConsent(cookieHeader))` inline before them.
6. Verify (browser devtools): before deciding, no request goes to third-party analytics or ad domains.
## Conventions
- Labels must be translated (`labels` prop); keep both main buttons equal in style and size.
- The consent cookie is first-party, not HttpOnly (scripts must read it), and holds no personal data.
- Keep the cookie policy page listing every cookie per category.
## Don't
- Don't pre-check categories, use "scroll means consent" or hide "Reject all" behind extra clicks.
- Don't load analytics/marketing scripts outside `ConsentGate`, or send hit data server-side without consent.
- Don't block the site behind the banner (cookie walls).
应用 .genpmignore 后将被注入的确切目录树。固定于
// Adaptador Hono: `app.route('/api/consent', consentRoutes({ cookiesByCategory: { analytics: ['_ga'], marketing: ['_fbp'] } }))`.
import { Hono } from 'hono';
import { handleConsent } from './http.ts';
export function consentRoutes(opts: Parameters<typeof handleConsent>[1] = {}) {
return new Hono().get('/', (c) => handleConsent(c.req.raw, opts)).post('/', (c) => handleConsent(c.req.raw, opts));
}
此包未声明 MCP 服务器。
| 版本 | 提交 | 发布时间 | 扫描 |
|---|---|---|---|
| 1.1.0 | 37d6a8f | 6小时前 | 扫描通过 |
- genpm
- @core/db ^1.0.0
- 建议
- GenPM 会给出 npm 命令建议,只有你同意时才会运行。
- 扫描
- 扫描通过 · 0 个问题
- 提交
- v1.1.0 → 37d6a8faf85f764fdc34ddf9623da7b2b19bcd35 · 获取后已校验
- 脚本
- 无。GenPM 从不运行包中的代码。
- 许可证
- MIT
- 质量
- 100/100
- 可识别的许可证已满足
- AGENTS.md 说明了用途已满足
- AGENTS.md 包含集成步骤已满足
- AGENTS.md 列出约定或禁止事项已满足
- 包含测试已满足
- 通过安全扫描已满足
- 最近 6 个月内发布已满足
- 已验证的发布者已满足
- 摘要和关键词已满足
- 举报
- 发现问题了吗?