CodeOrigin All articles
Privacy Engineering

Consent as State: Building a Privacy Switchboard Developers Can Defend

CodeOrigin
Consent as State: Building a Privacy Switchboard Developers Can Defend

Photo: person adjusting privacy settings toggles on laptop screen close up keyboard, via as1.ftcdn.net

Ask an engineering team where consent is enforced and the answer is usually a component name. The banner lives in a path like src/components/CookieNotice.tsx, it stores a JSON blob in local storage, and it disappears once the visitor clicks accept. Meanwhile the tag manager has already fired eleven scripts, three of which set identifiers, and one of which loaded before the banner component mounted.

The banner is the smallest part of the problem. Consent is a state variable that many systems read — scripts, APIs, server renders, downstream analytics exports — and state that many systems read needs a defined machine, a single writer, and enforcement at the boundary where it actually matters. Anything less is a notice, not a control.

Purposes Before Categories

U.S. state privacy laws do not map cleanly onto the tidy four-category model copied from European implementations. Before writing UI, write down the purposes your product actually performs, then assign each a category:

Purpose Category Default
Session integrity, security, load balancing Strictly necessary On, not revocable
Aggregate product analytics without identifiers Analytics On, with opt-out
Cross-site advertising identifiers Sale / sharing Off until opted in
Personalized recommendations on-site Targeted content Off until opted in

Two rules make this table useful. First, each purpose names a concrete technical behavior, not a marketing abstraction — if you cannot point at the script or endpoint that implements it, the row is decorative. Second, for California and the growing set of states with comparable statutes, the sale or sharing category must default off and honor a Global Privacy Control signal as an opt-out of sale and sharing without requiring the visitor to find your banner at all.

The State Machine

Three states per purpose, and one rule that filters everything:

UNKNOWN --opt-in--> GRANTED
UNKNOWN --opt-out--> DENIED
GRANTED --opt-out--> DENIED
DENIED --opt-in--> GRANTED
(any) --policy-version-bump--> UNKNOWN for affected purposes

The policy-version transition is the one teams forget. When a purpose changes meaning — a new vendor joins the analytics category, a new advertising partner appears — previously recorded consent does not automatically cover it. Bumping the version for that purpose and re-asking is the honest move, and it is far cheaper than discovering the gap during a review.

Crucially, enforcement treats UNKNOWN as DENIED. A system that treats absence as permission has a default-allow bug, and default-allow is the most expensive bug in this entire domain.

Server-Side Enforcement Is the Only Enforcement

Client-side gating is necessary and insufficient. A script blocked in the browser can still be triggered by a cached server render, a server-side tag container, or a direct API call that never involved the browser at all.

Enforce at the boundary that has the data:

  1. Every analytics and advertising endpoint receives the consent decision as a signed, server-verified claim — not a client-supplied boolean.
  2. The endpoint refuses or downgrades the request when the purpose is not granted, returning a distinguishable status rather than silently dropping the payload.
  3. The server-rendered page omits third-party markup entirely when the purpose is denied, rather than rendering a placeholder that a script later fills.

Step three is where most implementations leak. Conditional rendering in React is still shipping the tag to clients that ignore the condition.

Records an Auditor Can Read

A consent record should be append-only and answerable without a support engineer:

{
  "visitor_id": "v_8f21",
  "purpose": "analytics",
  "state": "granted",
  "policy_version": 4,
  "surface": "preference-center",
  "signal": null,
  "recorded_at": "2026-11-14T18:22:07Z",
  "ip_truncated": "203.0.113.0/24"
}

Store the decision history, not just the current state. When someone asks what a visitor agreed to in March, the answer must be reconstructible from the log rather than inferred from a mutable row that has been overwritten six times.

The UI Must Be Testable

An accessible preference center is not decoration; it is the surface that produces the state the rest of the system depends on.

Testing the Switchboard

Four tests turn the banner from theater into a component with a specification:

Privacy preferences are state, and state deserves a machine, a single writer, and enforcement where the data lives. Once that is true, the banner stops being a legal formality and starts being the control panel it was always supposed to be — one your engineers can defend in a review without reaching for the phrase that is handled by marketing.

All Articles

Related Articles

Write the Event Where You Write the Row: Anatomy of a Transactional Outbox

Write the Event Where You Write the Row: Anatomy of a Transactional Outbox

Every Copy Has an Owner: Designing Cache Invalidation as a Contract

Every Copy Has an Owner: Designing Cache Invalidation as a Contract

One Request, Many Rooms: A Correlation Contract for Code That Leaves Home

One Request, Many Rooms: A Correlation Contract for Code That Leaves Home