Cookie Munch consent
Let the Lucida browser SDK follow the visitor's Cookie Munch consent choices.
Cookie Munch is the consent banner, consent ledger and privacy-request service Lucida uses on its own site. Two things matter to you: the browser SDK can follow its banner, and a self-hosted Lucida can answer its rights requests for your own console users.
Follow Cookie Munch in the browser SDK
cookieMunchConsent has been in @lucida-analytics/browser since 0.1.1 (it is not in 0.1.0; the current release is 0.1.8). Anything marked "0.1.8" below needs that version or later (npm install @lucida-analytics/browser@latest). Add the bridge module next to the SDK. It reads CookieMunch.consent once the visitor has a decision (hasResponse), then follows CookieMunchOnChange and CookieMunchOnConsentReady:
import { createClient } from "@lucida-analytics/browser";
import { cookieMunchConsent } from "@lucida-analytics/browser/consent";
createClient("lc_pk_...", { consent: { mode: "opt_in" } }, [cookieMunchConsent]);Cookie Munch category | Lucida category |
|---|---|
|
|
|
|
| not mapped (they gate your own storage, not Lucida's) |
a custom id you name with |
|
Before the visitor answers nothing is captured or stored. Cookie Munch's snapshot is all-false before a decision; the bridge never reads that as a decline.
Each change writes the usual
$consent_updatedrecord withsource: "cookiemunch"; an unchanged re-announcement is skipped.When Cookie Munch exposes a receipt or ledger id for the decision (a
receiptId,consentReceiptId,consentIdorledgerIdon the change event'sdetailor onwindow.CookieMunch),$consent_updatedcarries it asconsent_receipt_id(0.1.8). Without one the property is absent. Use it to tie a Lucida consent record to your Cookie Munch ledger entry.Every decision also writes the first-party cookies
lc_consent=granted|denied(and, on a grant,lc_distinct_id) so your server can follow it; nothing is written before a decision (0.1.8). See below and Evaluate flags at the edge.Cookie Munch is Cookiebot-compatible (
window.Cookiebotis the same object), socookiebotConsentalso works. UsecookieMunchConsentfor the native event names.Load the Cookie Munch tag before or after the SDK; both orders work. For the tag's own CSP sources use the
cspit returns fromGET /v1/sites/{cbid}/snippet, next to the SDK hosts in Content Security Policy. Consent defaults by country are in Consent by location.
Content Security Policy and Cookie Munch vendor hooks
With the
cookieMunchConsentmodule you do not need a Cookie MunchvendorHooksentry for Lucida: the module reads the visitor's decision itself and gates Lucida. Adding one on top is redundant.connect-srcneedshttps://capture.lucidace.com(or your own proxy host).script-srcneeds a Lucida host only when you load the SDK from Lucida's CDN (the classiclucida.jsloader). A bundled npm install is covered by'self'. See Content Security Policy.
Consent-aware server events
Server code (Node, Python, webhooks) sends events with a secret key, and no banner is involved. Lucida remembers each person's last analytics choice so those events can respect it:
Every
$consent_updatedrecord (from the browser SDK, or sent by your server when you record consent yourself) sets the person property$consent_analyticstograntedordenied, taken fromcategories.analytics. The anonymous decline beacon identifies nobody, so it sets nothing.Choose a mode with
server_event_consentin the project's ingest settings (PUT /v1/projects/{id}/settings/ingest). Browser events are untouched in every mode: the SDK already stops them.off(the default): nothing is dropped.drop_denied: secret-key events for a person whose$consent_analyticsisdeniedare dropped at ingestion.require_granted: also drop a secret-key event when there is no grant. It is kept only if the event's ownproperties.$consent_analyticsisgranted, or the person's stored$consent_analyticsisgranted. A person who denied is dropped either way.The older boolean
drop_server_events_without_consent: truemeansdrop_denied. It is ignored whenserver_event_consentis set.
List event names that must always pass (for example billing events you need to keep) in
consent_exempt_events.$consent_updateditself is never dropped, so a person can grant consent again.Every dropped event writes an ingestion warning with outcome
dropped: kindconsent_deniedwhen the person denied, kindconsent_missing(require_grantedonly) when no grant was found. Count them in the ingestion warnings list.First sign-in under
require_granted. A brand-new person has no stored answer yet, so their first server event (a sign-up event, for example) is dropped. If your server knows the choice from the consent banner, send it on the event:properties: { "$consent_analytics": "granted" }. The event is then kept. Send it only when the visitor really granted.To read the value in the Profile API, add
$consent_analyticsto the profile property allowlist.
Where a person's $consent_analytics comes from
Browser SDK. A consent bridge (
cookieMunchConsentand the other consent modules) records a$consent_updatedevent for an identified visitor, and Lucida sets$consent_analyticsfromcategories.analytics. A visitor who declines is not identified by the anonymous decline beacon, so a decline sets nothing on a person.Cookie Munch partner deliveries. Each decision delivered through the partner link sets
$consent_analyticsand$consent_replay(see the partner link section below).POST /v1/projects/{id}/persons/consent. Sets them directly:{"distinct_id": "user_123", "analytics": false, "replay": false}. At least one ofanalyticsandreplayis required; an absent one is left as it is. It answers202with theevent_uuidof the$setevent that carries the change, so the value shows up once that event is processed. Needs a key with person write access.React Native SDK.
optIn()captures a$consent_updatedevent, so it setsgrantedfor the identified person. Since 0.2.1,optOut()while a person is identified first sends one identified$consent_updated(categories false, with$setof$consent_analyticsand$consent_replaytodenied), then stops capture, so server-side consent gating drops that person's server events. An anonymous visitor's decline only sends the decline beacon (whenconsent.logBeaconis on), which sets nothing on a person.
When the decision is made somewhere other than the browser bridge, for example in a mobile app or a preference centre, send it with POST /v1/projects/{id}/persons/consent. Then server-side drops and replay follow the person's real choice.
Read the current decision with GET /v1/projects/{id}/persons/consent?distinct_id=user_123 (a key with person read access):
{ "distinct_id": "user_123", "analytics": "denied", "replay": null }analytics and replay are granted, denied, or null when no decision was recorded. An unknown person is 404. After a POST, the GET can lag by the time it takes the event to be processed.
curl -X PUT https://<your-lucida>/v1/projects/<project-id>/settings/ingest \
-H "Authorization: Bearer <token>" -H "Content-Type: application/json" \
-d '{"server_event_consent": "require_granted", "consent_exempt_events": ["invoice_paid"]}'Changes reach ingestion within about a minute. A person with no recorded choice is treated as not denied, so drop_denied keeps their events and require_granted drops them unless the event itself says granted.
A separate replay category
By default statistics switches on both analytics and replay. To let visitors accept replay separately, create a custom category in Cookie Munch (for example session_replay) and name it on the bridge. statistics then gates analytics only and the custom category gates replay only (0.1.8; the default is unchanged):
import { cookieMunchBridge } from "@lucida-analytics/browser/consent";
createClient("lc_pk_...", { consent: { mode: "opt_in" } }, [cookieMunchBridge({ replayCategory: "session_replay" })]);Next.js and React
LucidaNextProvider (@lucida-analytics/next/client) and LucidaProvider (@lucida-analytics/react) take modules, passed as the third argument of init (@lucida-analytics/next 0.1.5 and @lucida-analytics/react 0.1.3). A server component cannot pass functions to a client component, so put the provider in a small client component:
// app/lucida-provider.tsx
"use client";
import { LucidaNextProvider } from "@lucida-analytics/next/client";
import { cookieMunchConsent } from "@lucida-analytics/browser/consent";
import type { Bootstrap } from "@lucida-analytics/next";
export function Lucida({ bootstrap, children }: { bootstrap: Bootstrap; children: React.ReactNode }) {
return (
<LucidaNextProvider
apiKey={process.env.NEXT_PUBLIC_LUCIDA_KEY!}
bootstrap={bootstrap}
options={{ consent: { mode: "opt_in" } }}
modules={[cookieMunchConsent]}
>
{children}
</LucidaNextProvider>
);
}Plain React: <LucidaProvider apiKey="lc_pk_..." options={{ consent: { mode: "opt_in" } }} modules={[cookieMunchConsent]}>. modules is read once, when the client is created. The Cookie Munch tag itself loads in your layout; take the exact tag from your Cookie Munch dashboard.
The server side of the same flow
Before the visitor answers there is no
lc_*cookie. Cookie Munch's all-false snapshot is not read as a decline.When they grant statistics, the bridge writes
lc_consent=grantedandlc_distinct_id(the browser's id).The next request reaches
lucidaMiddleware(proxy.tson Next 16,middleware.tson 14 and 15), which sees the consent, keeps the cookie and forwards the same id;getBootstrapreturns it, so server-rendered flags match the browser.A later decline writes
lc_consent=deniedand removeslc_distinct_id.
To read Cookie Munch's own cookie on the server instead, give the middleware a consent(req) callback. The full flow is in Evaluate flags at the edge.
Forward a Cookie Munch erasure to Lucida
Cookie Munch can run rights requests on Lucida directly (see the next section). Without that connection, Lucida does not hear about an erasure by itself: your own handler forwards it. Lucida erases by person or by distinct id only. Use the id you passed to identify(...) for signed-in users (for visitors who never signed in, the anonymous id is in the lc_distinct_id cookie), and call the bulk delete API, also described in Test against production:
curl -s -X POST https://<api-host>/v1/projects/<project_id>/persons/bulk_delete \
-H 'authorization: Bearer <key with person admin access>' -H 'content-type: application/json' \
-d '{"distinct_ids":["user_123"]}'The response lists the queued requests and a batch_id; poll GET /v1/projects/<project_id>/deletion-requests?batch_id=<batch_id> until each is done. The person, their events, sessions and recordings go, and the delete is forwarded to connected destinations that have a delete API. The body also takes events, recordings and keep_person. Distinct ids that name no person come back in errors. Erasure is permanent. Keep the consent_receipt_id (if you capture it) next to your own record of the request.
Link a Lucida project from Cookie Munch (partner link)
Lucida is in Cookie Munch's partner catalogue, so a Cookie Munch site links to a Lucida project with no key copied by hand. GET /v1/projects/<project_id>/cookiemunch shows partner_enabled: true and, after the first delivery, the site under linked_sites. In Cookie Munch, grant the partner lucida on the site with externalId set to your Lucida project id (Project settings, or GET /v1/projects). Two things then work on their own:
Consent reaches the person. Each consent decision Cookie Munch records for a signed-in visitor is delivered to Lucida, which sets
$consent_analyticsand$consent_replay(grantedordenied) on that person. Analytics follows thestatisticscategory; replay follows it too unless your site has a separate replay category. A delivery for a visitor who was never linked to a person (noidentify()subject) is ignored and the link shows the reason. Withserver_event_consentset todrop_deniedorrequire_granted(or the olderdrop_server_events_without_consenton), server events of a person who denied analytics are dropped. To set the same properties yourself, callPOST /v1/projects/<project_id>/persons/consentwith{ "distinct_id": "user_123", "analytics": false, "replay": false }(a key with person write access).Rights requests run with no key. Provision the executor by asking Cookie Munch to mint it from the link. It creates a Lucida project secret key that holds only the
privacy:executescope (lookup and erasure of this project's people, nothing else) and stores it encrypted:
{ "system": "lucida", "preset": "lucida", "mintFrom": "lucida", "cbid": "dv-...", "externalId": "<project_id>" }Send it to Cookie Munch's POST /v1/dsar/executors. mintFrom needs the link to exist first: grant the lucida partner on the site (POST /v1/partner_links with partner lucida), or pass cbid and externalId as above. Without either, Cookie Munch answers 400 on mintFrom ("no link for lucida on this site"). Check the body with ?dryRun=1 first.
Cookie Munch calls Lucida once per site, confirms the link with its own API, and Lucida answers with the key and https://<api-host>/v1/projects/<project_id> as the executor address. Minting again replaces the key for that site. Revoke the link in Cookie Munch (or the key under Project settings, API keys) to stop it at once.
A key that only erases: give a project secret key the privacy:execute scope and it alone may call persons/bulk_delete and DELETE /v1/projects/<project_id>/persons/<person_id>, so the handler needs no admin key (secret keys cannot hold admin). It reads nothing else.
Let Cookie Munch run rights requests on Lucida
Lucida speaks the cm-standard-v2 executor contract for a project's persons, so Cookie Munch looks people up, exports their data and erases them without any handler of yours.
Which key: the executor preset's secretKey is a project secret key holding privacy:execute, minted with your account key (lc_pat_). Not the project's event key: a capture-only secret key answers 403 this key can only send events, and a project key cannot mint keys. GET /v1/whoami with any key shows its kind and scopes.
With your account key, mint a project secret key with the
privacy:executescope:POST /v1/projects/<project_id>/keyswith{"name": "cookie-munch", "kind": "secret", "scopes": ["privacy:execute"]}. Show-once secret; the key reads nothing besides what these routes return.Register the executor in Cookie Munch (
POST /v1/dsar/executors, checked with?dryRun=1on 2026-11-25):
{ "system": "lucida", "preset": "lucida", "projectId": "<project_id>", "secretKey": "<privacy:execute key>", "cbid": "dv-..." }Cookie Munch resolves it to POST /v1/projects/<project_id>/privacy/lookup and /privacy/requests (export as access, erase as deletion) with Bearer auth.
The routes under that base URL are POST /privacy/lookup, POST /privacy/requests, GET /privacy/requests/{id}, POST /privacy/requests/{id}/cancel and /run. Every answer carries X-Version: 2.
Matching. A lookup finds a person by the subject id first, then by distinct id, then by the person's
emailor$emailproperty. An email is never matched through a person who carries a different subject id, and when an identity is sent but matches nobody, the email is only tried when Cookie Munch says the address is verified.$cm_subject_id. The subject id is the person property$cm_subject_id. Set it when the visitor is identified, with the id Cookie Munch knows them by:lucida.identify("user_123", { $cm_subject_id: "user_123" }), or$seton any event. Passing it yourself is optional from browser SDK 0.1.13. With thecookieMunchConsentmodule the SDK does this automatically: after eachidentify()it sets$cm_subject_idfromCookieMunch.getSubjectId()when that returns a non-empty string and you did not pass your own. A person whose distinct id already is that id is found without it.Access answers
completedwith the person's properties, events and replay metadata inline (newest events first; capped near 5 MB, thenevents_truncated: true).Erasure and closure queue the same erasure as
persons/bulk_delete(events, recordings, forwarding to destinations) and answerprocessing, thencompletedwhen it has run. A futureexecuteAfterisscheduledand can be cancelled until then.Restriction and rectification are
rejectedwith a reason (erase the person instead, or change properties through identify).A request is idempotent by
caseIdandIdempotency-Key. Cookie Munch's canary subject is answered without touching any data.
Signed completions
By default Cookie Munch polls Lucida for each request's outcome. To have Lucida tell it the moment a request is final, give Lucida the connection's completionUrl and completionSecret (shown on the executor connection in Cookie Munch):
PUT /v1/projects/<project_id>/privacy/completion
{ "url": "https://api.cookiemunch.net/v1/dsar/executors/<connection id>/completions", "secret": "whsec_..." }(Project settings, Cookie Munch card, does the same.) Every request that reaches completed, completed_with_retention, no_match, rejected or cancelled is POSTed there once, signed with Webhook-Id, Webhook-Timestamp and Webhook-Signature (v1, plus a base64 HMAC-SHA256 over <id>.<timestamp>.<body>). A failed push is retried twice (after 1 and 4 seconds) and never fails your request; Cookie Munch's poll covers anything missed. The secret is stored encrypted and never returned: GET on the same path shows url, configured and last_signed_completion_at, and DELETE turns pushes off. GET /v1/projects/<project_id>/cookiemunch lists the linked sites and whether completions are configured.