> 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/public-function-scope/user-storage-per-tool-instance.md).

# User Storage

## `userStorage` API (Server-Side)

{% hint style="info" %}
The `this.storage` function is our deprecated method for accessing User-Storage! Internally, calls to `this.storage` are forwarded to `this.userStorage`. While it should no longer be used in new code, it remains fully functional for backward compatibility.
{% endhint %}

The `userStorage` API is the primary interface for **persisting data server-side per tool instance** for a specific user. It is commonly used to store **identifiers** such as:

* Client IDs (e.g., `client_id`)
* Click IDs (e.g., `gclid`, `fbclid`)
* Campaign parameters or session-level values

These functions are available within the **server-side variable runtime environment** under the `this` scope.

{% hint style="info" %}
Looking for a practical use case how to put your server side storage into use? See here: [Persist User Data for Google Ads Enhanced Conversions](/use-cases-and-tutorials/persist-user-data-for-google-ads-enhanced-conversions.md).
{% endhint %}

***

### Available Functions

#### 1. `this.userStorage.write(name, value, expirationTimestamp)`

Stores a value under a given key and defines when it should expire.

**Parameters**

| Placeholder              | Description                                               | Type                    | Required                                      | Example                 |
| ------------------------ | --------------------------------------------------------- | ----------------------- | --------------------------------------------- | ----------------------- |
| `<NAME>`                 | The key used to store and retrieve the value              | `string`                | <i class="fa-square-check">:square-check:</i> | `"client_id"`           |
| `<VALUE>`                | The value to be stored (can be any data type)             | `any`                   | <i class="fa-square-check">:square-check:</i> | `"123abcd123.11111111"` |
| `<EXPIRATION TIMESTAMP>` | Unix timestamp (in milliseconds) for automatic expiration | `number` (milliseconds) | <i class="fa-square-check">:square-check:</i> | `1740555149453`         |

**Example**

```js
async function() {
    const href = this.getFrontendVariable('window_location_href');
    const url = new URL(href);
    const gclid = url.searchParams.get("gclid");

    if (gclid) {
        const expirationTime = Date.now() + 7890000000;
        this.userStorage.write("gclid", gclid, expirationTime);
        return gclid;
    }

    return null;
}
```

***

#### 2. `this.userStorage.read(name)`

Reads a stored value from user storage based on the given key.

**Parameters**

| Placeholder | Description                             | Type     | Required                                      | Example   |
| ----------- | --------------------------------------- | -------- | --------------------------------------------- | --------- |
| `<NAME>`    | The key under which the value is stored | `string` | <i class="fa-square-check">:square-check:</i> | `"gclid"` |

**Example**

```js
async function() {
    const gclid = this.userStorage.read("gclid");
    return gclid || "";
}
```

***

#### 3. `this.userStorage.delete(name)`

Deletes a stored value from user storage by key.

**Parameters**

| Placeholder | Description                             | Type     | Required                                      | Example   |
| ----------- | --------------------------------------- | -------- | --------------------------------------------- | --------- |
| `<NAME>`    | The key under which the value is stored | `string` | <i class="fa-square-check">:square-check:</i> | `"gclid"` |

**Example**

```js
async function() {
    this.userStorage.delete("gclid");
    return "";
}
```

***

### Best Practices

* Always set a **realistic expiration** for stored values to prevent unnecessary data buildup.
* Combine client-side values with server-side logic for advanced tracking use cases.

***

### Summary

The `userStorage` API enables persistent, scoped storage for identifiers and session-related data inside server-side variables. It offers a simple but powerful interface to **write, read, and delete** values securely within the JENTIS TWIN-Browser runtime.

For additional guidance or complex implementations, please refer to the Server-Side Variable Guide or contact JENTIS Support.


---

# 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/public-function-scope/user-storage-per-tool-instance.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.
