> For the complete Lynkow documentation index in agent-friendly format, see [llms.txt](/llms.txt).

# Log a cookie consent action

**Published**: 2026-11-30
**Category**: Analytics & Tracking

## `POST /cookie-consent/logs`

**Log a cookie consent action**

Records one consent action from the site's consent banner. Send
`visitorId`, `action` and `consentGiven`, plus the optional
`sessionId`, `pageUrl` and `locale`.

Pass the `locale` you sent to `GET /cookie-consent/config`: the log
then records the banner language served and its `version`. It also
stores the `User-Agent` and a site-scoped hash of the client IP,
never the raw IP.

The route takes no credential and no spam fields, so a logged row
does not prove that a real visitor made the choice.

Returns 200. An invalid field returns 422 and nothing is recorded.

### Request Body

Content-Type: `application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `visitorId` | string | Yes | Required. The visitor's stable identifier, 1 to 64 characters after surrounding whitespace is trimmed. |
| `sessionId` | string | No | Analytics session ID. UUID format |
| `action` | "accept_all" \| "reject_all" \| "customize" \| "withdraw" | Yes | Required. The consent action: `accept_all`, `reject_all`, `customize` or `withdraw`. |
| `consentGiven` | object | Yes | Required. Maps each category id to `true` (accepted) or `false`. At most 100 keys, each 1 to 50 characters. |
| `pageUrl` | string | No | Absolute `http` or `https` URL of the page, up to 2048 characters. Any other scheme, or none, returns 422. |
| `locale` | string | No | Banner language requested, as sent to `GET /cookie-consent/config`. An unmatched value uses the site default, then English. |


### Responses

| Status | Description |
| --- | --- |
| `200` | Successful response |
| `402` | The site subscription does not currently permit this operation |
| `422` | Validation error |


> **Notes:** Rate-limit bucket: analytics, 600 requests per minute per site and
> client. Exceeding it returns 429 `RATE_LIMIT_EXCEEDED`.

### SDK

```typescript
import { createClient } from 'lynkow'

const lynkow = createClient({ siteId: process.env.LYNKOW_SITE_ID! })

// Revoking a granted consent: 'withdraw' is never inferred.
await lynkow.cookies.logConsent(
  { necessary: true, analytics: false, marketing: false },
  { action: 'withdraw' }
)
```

### Examples

```curl
curl -X POST "https://api.lynkow.com/storefront/{siteId}/cookie-consent/logs" \
  -H "Content-Type: application/json" \
  -d '{
    "visitorId": "v_8f3a2c91d4e7",
    "sessionId": "3f2b8c1e-7a4d-4e9b-9c2a-5d6e7f8a9b0c",
    "action": "customize",
    "consentGiven": { "necessary": true, "analytics": true, "marketing": false, "preferences": true },
    "pageUrl": "https://www.example.com/pricing"
  }'
```

```javascript
await fetch(`https://api.lynkow.com/storefront/${siteId}/cookie-consent/logs`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    visitorId,
    action: 'customize',
    consentGiven: { necessary: true, analytics: true, marketing: false, preferences: true },
    pageUrl: `${location.origin}${location.pathname}`,
  }),
})
```

### Response Example

```json
{
  "data": {
    "message": "Consent logged successfully"
  }
}
```

---