---
title: "Configure consent for tracking and personalization"
slug: "configure-consent-for-tracking-and-personalization"
abstract: "Apply visitor consent to Content SDK cookie creation, page-view tracking, and personalization in Next.js applications."
---

# Configure consent for tracking and personalization

Your application controls whether Content SDK creates visitor cookies and runs tracking or personalization features. Connect your consent-management solution to both the browser and server integrations so that they use the visitor’s consent choice.

Content SDK does not provide a cookie-consent UI or a direct integration with consent-management platforms. Use your preferred solution to collect consent and make the resulting state available to your application.

> [!important]
> Cookie configuration alone is not a complete consent implementation. You must also conditionally enable or disable the personalization middleware/proxy and page-view tracking through `CdpPageView`. `PersonalizeProxy` enables cookies internally. `CdpPageView` calls `pageView()`, which cookie flags do not disable.

> [!notice]
> **Before you begin**
> This topic covers Content SDK for Next.js 2.x and assumes that your application already initializes Content SDK and uses a consent-management solution.
>
> Your application must:
> 
> - Determine whether the visitor has granted the consent required for each feature.
> - Make consent state available before browser tracking starts.
> - Make consent state available to the server before personalization runs.
> - Handle changes to the visitor’s consent choice.

The examples use a single consent choice for analytics and personalization. Adapt the consent lookup to your application’s requirements. An absent or unreadable consent value doesn't mean consent is granted.

For plugin and adapter setup, see [Initializing tracking, events, and personalization in the Content SDK](https://doc.sitecore.com/sai/en/developers/content-sdk/20/initializing-tracking-events-and-personalization-in-the-content-sdk.html).

## Configure browser cookie creation

In your existing browser `initContentSdk()` call, pass the applicable consent state to:

- `analyticsPlugin.options.enableCookie` to control creation of `sc_cid`.
- `personalizeBrowserPlugin.options.enablePersonalizeCookie` to control browser creation of `sc_cid_personalize`.

Browser web personalization is optional and standard starters typically do not enable it. If your application uses it, also make `webPersonalization` conditional. This option loads the browser personalization script independently of the cookie flags, so disabling cookie creation alone doesn't prevent the script from loading.

The following example illustrates browser initialization when the browser is responsible for creating both cookies. It assumes that `cookieConsentGiven` comes from your application’s consent implementation:

```ts
await initContentSdk({
  config: {
    contextId: scConfig.api.edge.clientContextId,
    edgeUrl: scConfig.api.edge.edgeUrl,
    siteName: siteName || scConfig.defaultSite,
  },
  plugins: [
    analyticsPlugin({
      options: {
        enableCookie: cookieConsentGiven,
        cookieDomain: window.location.hostname.replace(/^www\./, ''),
      },
      adapter: analyticsBrowserAdapter(),
    }),
    eventsPlugin(),
    personalizeBrowserPlugin({
      options: {
        enablePersonalizeCookie: cookieConsentGiven,
        webPersonalization: cookieConsentGiven
          ? { async: true, defer: false }
          : false,
      },
      adapter: personalizeBrowserAdapter(),
    }),
  ],
});
```

Use a cookie domain appropriate for your deployment.

When these cookie options are `false`, the corresponding plugin initialization doesn't create the cookies. However, this doesn't delete cookies that already exist or automatically suppress every tracking or personalization call.

Creating `sc_cid_personalize` requires both `enableCookie` and `enablePersonalizeCookie` to be `true` in the relevant initialization.

> [!note]
> If your application uses both browser and server personalization plugins, configure only one side to create `sc_cid_personalize`. If the server creates it, keep the browser’s `enablePersonalizeCookie` set to `false`.

## Conditionally send page-view events

In starter applications, update the `disabled()` function in `src/components/content-sdk/CdpPageView.tsx` to check consent. Keep the existing development-mode check and any other conditions your application uses.

The following fragment assumes that `cookieConsentGiven` is available inside the component and reflects your application's current consent state:

```ts
const disabled = () => {
  return process.env.NODE_ENV === 'development' || !cookieConsentGiven;
};
```

`CdpPageView` checks `disabled()` before calling `pageView()`. It does not initialize cookies. Setting `enableCookie: false` in SDK initialization does not prevent this event API from sending requests.

Alternatively, conditionally render the component:

```tsx
{cookieConsentGiven && <CdpPageView />}
```

Apply consent checks to any additional tracking calls your application makes. Do not assume that the cookie options automatically block custom events or other direct SDK calls.

## Make consent available to the server

Server-side personalization runs before browser scripts execute. A consent value stored only in browser memory cannot control the initial server request.

Persist the consent state using an application-managed mechanism that the server can read, such as a consent cookie sent with incoming requests.

For example:

```typescript
const cookieConsentGiven =
  request.cookies.get('app_tracking_consent')?.value === 'granted';
```

`app_tracking_consent` is an example application cookie, not a Content SDK cookie. Replace it with your own consent lookup.

If you use a consent-management platform, interpret its stored consent values according to that platform’s format and your configured consent categories. Do not treat the presence of its cookie alone as proof that the required consent was granted.

## Conditionally run server-side personalization

### Applications using PersonalizeProxy

Skip `PersonalizeProxy` when the visitor has not granted the required consent. Add a consent check to its existing configuration:

```ts
const personalize = new PersonalizeProxy({
  ...scConfig.api.edge,
  ...scConfig.personalize,
  sites,
  skip: (request) =>
    request.cookies.get('app_tracking_consent')?.value !== 'granted',
});
```

Preserve any existing skip conditions by combining them with the consent check.

`PersonalizeProxy` enables cookies internally. Changing browser plugin options does not change this server-side configuration. Skipping the proxy prevents its personalization processing from running for that request.

### Applications initializing server plugins directly

If your application initializes server personalization itself, use server-readable consent state in both plugin configurations:

```ts
analyticsPlugin({
  adapter: analyticsAdapter,
  options: {
    enableCookie: cookieConsentGiven,
  },
}),
personalizeServerPlugin({
  adapter: personalizeAdapter,
  options: {
    enablePersonalizeCookie: cookieConsentGiven,
  },
}),
```

This fragment assumes that `analyticsAdapter` and `personalizeAdapter` are configured for your server environment.

Disabling these options prevents cookie creation through this initialization path. To prevent personalization processing, also use consent checks before executing personalization logic.

## Behavior when consent is absent

The behavior depends on applying consent consistently across the application:

| Application configuration | Result |
| --- | --- |
| `enableCookie` is `false` in the relevant plugin initialization. | That initialization does not create `sc_cid`. |
| `enablePersonalizeCookie` is `false` in the relevant plugin initialization. | That initialization does not create `sc_cid_personalize`. |
| The application's `CdpPageView.disabled()` returns `true`, or the application does not render the component. | That component does not send page-view events. |
| The application suppresses direct `pageView()` and other event calls. | Those calls do not send tracking requests. |
| The application skips `PersonalizeProxy`. | That proxy does not run server-side personalization. |
| Browser `webPersonalization` is `false`. | That plugin initialization does not load the web personalization script. |
| The application suppresses any direct `personalize()` calls. | Those calls do not request personalization decisions. |

When the application applies all applicable controls above, it does not send analytics/events or run personalization, and the visitor receives the default unpersonalized experience. This requires applying consent to every tracking and personalization integration in the application, not only setting the cookie flags to `false`.

These settings do not automatically remove existing cookies or guarantee that other application code sends no tracking requests. Review all tracking and personalization paths in your application.

## Handle changes to consent

When a visitor changes their consent choice, make the updated state available to both browser and server execution.

Your consent-change handling must account for:

- Whether `CdpPageView` can send page-view events.
- Whether subsequent server requests can run personalization.
- Cookie-creation options used by directly initialized plugins.
- Browser personalization script loading and direct tracking or personalization calls.

### Delete cookies when consent is withdrawn

When a visitor withdraws consent, stop the relevant tracking and personalization processing and delete these existing cookies:

- `sc_cid`
- `sc_cid_personalize`
- Legacy `sc_{contextId}` and `sc_{contextId}_personalize` cookies, if present. Replace `{contextId}` with the context ID used when those cookies were created.

Setting cookie options to `false` only prevents creation. It does not delete existing cookies, and adapters can still read cookies left in the browser or incoming request.

Content SDK does not provide a public cookie-deletion API. Use your application's cookie-handling code to expire the cookies, matching the Domain and Path and preserving the Secure and SameSite settings used when they were set. Do not use the internal SDK `deleteCookie` helper as a public API.
