> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wendung.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Wendung.setConsent(): Apply the visitor's analytics choice

> Start collection when analytics is allowed, or stop it, drop queued events, and remove the SDK's browser identifiers when it is denied.

Call `Wendung.setConsent()` when the visitor makes or changes their analytics choice. It moves the SDK between the three states described in the [consent guide](/guides/consent). Calling it with the current state does nothing.

Throws if called before [`init()`](/api-reference/init) or with a value other than the three states.

```typescript theme={null}
Wendung.setConsent(state: ConsentState): void
```

## Parameters

<ParamField body="state" type="'pending' | 'granted' | 'denied'" required>
  `granted` creates the anonymous ID and session, restores a saved identity, and starts collecting from this moment on. With `trackPageviews: true`, the SDK records the current page. If aggregate collection was active, it sends the queued aggregate batch and starts full collection without recounting that page. The next recorded pageview starts the consented web session. Earlier aggregate pageviews stay unlinked.

  `denied` stops the flush timer and navigation tracking, discards queued events without sending them, and removes the anonymous ID, session, and identity from browser storage. Later analytics calls are dropped while the state remains `denied`.

  `pending` discards the current queue and leaves browser storage untouched. With `trackPageviews: 'auto'`, the SDK collects aggregate pageviews without reading or writing identifiers. Otherwise it stops collection. Custom events and `identify()` calls are dropped while pending.
</ParamField>

## Returns

`void`

## Examples

### From a banner

```typescript theme={null}
allowButton.addEventListener('click', () => {
  localStorage.setItem('analytics-consent', 'granted')
  Wendung.setConsent('granted')
  Wendung.identify(currentUser.id)
})

declineButton.addEventListener('click', () => {
  localStorage.setItem('analytics-consent', 'denied')
  Wendung.setConsent('denied')
})
```

### From a settings toggle

```typescript theme={null}
toggle.addEventListener('change', () => {
  Wendung.setConsent(toggle.checked ? 'granted' : 'denied')
})
```

<Note>
  The SDK does not persist the state. Store it yourself and pass it back through the `consent` option of [`init()`](/api-reference/init) on the next page load.
</Note>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.