# 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.
