> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: Manage Cookie Consent

## Article: Manage Cookie Consent

## Article Link: https://dev.wix.com/docs/go-headless/wix-managed-headless/full-integration-astro/feature-guides/manage-cookie-consent.md

## Article Content:

# Manage Cookie Consent

A [Wix-managed headless project](https://dev.wix.com/docs/go-headless/wix-managed-headless/about-wix-managed-headless.md) built with [Wix's Astro integration](https://dev.wix.com/docs/go-headless/wix-managed-headless/full-integration-astro/about-the-astro-integration.md) loads the same site analytics, tag manager, and consent-policy runtime scripts as a standard Wix site. This article explains the default consent behavior and how to override it in code before analytics or advertising scripts run.

To manage consent without code, we recommend the [Usercentrics for Wix](https://www.wix.com/app-market/cookiebot-for-wix) consent app from the App Market. If you use a different consent app, check that it works on your released site. Use only one consent solution, either a consent app or the steps in this article.

> **Note:** This applies to headless projects built with the Astro integration. Wix injects these scripts when it builds your project. On a self-managed project, the same consent scripts load when you [load site scripts](https://dev.wix.com/docs/go-headless/self-managed-headless/site-scripts/load-site-scripts-on-a-self-managed-project.md). The layout steps below are for the Astro integration.

## Default consent policy

On a newly created Wix-managed headless site, the default consent policy grants every category, `essential`, `functional`, `analytics`, `advertising`, and `dataToThirdParty`, until you configure a different site-level default or a visitor makes a choice.

This is an opt-out default. Analytics and tag manager scripts can run, and set a session cookie, before a visitor interacts with any consent UI. Some regions require opt-in consent before non-essential cookies run, such as under GDPR or Germany's TDDDG. If a site serves visitors there, set a restrictive policy before those scripts trigger, with a consent app or with the steps below.

If you already set a site-level default policy with the [Update Consent Policy API](https://dev.wix.com/docs/api-reference/business-management/site-properties/properties/update-consent-policy.md), the runtime uses that configured default instead of the all-granted policy shown above.

## The consent policy manager

The runtime exposes a `consentPolicyManager` object on `window`:

- `window.consentPolicyManager.getCurrentConsentPolicy()`: returns the active policy as `{ defaultPolicy, policy: { essential, functional, analytics, advertising, dataToThirdParty }, createdDate }`. `defaultPolicy` is `true` until a policy has been explicitly set for this visitor.
- `window.consentPolicyManager.setConsentPolicy(policy, successCallback, errorCallback)`: persists a policy for the current visitor. The runtime always forces `essential` to `true`. The callback parameters are optional. Setting a category changes only that category, and omitted categories keep their current value.

> **Note:** This is the same object documented as the [Consent Policy Manager](https://dev.wix.com/docs/sdk/host-modules/site/consent-policy-manager/introduction.md) API in the `@wix/site` package. It also exposes `resetConsentPolicy()` to revert to the site default and `onConsentPolicyChanged()` to react to later policy changes. Use `window.consentPolicyManager` directly only for the early inline script in the steps below, which must run before your bundle loads. Use the `@wix/site` import everywhere else.

## Consent requirements for page views

Wix Analytics records page views itself, and Wix also forwards page views to platforms you connect, such as Google Analytics and Facebook Pixel. The two depend on different consent categories:

- Wix Analytics records page views only when both `functional` and `analytics` are `true` for the current visitor. If `analytics` is `true` but `functional` is `false`, Wix Analytics records no page views. Events that you send with [`trackEvent()`](https://dev.wix.com/docs/go-headless/wix-managed-headless/full-integration-astro/feature-guides/track-analytics-events.md) follow the same rule when Wix Analytics records them.
- Wix forwards page views to connected platforms when `analytics` or `advertising` is `true`. Connected platforms' scripts also load only when `dataToThirdParty` is `true`, so if `dataToThirdParty` is `false`, connected platforms receive no page views.

## Step 1 | Write a helper that applies your policy

Call `setConsentPolicy()` with the categories you want to deny. Apply the policy only while `defaultPolicy` is `true`, so the helper doesn't overwrite a choice that the visitor or a consent banner already saved:

```javascript
function applyConsentPolicy() {
  if (!window.consentPolicyManager.getCurrentConsentPolicy().defaultPolicy) {
    return;
  }
  window.consentPolicyManager.setConsentPolicy({
    functional: false,
    analytics: false,
    advertising: false,
    dataToThirdParty: false,
  });
}
```

## Step 2 | Wait for the manager, don't poll for it

A script that Wix injects with `defer` sets up `consentPolicyManager`, so it isn't guaranteed to exist yet when your own script runs. For example, an inline script you add to your layout's `<head>` might run first. Rather than polling for it, check for it once and otherwise listen for the `consentPolicyManagerReady` event, which the runtime dispatches on `window` the moment the manager becomes available:

```javascript
if (window.consentPolicyManager) {
  applyConsentPolicy();
} else {
  window.addEventListener("consentPolicyManagerReady", applyConsentPolicy, { once: true });
}
```

## Step 3 | Add the helper to your layout's `<head>`

Add the helper from step 1 and the check from step 2 as an inline script in your layout, such as `src/layouts/Layout.astro`, so it runs before the visitor sees any content:

```astro
<head>
  <script is:inline>
    function applyConsentPolicy() {
      if (!window.consentPolicyManager.getCurrentConsentPolicy().defaultPolicy) {
        return;
      }
      window.consentPolicyManager.setConsentPolicy({
        functional: false,
        analytics: false,
        advertising: false,
        dataToThirdParty: false,
      });
    }
    if (window.consentPolicyManager) {
      applyConsentPolicy();
    } else {
      window.addEventListener("consentPolicyManagerReady", applyConsentPolicy, { once: true });
    }
  </script>
</head>
```

> **Note:** `setConsentPolicy()` only changes the policy stored for the current visitor going forward. It doesn't undo cookies already set by scripts that already ran. Run it as early as possible, before any tracking script has a chance to execute. `setConsentPolicy()` itself persists the policy through a network request rather than setting it synchronously, so on a slow connection it's possible for the runtime's very first tracking call on that same page load to still see the prior policy. The [`setConsentPolicy()` reference](https://dev.wix.com/docs/sdk/host-modules/site/consent-policy-manager/set-consent-policy.md) also notes that policy changes take effect only after the visitor refreshes the page. If a site needs certainty from the first pageview on, set a restrictive policy at the site level with the [Update Consent Policy API](https://dev.wix.com/docs/api-reference/business-management/site-properties/properties/update-consent-policy.md) instead of relying only on this early-script override.

If you add your own consent banner:

- When a visitor opts in to analytics, set both `functional` and `analytics` to `true`, so that Wix Analytics records page views. Tell visitors that the banner also sets the functional category.
- Don't use `defaultPolicy` to decide whether to show the banner. After the helper's first run, `defaultPolicy` is `false` even if the visitor hasn't chosen anything. Store the visitor's choice yourself, for example in local storage, and show the banner until the visitor makes a choice.

## See also

- [Track Analytics Events](https://dev.wix.com/docs/go-headless/wix-managed-headless/full-integration-astro/feature-guides/track-analytics-events.md)
- [Update Consent Policy API](https://dev.wix.com/docs/api-reference/business-management/site-properties/properties/update-consent-policy.md)
- [Post-Migration Checklist: Wix Studio and Editor Sites to Headless](https://dev.wix.com/docs/go-headless/wix-managed-headless/full-integration-astro/get-started/post-migration-checklist-wix-studio-and-editor-sites-to-headless.md)