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

# CookieFirst

Integrates [CookieFirst](https://cookiefirst.com/) consent management with walkerOS by listening for CookieFirst events and translating consent categories to walkerOS consent groups.

## Installation[​](#installation "Direct link to Installation")

```
npm install @walkeros/web-source-cmp-cookiefirst
```

```
import { startFlow } from '@walkeros/collector';

import { sourceCookieFirst } from '@walkeros/web-source-cmp-cookiefirst';



await startFlow({

  sources: {

    consent: {

      code: sourceCookieFirst,

    },

  },

});
```

## Configuration[​](#configuration "Direct link to Configuration")

This <!-- -->source<!-- --> uses the standard <!-- -->source<!-- --> config wrapper (consent, data, env, id, ...). For the shared fields see [source<!-- --> configuration](https://www.walkeros.io/docs/sources.md#configuration). Package-specific fields live under `config.settings` and are listed below.

## Settings[​](#settings "Direct link to Settings")

| Property       | Type                     | Description                                                                                                  | More |
| -------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------ | ---- |
| `categoryMap`  | `Record<string, string>` | Map the CMP's consent categories (keys) to walkerOS consent groups (values).                                 |      |
| `explicitOnly` | `boolean`                | Only process consent after the user made an explicit choice. Ignores default/implicit states. Default: true. |      |
| `globalName`   | `string`                 | Custom name for the CookieFirst global on window. Default: 'CookieFirst'.                                    |      |

## Mapping[​](#mapping "Direct link to Mapping")

This package does not define custom rule-level settings. For the standard rule fields (consent, condition, data, batch, name, policy) see [mapping](https://www.walkeros.io/docs/mapping.md).

## Examples

### Category map override

Custom categoryMap remaps performance to statistics instead of analytics

Event

```
{
  "necessary": true,
  "functional": false,
  "performance": true,
  "advertising": false
}
```

Mapping

```
{
  "settings": {
    "categoryMap": {
      "performance": "statistics"
    }
  }
}
```

Out

```
elb("walker consent", {
  "functional": true,
  "statistics": true,
  "marketing": false
})
```

### cf\_init detection

CMP detected via cf\_init CustomEvent (primary detection path)

Event

```
{
  "necessary": true,
  "functional": false,
  "performance": false,
  "advertising": true
}
```

Out

```
elb("walker consent", {
  "functional": true,
  "analytics": false,
  "marketing": true
})
```

### Full consent

CookieFirst reports all categories granted and the source forwards a walker consent command with all groups true.

Event

```
{
  "necessary": true,
  "functional": true,
  "performance": true,
  "advertising": true
}
```

Out

```
elb("walker consent", {
  "functional": true,
  "analytics": true,
  "marketing": true
})
```

### Partial consent

A partial CookieFirst grant maps analytics and marketing to false in the emitted walker consent command.

Event

```
{
  "necessary": true,
  "functional": true,
  "performance": false,
  "advertising": false
}
```

Out

```
elb("walker consent", {
  "functional": true,
  "analytics": false,
  "marketing": false
})
```

## How it works[​](#how-it-works "Direct link to How it works")

1. **Initialization**: Checks if CookieFirst is already loaded and processes existing consent state from `window.CookieFirst.consent`.

2. **cf\_init event**: Listens for the `cf_init` event fired when CookieFirst banner initializes.

3. **cf\_consent event**: Listens for the `cf_consent` event fired when user changes consent preferences.

4. **Consent mapping**: Translates CookieFirst categories to walkerOS consent groups and calls `elb('walker consent', state)`.

### Default category mapping[​](#default-category-mapping "Direct link to Default category mapping")

```
{

  necessary: 'functional',

  functional: 'functional',

  performance: 'analytics',

  advertising: 'marketing',

}
```

When multiple CookieFirst categories map to the same walkerOS group (e.g., both `necessary` and `functional` to `functional`), the source uses OR logic: if ANY source category is `true`, the target group is `true`.

### Custom mapping example[​](#custom-mapping-example "Direct link to Custom mapping example")

```
await startFlow({

  sources: {

    consent: {

      code: sourceCookieFirst,

      config: {

        settings: {

          categoryMap: {

            performance: 'statistics', // Use 'statistics' instead of 'analytics'

          },

          explicitOnly: true,

        },

      },

    },

  },

});
```

## Reference[​](#reference "Direct link to Reference")

* [CookieFirst public API documentation](https://support.cookiefirst.com/hc/en-us/articles/360011568738-Cookie-Banner-Public-API-documentation)
* [Source code](https://github.com/elbwalker/walkerOS/tree/main/packages/web/sources/cmps/cookiefirst)
