> Part of the walkerOS documentation. Project overview and full index: <https://www.walkeros.io/llms.txt>

# Consent management

walkerOS checks consent before events leave a flow. You record the user's choices in the collector, and each source and destination declares which consent it needs. Events that lack consent either wait or are dropped, depending on where you set the requirement and, on a server, on the collector's `consentDenied` setting.

warning

This page is not legal advice. Consult a legal expert about the laws and regulations that apply to your business.

## Record consent[​](#record-consent "Direct link to Record consent")

A Consent Management Platform (CMP) usually collects the user's choice. That happens asynchronously: the CMP has to load, and the user may decide late or not at all. walkerOS provides [CMP source packages](https://www.walkeros.io/docs/sources/web/cmps.md) that listen for CMP events and send the consent command for you.

Without a CMP source, send the `walker consent` command yourself:

```javascript
elb('walker consent', { functional: true, marketing: false });
```

Consent keys are free-form. Common groups are `functional`, `analytics`, and `marketing`, and you can also use one key per vendor. The command stores each value as a boolean and only updates the keys it contains, so `elb('walker consent', { marketing: true })` leaves an existing `functional` state as it is.

## Configure consent in a flow[​](#configure-consent-in-a-flow "Direct link to Configure consent in a flow")

This web flow uses a CMP source to record consent and allows the gtag destination to receive events only with analytics or marketing consent. The gtag destination's default Consent Mode mapping sends the CMP source's `analytics` group to Google's `analytics_storage`:

```json
{
  "version": 4,
  "flows": {
    "default": {
      "config": { "platform": "web" },
      "sources": {
        "cmp": {
          "package": "@walkeros/web-source-cmp-cookiefirst"
        },
        "browser": {
          "package": "@walkeros/web-source-browser",
          "config": {
            "settings": { "pageview": true }
          }
        }
      },
      "destinations": {
        "gtag": {
          "package": "@walkeros/web-destination-gtag",
          "config": {
            "loadScript": true,
            "consent": { "analytics": true, "marketing": true },
            "settings": {
              "ga4": {
                "measurementId": "G-XXXXXXXXXX",
                "pageview": false
              }
            }
          }
        }
      }
    }
  }
}
```

`"loadScript": true` makes the destination load gtag.js; leave it out when your page already loads it. `"pageview": false` stops gtag's `config` from sending a page view of its own next to the browser source's `page view`.

### Gate a destination with `consent`[​](#gate-a-destination-with-consent "Direct link to gate-a-destination-with-consent")

A destination's `config.consent` lists the consent keys it needs. The collector checks every event against it before the destination sees the event:

* One granted key is enough. With `{ "analytics": true, "marketing": true }`, the destination receives events if either `analytics` or `marketing` is granted.
* Events without the required consent wait in the destination's queue (the push answers `queued` with the reason `consent`). Once consent is granted, they are delivered in their original order. Server flows built by the CLI skip these events instead (`consentDenied: 'skip'`). On a server collector that queues, one `walker consent` sends every user's waiting events, see [consent-denied events on a server](https://www.walkeros.io/docs/collector.md#consent-denied-events-on-a-server).
* The collector initializes the destination only after its required consent is granted: at the first event that passes the check or, for a destination with an `on()` handler, at the consent command that grants it.
* The queue holds up to 1000 events per destination by default. When it is full, the oldest events go first. Change the limit with `config.queueMax`. See [buffer bounds](https://www.walkeros.io/docs/collector.md#buffer-bounds).

`config.queue` does not switch off this consent queue. The collector also keeps the events of the current run, so a destination added later still receives them. `"queue": false` skips only that replay for the destination.

Once a consent state is recorded, a destination receives it through its `on('consent')` handler before any later event is sent to it. This holds when consent was set before or after `walker run`, when the destination waits for consent with `require`, and when it is added with `walker destination` while the flow is running. The collector waits for the handler to finish, up to the destination's `config.timeout` (10 seconds by default), and delivers the state again when it changes. Events pushed meanwhile are held for the destination: their push answers `queued` with the reason `held`.

If the handler fails or does not finish in that time, the collector writes an ERROR line (`consent not applied`) and holds the destination's events for one more `config.timeout`. The first push after that window retries a failed delivery before it sends, and a handler that finishes late receives the current state again right away. Once a delivery succeeds, the held events are delivered. If none has succeeded by the first push after the window, the held events and every later event with the required consent fail with the reason `blocked` until one does: the push answers `ok: false`, the events are counted in `status.destinations[id].failed` and kept in the destination's dead-letter queue, an ERROR `Push failed` line is written, and they are not sent when the destination recovers. Later pushes retry the delivery once per `config.timeout`. A handler that timed out gets no new delivery until it finishes, so one that never finishes keeps its destination blocked. A `walker run` discards events that are still held, with no counter and no log line. See the [failure codes](https://www.walkeros.io/docs/collector/logger.md#failure-codes).

### Gate one event type with a rule's `consent`[​](#gate-one-event-type-with-a-rules-consent "Direct link to gate-one-event-type-with-a-rules-consent")

A mapping rule's `consent` adds a requirement for the events that rule matches, on top of the destination's `config.consent`:

```json
"gtag": {
  "package": "@walkeros/web-destination-gtag",
  "config": {
    "consent": { "analytics": true },
    "settings": { "ga4": { "measurementId": "G-XXXXXXXXXX" } },
    "mapping": {
      "order": {
        "complete": { "name": "purchase", "consent": { "marketing": true } }
      }
    }
  }
}
```

Both must hold. Events the rule matches wait in the same queue and are delivered in queue order once both are granted (with an async `condition`, an event joins the queue when its condition settles); server flows built by the CLI skip them instead. Observe and `walkeros push --simulate` show the rule's key and the missing consent.

### Gate a source with `consent`[​](#gate-a-source-with-consent "Direct link to gate-a-source-with-consent")

The collector drops events from a source when they lack the consent in the source's `config.consent`. Sources have no consent queue, so granting consent later does not bring these events back:

```json
"browser": {
  "package": "@walkeros/web-source-browser",
  "config": {
    "consent": { "functional": true },
    "settings": { "pageview": true }
  }
}
```

A source mapping rule's `consent` drops the events that rule matches the same way.

Use source gating when events must not enter the flow at all without consent. Use destination gating when events should wait for a decision (in a server flow built by the CLI they are skipped, see above).

### Wait for the CMP with `require`[​](#wait-for-the-cmp-with-require "Direct link to wait-for-the-cmp-with-require")

`"require": ["consent"]` holds a destination back, and holds a source's `on()` delivery back, until the collector has a consent state. Any recorded state counts, whether granted or denied, so `require` does not check values; `config.consent` decides which events the destination receives. See [conditional activation](https://www.walkeros.io/docs/sources/web/cmps.md#conditional-activation-with-require) for how `require` works.

### Set an initial consent state[​](#set-an-initial-consent-state "Direct link to Set an initial consent state")

The flow's `collector` block (next to `sources` and `destinations`) sets the state before any CMP reports:

```json
"collector": {
  "consent": { "functional": true }
}
```

An initial state is a recorded consent state, so it satisfies `"require": ["consent"]` as soon as the flow starts.

## How queued events are processed[​](#how-queued-events-are-processed "Direct link to How queued events are processed")

The collector re-checks a destination's queue whenever a new event or a state command (such as `walker consent`, `walker user`, or `walker globals`) reaches the destinations. Before the check, each queued event is updated:

* `consent` is replaced with the current collector state. Once the event passes, it carries only the granted keys. A held event keeps the consent it was pushed with (see [Revoke consent](#revoke-consent)).
* `user` is merged with the collector's user data. Values already on the event take precedence. This holds for the consent queue. Events a destination receives when its `require` is met, or when it is added with `walker destination`, carry the user set after they were captured: an event from before a `walker user` call reaches that destination under the user id that call set. An event that brought its own `user` keeps those values; a field it lacks, such as `id`, comes from the later user.
* `globals` keeps the values the event was captured with.

The queues belong to the current run. A `walker run` command starts a new run and clears the destination queues along with the replay buffer, so events still waiting for consent are lost. The collector already runs by default, so do not send `walker run` in reaction to a consent change. Only a bundle you build with `run: false` needs one `elb('walker run')`: call it once, from your CMP's first consent callback, not from an `on consent` handler, which is not called before the collector runs.

## Revoke consent[​](#revoke-consent "Direct link to Revoke consent")

To stop sending events to a destination, set its required keys to `false`:

```javascript
elb('walker consent', { marketing: false });
```

Once none of a destination's required keys is granted, new events are queued for it instead of delivered (skipped in a server flow built by the CLI). If consent is granted again during the same run, those queued events are delivered. Events that were already sent are not affected. An event that is held for the destination when consent is revoked (while a consent delivery to it runs, or within the window after one failed, see [Gate a destination](#gate-a-destination-with-consent)) is still sent when the hold ends, after the revocation, with the consent it was pushed with. So is an event that a `collector.next` chain split into several (a `many` route, or a transformer returning more than one event) when the revocation lands while a destination waits for that event's async rule `condition`.

## Opt-out[​](#opt-out "Direct link to Opt-out")

An opt-out beats consent: when a user opts out, no event of theirs reaches a destination, whatever consent they granted. Mark the user with `optout: true` and stop the event at the first step of the chain with a gated stop:

```json
{
  "match": { "key": "event.user.optout", "operator": "eq", "value": "true" },
  "stop": true
}
```

* **Web:** put the stop first in your bundle's `collector.next`. No event of an opted-out browser reaches a destination. Sources still run, for example the session source keeps its ids in storage.
* **Server:** put the stop first in the source's `next`, before deduplication. An opted-out event leaves no dedup entry and no fingerprint hash, and reaches no destination.

`eq` compares as strings, so a boolean `true` and the string `"true"` both match.

The stop applies to events only. A destination with an `on()` handler still initializes: right away when it has no consent requirement, otherwise once that consent is granted. Its `on()` handler still receives consent and user changes, including the `optout` flag and the user's ids. A destination without an `on()` handler initializes with its first event, so for an opted-out user it does not initialize. A destination that loads a vendor script loads it for an opted-out user too: the gtag destination with `"loadScript": true` loads gtag.js and runs its `config` command, and gtag.js then sends what the Google tag collects by itself, such as Google's own page view (unless `pageview` is `false`) and the enhanced measurement events of the GA4 data stream. `"pageview": false` turns off only that page view, not the rest.

Set the flag before the first event. A `walker user` command queued in `elbLayer` before your bundle loads applies before anything is sent:

```javascript
// Before your bundle loads
window.elbLayer = window.elbLayer || [];
window.elbLayer.push(['walker user', { optout: true }]);
```

`data-elbuser` is read right before the page view, so it keeps the page view in the browser. Events sent before it is read, such as `session start` and events queued in `elbLayer` before your bundle loaded, are sent.

```html
<body data-elbuser="optout:true">
```

A `walker user` command after your bundle loaded stops every later event, but the page view of that page has already been sent.

The server flow of [`flow-complete.json`](https://github.com/elbwalker/walkerOS/blob/main/packages/cli/examples/flow-complete.json), the tested example flow, stops opted-out events before `dedup`; its web flow uses the same stop first in `collector.next`:

`/flows/server/sources/express/next/0`

```json
{
  "match": {
    "key": "event.user.optout",
    "operator": "eq",
    "value": "true"
  },
  "stop": true
}
```

An opted-out user (user.optout true) is stopped first: on the server before dedup, so no dedup entry, hash or delivery; on the web first in collector.next, so the browser sends nothing. [Guide chapter `consent-privacy`](https://github.com/elbwalker/walkerOS/blob/main/packages/cli/examples/flow-complete.md#consent-privacy-consent-and-personal-data)

## Consent on a single event[​](#consent-on-a-single-event "Direct link to Consent on a single event")

An event can carry its own `consent`. It is merged over the collector state for this event, and the event's values win:

```javascript
elb({ name: 'order complete', consent: { marketing: true } });
```

If the event is still waiting for consent, the next check replaces its `consent` with the collector state, as described above.

To send a single field only with consent, use [consent in a mapping value](https://www.walkeros.io/docs/mapping/value.md#consent).

## React to consent changes[​](#react-to-consent-changes "Direct link to React to consent changes")

Use the `walker on` command with the `consent` type to run code when consent changes. `rules` is an object with one handler per consent key:

```javascript
elb('walker on', {
  type: 'consent',
  rules: {
    marketing: (consent, context) => {
      if (consent.marketing) {
        // marketing was granted
      } else {
        // marketing was denied
      }
    },
  },
});
```

A handler receives the consent state and a context with `collector` and `logger`:

* It runs when its key is part of a `walker consent` command, for a denial as well as a grant, and receives only the values of that command. Check the value inside the handler.
* When it is registered, and when the collector starts, it receives the full consent state and runs if its key is set. Until the collector runs, no handler is called.
* `rules` must be an object keyed by consent name. A bare function has no key and is never called.

To start or stop sending events based on consent, use `config.consent` and `require` instead of handlers. See [on](https://www.walkeros.io/docs/collector/commands.md#on) for all subscription types.

## Google Consent Mode[​](#google-consent-mode "Direct link to Google Consent Mode")

The [gtag destination](https://www.walkeros.io/docs/destinations/web/gtag.md) supports Google Consent Mode v2 through its `como` setting, which is on by default. When the destination has a `config.consent` requirement (or `como_advanced` is set), it first sets every mapped parameter to `denied` with `gtag('consent', 'default', ...)` before it loads or configures any Google tag (GA4, Google Ads, GTM); otherwise it sends that default right before its first update. It turns consent commands into `gtag('consent', 'update', ...)` calls, and holds commands sent before it initializes until initialization. The default mapping is:

| walkerOS key | Consent Mode parameters                            |
| ------------ | -------------------------------------------------- |
| `marketing`  | `ad_storage`, `ad_user_data`, `ad_personalization` |
| `analytics`  | `analytics_storage`                                |

The Cookiebot, CookieFirst and CookiePro sources report measurement consent as `analytics` and advertising consent as `marketing`, so the default mapping follows the visitor's choices. The Usercentrics source reports your own category slugs: map your measurement category to `analytics` and your advertising category to `marketing` in its `categoryMap`, or `analytics_storage` stays denied. When several walkerOS keys map to the same parameter, the parameter is `granted` only if every one of them is granted in the current consent state.

Pass an object to use your own keys:

```json
"gtag": {
  "package": "@walkeros/web-destination-gtag",
  "config": {
    "loadScript": true,
    "consent": { "statistics": true, "marketing": true },
    "settings": {
      "como": {
        "marketing": ["ad_storage", "ad_user_data", "ad_personalization"],
        "statistics": "analytics_storage"
      },
      "ga4": { "measurementId": "G-XXXXXXXXXX", "pageview": false }
    }
  }
}
```

Set `"como": false` to turn it off. Do not call `gtag('consent', 'update')` yourself while `como` is on, because Google then receives duplicate or conflicting updates.
