Cookie Munch consent

Let the Lucida browser SDK follow the visitor's Cookie Munch consent choices.

Embed
Preview of the card
<a href="https://lucidace.com/help/cookie-munch"><img src="https://lucidace.com/help/_api/public/orgs/af34862a-c837-4478-8335-0505efe40459/spaces/2f4b888b-c4e6-488b-81bd-6e838fb12d2e/pages/d6a8ab04-e9c3-4237-8118-a439edbc7be2/social-card.svg?v=3e7ae33eec8b" alt="Cookie Munch consent" width="600" height="315"></a>

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.

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

statistics

analytics and replay

marketing

marketing

necessary, preferences, custom ids

not mapped (they gate your own storage, not Lucida's)

a custom id you name with replayCategory (0.1.8)

replay only

  • 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_updated record with source: "cookiemunch"; an unchanged re-announcement is skipped.

  • When Cookie Munch exposes a receipt or ledger id for the decision (a receiptId, consentReceiptId, consentId or ledgerId on the change event's detail or on window.CookieMunch), $consent_updated carries it as consent_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.Cookiebot is the same object), so cookiebotConsent also works. Use cookieMunchConsent for 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 csp it returns from GET /v1/sites/{cbid}/snippet, next to the SDK hosts in Content Security Policy. Consent defaults by country are in Consent by location.

  • With the cookieMunchConsent module you do not need a Cookie Munch vendorHooks entry for Lucida: the module reads the visitor's decision itself and gates Lucida. Adding one on top is redundant.

  • connect-src needs https://capture.lucidace.com (or your own proxy host).

  • script-src needs a Lucida host only when you load the SDK from Lucida's CDN (the classic lucida.js loader). A bundled npm install is covered by 'self'. See Content Security Policy.

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_updated record (from the browser SDK, or sent by your server when you record consent yourself) sets the person property $consent_analytics to granted or denied, taken from categories.analytics. The anonymous decline beacon identifies nobody, so it sets nothing.

  • Choose a mode with server_event_consent in 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_analytics is denied are dropped at ingestion.

    • require_granted: also drop a secret-key event when there is no grant. It is kept only if the event's own properties.$consent_analytics is granted, or the person's stored $consent_analytics is granted. A person who denied is dropped either way.

    • The older boolean drop_server_events_without_consent: true means drop_denied. It is ignored when server_event_consent is set.

  • List event names that must always pass (for example billing events you need to keep) in consent_exempt_events. $consent_updated itself is never dropped, so a person can grant consent again.

  • Every dropped event writes an ingestion warning with outcome dropped: kind consent_denied when the person denied, kind consent_missing (require_granted only) 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_analytics to the profile property allowlist.

  • Browser SDK. A consent bridge (cookieMunchConsent and the other consent modules) records a $consent_updated event for an identified visitor, and Lucida sets $consent_analytics from categories.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_analytics and $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 of analytics and replay is required; an absent one is left as it is. It answers 202 with the event_uuid of the $set event 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_updated event, so it sets granted for the identified person. Since 0.2.1, optOut() while a person is identified first sends one identified $consent_updated (categories false, with $set of $consent_analytics and $consent_replay to denied), then stops capture, so server-side consent gating drops that person's server events. An anonymous visitor's decline only sends the decline beacon (when consent.logBeacon is 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

  1. Before the visitor answers there is no lc_* cookie. Cookie Munch's all-false snapshot is not read as a decline.

  2. When they grant statistics, the bridge writes lc_consent=granted and lc_distinct_id (the browser's id).

  3. The next request reaches lucidaMiddleware (proxy.ts on Next 16, middleware.ts on 14 and 15), which sees the consent, keeps the cookie and forwards the same id; getBootstrap returns it, so server-rendered flags match the browser.

  4. A later decline writes lc_consent=denied and removes lc_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.

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.

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_analytics and $consent_replay (granted or denied) on that person. Analytics follows the statistics category; replay follows it too unless your site has a separate replay category. A delivery for a visitor who was never linked to a person (no identify() subject) is ignored and the link shows the reason. With server_event_consent set to drop_denied or require_granted (or the older drop_server_events_without_consent on), server events of a person who denied analytics are dropped. To set the same properties yourself, call POST /v1/projects/<project_id>/persons/consent with { "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:execute scope (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.

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.

  1. With your account key, mint a project secret key with the privacy:execute scope: POST /v1/projects/<project_id>/keys with {"name": "cookie-munch", "kind": "secret", "scopes": ["privacy:execute"]}. Show-once secret; the key reads nothing besides what these routes return.

  2. Register the executor in Cookie Munch (POST /v1/dsar/executors, checked with ?dryRun=1 on 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 email or $email property. 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 $set on any event. Passing it yourself is optional from browser SDK 0.1.13. With the cookieMunchConsent module the SDK does this automatically: after each identify() it sets $cm_subject_id from CookieMunch.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 completed with the person's properties, events and replay metadata inline (newest events first; capped near 5 MB, then events_truncated: true).

  • Erasure and closure queue the same erasure as persons/bulk_delete (events, recordings, forwarding to destinations) and answer processing, then completed when it has run. A future executeAfter is scheduled and can be cancelled until then.

  • Restriction and rectification are rejected with a reason (erase the person instead, or change properties through identify).

  • A request is idempotent by caseId and Idempotency-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.

Updated