# Setting up cookie consent

> How to add the AI Sales Agent to your cookie banner and connect your consent tool, step by step.

URL: https://help.yasan.ai/en/cookie-consent-setup/
Updated: 2026-11-20

Until a visitor accepts analytics cookies, the chat widget only sends anonymous, non-identifying statistics. Once the widget knows the visitor's choice, conversation analytics work for visitors who consented.

## Step 1: Add the widget to your cookie banner

The chat widget uses cookie-like storage for **essential functionality** (running the chat and keeping the conversation context — these require no consent) and, once consent is granted, for **conversation analytics**.

**1. Open your cookie banner settings**

Sign in to the tool you manage cookie consent with (Cookiebot, CookieYes, OneTrust, your platform's cookie banner…).

**2. Keep the widget script always loading**

Do not put the chat widget script among the scripts your tool blocks until consent — it must always load, otherwise the chat will not appear at all. Without consent the widget sends no analytics; step 2 shows how it learns the visitor's choice.

**3. List the widget in your cookie information**

In your cookie banner's text, list the Yasan chat widget under analytics (statistics) cookies so visitors know what they are consenting to. This is information for visitors — it is not tied to script blocking.

## Step 2: Connect your consent tool

### Cookiebot, CookieYes and OneTrust: no code needed

The chat widget reads the visitor's choice from Cookiebot, CookieYes and OneTrust by itself, on any store platform. It reads the choice each time it loads and whenever the visitor changes it, so it also picks up a choice made or withdrawn on a page where the widget had not loaded yet.

- Until the visitor decides, the widget sends no analytics.
- Where your tool gives consent without asking, for example in a region you set up without a banner, the widget follows what your tool allows there.
- The tool's statistics (analytics) category turns on conversation analytics; its marketing (advertisement) category is passed on as marketing consent.

**OneTrust:** the widget reads OneTrust's default category IDs, `C0002` for analytics and `C0004` for marketing. Check yours in your OneTrust admin under **Categorizations → Categories**. If yours are different or you added categories of your own, connect OneTrust as described in the next section. Your own code then takes precedence: once your page calls `setConsent`, the widget stops reading the cookie tools for the rest of that page.

**CookieYes WordPress plugin:** connect it to your CookieYes account. CookieYes documents that without that connection the plugin sends no consent events, so Yasan may miss the visitor's choice and later changes to it.

If you added a consent snippet for one of these tools earlier, you can remove it — it is no longer needed. Keep it for a OneTrust with category IDs of its own, which still needs it.

### Your own cookie bar or another tool

Pass the visitor's current choice to the widget as soon as it is ready, and again whenever the visitor makes or changes their choice, with `true` for accepted categories and `false` for declined ones. Put what your page tells the widget in one function and run it once the widget is ready:

```js
function myConsentSetup() {
  const analytics = getMyAnalyticsConsent();
  const marketing = getMyMarketingConsent();

  window.Yasan?.setConsent({
    analytics: analytics, // boolean
    marketing: marketing // boolean
  });
}

if (window.Yasan?.isReady) {
  myConsentSetup();
} else {
  window.addEventListener('yasan-ready', myConsentSetup, { once: true });
}
```

In your cookie bar's change handler, pass the new choice:

```js
const analytics = getMyAnalyticsConsent();
const marketing = getMyMarketingConsent();

window.Yasan?.setConsent({
  analytics: analytics, // boolean
  marketing: marketing // boolean
});
```

`getMyAnalyticsConsent()` and `getMyMarketingConsent()` stand for your own code that reads from your cookie bar whether the visitor allowed analytics and marketing cookies: `true` when allowed, `false` when declined.

Put this code in the page itself, in an inline script or a regular `<script>` tag. The widget starts only once the page's HTML has been parsed, so such code is in time and the choice applies before the widget records anything. Code that can run later, such as a `defer` or `async` script, a `load` handler or a tag from a tag manager, still passes the choice, but the widget may already have counted the page view with the choice stored on an earlier visit.

This works however the widget is installed. The [JavaScript API for developers](/developers/javascript-api/#the-visitors-cookie-choice) describes `yasan-ready` and `setConsent` in full.

The widget remembers the choice in the visitor's browser, so the call can run on every page load — repeated calls simply store the same value again. If the visitor revokes analytics consent, the widget also deletes its stored visitor identifier and any stored cart snapshot used only for analytics. Existing installs that call `window.Whisper` keep working unchanged.

## WordPress and WooCommerce

On a WordPress store, Cookiebot, CookieYes, OneTrust and Complianz need no code either.

**Another cookie plugin:** install the free [WP Consent API](https://wordpress.org/plugins/wp-consent-api/) plugin. In WordPress, go to **Plugins → Add Plugin**, search for **WP Consent API**, then click **Install Now** and **Activate**. It has no settings. Most cookie plugins, such as GDPR Cookie Compliance, then pass the visitor's choice to Yasan by themselves, and you need no code.

Only if your cookie plugin does not work with the WP Consent API, or for your own cookie bar, add the code from the previous section with a free code plugin. You don't need to edit your theme.

**Not sure which cookie tool you use?** In WordPress, open **Plugins** and look for CookieYes, Cookiebot, Complianz or another cookie plugin. Yasan also checks your store's homepage for Cookiebot, CookieYes, OneTrust and Complianz, but it can't see a store that's still in "Coming soon" mode.

**1. Install WPCode**

Go to **Plugins → Add Plugin**, search for **WPCode**, then click **Install Now** and **Activate**. WPCode adds code to every page of your store.

**2. Add a JavaScript snippet**

Open **Code Snippets → Add Snippet** and choose **Add Your Custom Code (New Snippet)**. Set **Code Type** to **JavaScript Snippet**.

**3. Paste your code**

Paste your code from the previous section into the code field: `myConsentSetup`, your `getMyAnalyticsConsent()` and `getMyMarketingConsent()`, and the call in your cookie bar's change handler.

**4. Load it on every page**

Under **Insertion**, keep **Auto Insert** and set **Location** to **Site Wide Header**. The site-wide header puts the code in the page itself, so it is in time.

**5. Save and activate**

Switch the snippet to **Active** and click **Save Snippet**.

**CookieYes: where the banner text goes.** In WordPress, open **CookieYes → Languages**, edit each language and add the text about the chat widget to **Cookie Notice → Message**. Then click **Publish Changes**.

## Where to find this in the app

The same instructions are part of the GDPR section. In the AI Sales Agent settings, open **GDPR**: the **Your cookie bar** step shows which tool we found on your website, **Cookie texts** has the text for your cookie bar, and **Technical setup** has the code for your own cookie bar. After the setup is finished, they are on the same page under **Show the texts and the code again**.

With advanced statistics on and the cookies declaration given, the GDPR page also checks that your cookie bar is connected. The check needs the Yasan script on your store, because the widgets report the visitor's choice. It shows **Waiting for your cookie bar** until a visitor's cookie choice reaches Yasan, then **Your cookie bar is connected**. To trigger the check yourself, open your store in an incognito window and accept or reject cookies.

![The cookie texts and the code in the GDPR section](https://help.yasan.ai/help/cookie-consent-setup/cookie-consent-settings.en.png)

*The texts and the code in the GDPR section, after the setup is finished*

## Not working?

- **The chat widget does not appear at all** — your consent tool is probably blocking the widget script. Allow it in the tool's settings; without consent the widget sends no analytics anyway.
- **Conversation analytics stay empty with Cookiebot, CookieYes or OneTrust** — check that the visitor accepted the statistics (analytics) category, and for OneTrust that your category IDs are the defaults (see above).
- **Conversation analytics stay empty with your own cookie bar** — check that `setConsent` is called when consent is granted and that `myConsentSetup` runs on every page (see above).

More solutions are in [Common issues](https://help.yasan.ai/en/common-issues/).

## Related Articles
- [Installing the AI Sales Agent](https://help.yasan.ai/en/installing-the-chat-widget/)
- [What to put on your website: GDPR and terms](https://help.yasan.ai/en/gdpr-and-terms/)