# setCookie

### `setCookie` Function

The `setCookie` function is used to **create or update a JavaScript cookie** in the browser. It also respects the **current consent situation** managed by JENTIS.

#### Consent Handling

Every variable in JENTIS is associated with a **tool**. This function checks whether at least one tool linked to the variable has valid consent. If so, the cookie is allowed to be set.

***

#### Function Signature

```ts
this.setCookie(config: {
  name: string;         // required
  value: string;        // required
  exdays: number | { m: number }; // required
  sameSite?: string;    // optional
}): void
```

#### Parameters

* **`name`** (`string`, required):\
  The name of the cookie.
* **`value`** (`string`, required):\
  The value to be stored in the cookie.
* **`exdays`** (`number | { m: number }`, required):\
  The expiration of the cookie. You can specify:
  * A number (e.g., `2`) for days
  * A JSON object (e.g., `{ m: 30 }`) for minutes, hours and seconds. (e.g., `{ h: 1, m: 15 }` )
* **`sameSite`** (`string`, optional):\
  Controls the SameSite cookie attribute (e.g., `"Lax"`, `"Strict"`, `"None"`).

***

#### Return Value

* **Type:** `void`\
  This function does not return a value.

***

#### Examples

**Example 1: Set a cookie with a 2-day expiration**

```js
function() {
  this.setCookie({
    name: "Cookie-Name",
    value: "Cookie-Value",
    exdays: 2
  });
  return "";
}
```

**Example 2: Set a cookie with a 30-minute expiration**

```js
function() {
  this.setCookie({
    name: "Cookie-Name",
    value: "Cookie-Value",
    exdays: { m: 30 }
  });
  return "";
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.jentis.com/developer-guide/variables/client-side-variables/public-function-scope/setcookie.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
