# Cookies and storage

By default, the Didomi CMP uses first-party cookies to store consent information. Consent is stored in the base domain and shared across all the subdomains of the base domain where the SDK is deployed.

**Example:** If you install Didomi on `www.domain.com`, consents will be stored in a cookie on `.domain.com` and all sub-domains of `domain.com` will have access to the same consent information.

## Store consent on a different domain (subdomain)

If you want to store the first-party cookie on a specific sub-domain, you can add this option into the configuration.

Consents will be shared only to pages with this specific sub-domain.

```javascript
window.didomiConfig = {
  cookies: {
    local: {
      customDomain: 'privacy.your-domain.com'
    }
  }
};
```

## Cookie name

The Didomi SDK uses up to three cookies and local storage items for storing user consent:

* `didomi_token` for vendors and purposes in the token format (JSON format)
* `didomi_dcs` for vendors and purposes stored in the Didomi Consent String format (binary encoded)
* `euconsent-v2` for IAB TCF vendors and purposes (only for the GDPR regulation)

The name of the `didomi_token` , `didomi_dcs` and `euconsent-v2` cookies can be modified if you want to use a different name by setting the `cookies` property:

```javascript
window.didomiConfig = {
  cookies: {
    didomiTokenCookieName: 'custom_cookie_name', // didomi_token custom name
    iabCookieName: 'custom_iab_cookie_name', // euconsent-v2 custom name
    didomiConsentStringCookieName: 'custom_dcs_cookie_name' // didomi_dcs custom name
  }
};
```

Keep in mind that modifying the cookie name on a website that already had the Didomi SDK installed will re-collect consent. We recommend using a short cookie name.

## **Enabling Collection of Consent for Different Pages**

There may be a case where some pages on your website(s) do not belong to the same legal entity, but you want to collect consent on different pages, for example, displaying multiple notices on the website, with different vendors configuration, and local regulations, and save them "locally" and not at the domain level.

If you would like to separate consent between different sub-domains or pages inside the domain you can use custom cookie names to store the user consent status in different cookies / storage items.

In this case, you must define a different name for both `didomiTokenCookieName` and `iabCookieName` by setting the `didomiConfig.cookies` property inside the given page as it is described in the previous sections and have the Web SDK loaded for this page.

Please have a look at the [Didomi Sandbox for Collecting Consent on Different Pages](https://sandbox.didomi.io/page-consent/index.html) to see how it works.

## Storage sources for user information

By default, the Web SDK stores user information and choices in both cookies and local storage. You can configure where user information and choices should be stored and use only cookies or local storage if you want to.

Set `cookies.storageSources.cookies` to `false` to disable storing data in cookies.\
Similarly, set `cookies.storageSources.localStorage` to `false` to disable storing data in local storage.

For instance, to configure the Web SDK to use local storage only:

```javascript
window.didomiConfig = {
  cookies: {
    storageSources: {
      cookies: false,
      localStorage: true
    }
  }
};
```
