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.

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

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

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

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

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

Last updated

Was this helpful?