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

# DC- (cookie data)

> Store your own key-value pairs in the encrypted design cookie, read them back, and use them to personalize the shop.

Some characteristics should accompany the visitor beyond the session: the customer group they once selected, or the product range they are interested in. For this, the shop creates its own cookie in which you can store any key-value pairs.

This so-called design cookie is encrypted and compressed. The visitor can neither read nor change what is in it.

Guide: Onsite personalization

> [!WARNING]
>
> Nothing is written without the visitor's consent. If there is no consent for the design cookie, `DC-CookieData_set()` has no effect, without any error message appearing. Therefore, build your template so that it also looks sensible without the stored characteristics.

## Writing and reading

| Tag | Effect |
| - | - |
| `DC-CookieData_set()` | stores a key-value pair |
| `DC-CookieData()` | checks whether there is a value for a key, and serves as a loop over all pairs |
| `DC-CookieData_get()` | outputs the value for a key |

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
~DC-CookieData_set(kundengruppe,katze)~
~DC-CookieData_set(favoriten,trockenfutter)~

{DC-CookieData(kundengruppe)}
   Ihre Kundengruppe: ~DC-CookieData_get(kundengruppe)~
{/DC-CookieData(kundengruppe)}

{!DC-CookieData(kundengruppe)}
   <a href="...">Sagen Sie uns, wofür Sie sich interessieren</a>
{/!DC-CookieData(kundengruppe)}
```

> [!NOTE]
>
> If the key already exists, `_set()` replaces the previous value. If it is new, it is added. A key can therefore never appear twice in the cookie.

> [!WARNING]
>
> Both arguments of `_set()` must be filled. An empty value does not delete the key, but makes the tag invalid. Upper and lower case of the keys do not matter: `Kundengruppe` and `kundengruppe` are the same entry.

## Iterating over all pairs

Without a parameter, `DC-CookieData()` is a loop tag over all stored pairs.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{@DC-CookieData()}
   ~DC-CookieData~ = ~DC-CookieData_get()~
{/@DC-CookieData()}
```

> [!NOTE]
>
> Within the loop, `~DC-CookieData~` outputs the key of the current entry and `~DC-CookieData_get()~` its value. This lets you list the entire content of the cookie, which is helpful during development.

Bracketing also works within the loop and then checks against the key of the current entry.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{@DC-CookieData()}
   {DC-CookieData(kundengruppe)}
      <!-- nur der Durchlauf, dessen Schlüssel "kundengruppe" heißt -->
   {/DC-CookieData(kundengruppe)}
{/@DC-CookieData()}
```

## Reusing a value

`DC-CookieData_get()` outputs, nothing more. If the value is to be used in a query or in another tag, provide it with `_touchKey()` and retrieve it via the two touched tags.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
~DC-CookieData_touchKey(kundengruppe)~
~DC-FP1_set($DC-CookieData_lastValueTouched$)~

{DC-FP1(katze)}
   <!-- Inhalte für Katzenhalter -->
{/DC-FP1(katze)}
```

| Tag | Returns |
| - | - |
| `DC-CookieData_touchKey()` | provides key and value, outputs nothing itself |
| `DC-CookieData_lastKeyTouched` | the provided key |
| `DC-CookieData_lastValueTouched` | the provided value |

Reference: DC- (free parameters and session parameters)

## Setting the cookie immediately

The shop only sends the changed cookie along with the next page. If the visitor leaves the shop directly after the page on which `_set()` appeared, nothing has been saved.

`DC-CookieData_cookieHasChanged` applies exactly when something in the cookie was changed on this page. Within it, you can additionally set the cookie in the browser.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{DC-CookieData_cookieHasChanged}
<script>
   document.cookie = "~DC-CookieData_cookieName~=\"~DC-CookieData_cookieValue~\"; path=/; max-age=31536000; SameSite=Lax; Secure";
</script>
{/DC-CookieData_cookieHasChanged}
```

| Tag | Returns |
| - | - |
| `DC-CookieData_cookieName` | the name of the design cookie, `ws_<Shop>_<Sprache>_design_cookie` |
| `DC-CookieData_cookieValue` | the encrypted content, and as a range tag the check whether there is any at all |

> [!NOTE]
>
> `DC-CookieData_cookieName` and `DC-CookieData_cookieValue` are not listed as separate tags in the previous documentation, but they exist in the shop and are already used in the example above.

> [!WARNING]
>
> The output value is the encrypted cookie content, not your plain-text data. Only the shop can decode it. Therefore, do not evaluate it in JavaScript.

## Limits

| Limit | Behavior |
| - | - |
| Length of the cookie content | above a certain size, the shop writes a warning to the log |
| Twice that length | the entire cookie content is discarded and a critical error is logged |

> [!WARNING]
>
> The second case affects not just the one entry that is too long, but the entire cookie: all previously stored characteristics are then gone. Therefore, store short keys and short values, for example abbreviations instead of full names, and do not store lists in the cookie.

> [!NOTE]
>
> The design cookie is intended for characteristics, not for data. Anything that should only apply within the session belongs in a session parameter `DC-SPX`, and anything that belongs to the customer account belongs in the customer data.

## Overview of the tags

| Tag | Single tag | Range tag | Negative range tag | Loop tag |
| - | - | - | - | - |
| `DC-CookieData()` | only in the loop | yes | yes | yes |
| `DC-CookieData_set()` | yes | – | – | – |
| `DC-CookieData_get()` | yes | – | – | – |
| `DC-CookieData_touchKey()` | yes | – | – | – |
| `DC-CookieData_lastKeyTouched` | yes | – | – | – |
| `DC-CookieData_lastValueTouched` | yes | – | – | – |
| `DC-CookieData_cookieHasChanged` | – | yes | yes | – |
| `DC-CookieData_cookieName` | yes | – | – | – |
| `DC-CookieData_cookieValue` | yes | yes | yes | – |

All tags are permitted in all templates.

## Related topics

* Guide: Onsite personalization
* Materials: Cookies used
* Reference: DC- (free parameters and session parameters)
* Reference: CHECK- (URL and cookie data)


## Related topics

- [CHECK- (URL and cookie data)](https://dokumentation.websale.de/en/v8s/referenz/tags/check.md)
- [Onsite personalization](https://dokumentation.websale.de/en/v8s/marketing-funktionen/onsite-personalisierung.md)
- [Materials: consent to data processing](https://dokumentation.websale.de/en/v8s/materialien/materialien-einwilligung-zur-datenverarbeitung.md)
- [DC- (comparisons and other tags)](https://dokumentation.websale.de/en/v8s/referenz/tags/dc/vergleiche.md)
- [Cookies used](https://dokumentation.websale.de/en/v8s/referenz/verwendete-cookies.md)


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