# 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: 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/server-side-variables.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.
