> For the complete documentation index, see [llms.txt](https://docs.jentis.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.jentis.com/developer-guide/variables/server-side-variables.md).

# Server-Side Variables

## Introduction to Server-Side Variables

**Server-Side Variables** in JENTIS enable you to **create, read, update, and delete persistent information** stored in the **JENTIS Runtime Environment** on our proprietary **TWIN-Browser**.

These variables are designed for advanced use cases where data persistence, cross-request consistency, or enhanced data enrichment is required.

***

### What Are Server-Side Variables?

Unlike client-side variables that run in the user’s browser, **server-side variables execute within the TWIN-Browser**—a virtual browser environment hosted by JENTIS. This enables you to store and manage data across sessions, events, and user interactions in a secure, server-controlled context.

***

### Common Use Cases

Server-side variables are particularly useful for:

* **Storing identifiers**\
  e.g., `user-id`, `client-id`, session identifiers
* **Counting occurrences**\
  e.g., `hit-counter`, `session-counter`, custom goals
* **Persisting campaign parameters**\
  e.g., `gclid`, `fbclid`, or other marketing UTM tags

***

### Key Features

* **Persistent data storage**\
  Stored in JENTIS’ TWIN-Browser, across sessions and interactions.
* **Cross-variable interaction**\
  Server-side variables can **access values from client-side variables**.
* **Modern JavaScript support**\
  These variables run in a **Node.js** environment, so you're free to use **modern JavaScript (ES6+)** syntax and features.
* **Asynchronous execution**\
  Server-side variables **must be defined with the `async` keyword**, as operations like reading and writing storage are asynchronous.

***

### Example: Create, Read & Update a User ID

```js
async function() {
  let cid = this.userStorage.read("cid");

  if (cid === false || cid === null) {
    cid = Math.round(2147483647 * Math.random());
  }

  this.userStorage.write("cid", cid, Date.now() + 94608000000); // 3 years
  return cid;
}
```

In this example:

* A user ID (`cid`) is **read** from the persistent storage.
* If no value is found, a new one is **generated**.
* The ID is then **stored** with a future expiration (3 years).
* Finally, the value is **returned** for use in your tracking logic.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.jentis.com/developer-guide/variables/server-side-variables.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
