---
title: Sending custom vars - Web
description: Send custom vars from your web page
lastUpdated: 12 December 2025
source_url:
  html: https://docs.contentsquare.com/en/web/sending-custom-vars/
  md: https://docs.contentsquare.com/en/web/sending-custom-vars/index.md
---

## General principles

Note

Custom vars are sent when a pageview event is triggered. There is no command to send them specifically.

### Use

**Custom vars** are additional information on the page, the user or the session, sent along with pageviews.

They generally include datalayer information, such as:

* Page type,
* Product category,
* If the user is signed in or not,
* The number of items in the cart

This information enables visitor segmentation or page grouping, for which the URL would not be enough.

### Limits

Each custom var is composed of a key (max. 512 characters) and value (max. 255 characters).

You are limited to 20 custom vars per project. You can update up to 20 cvars on the same page.

Each custom var holds a unique index, strictly between 1 and 20. Custom vars with indexes outside this range are **not sent**. Indexes are available for users to select within Contentsquare.

Use a consistent index for a given custom var within a project — for instance, if the "page template" is collected with an index of 3, use the slot 3 for this information on every page of the website.

Saving a custom variable creates a URI-encoded cookie which contains a stringified JSON of the stored information. This string may contain all URI [allowed characters ↗](https://en.wikipedia.org/wiki/Percent-encoding).

Warning

Make sure there is no security limitation on your server which blocks site entry with URI-encoded cookies, or any regex test that could target Contentsquare cookies.

## Defining custom vars

[Tag Configurator Template: Custom Variable ](https://support.contentsquare.com/hc/en-us/articles/37271895488401-CSTC-Template-Custom-Variable)Use the Tag Configurator to implement custom variables through a visual interface.

To define a custom var, use the `setCustomVariable` command:

```html
<script type="text/javascript">
  window._uxa = window._uxa || [];
  window._uxa.push(["setCustomVariable", index, name, value, scope]);
</script>
```

This means that you have to add an array to the `_uxa` object, containing:

* `index` is a integer > 0 and <= 20

* `name` is a string of 512 characters max (if longer the Tag will truncate it)

* `value` is a string of 255 characters max (if longer the Tag will truncate it)

* `scope` (optional) defines the custom var scope and behavior

  * No `scope` specified (**default**):
    * In scopes `visit` and `page`.

  * `2` or `visit`:
    * In scope `visit`.

  * `3` or `page`:

    * In scope `page`.
    * Deleted after a Natural pageview.

  * `4` or `nextPageOnly`:

    * In scope `nextPageOnly`.
    * Deleted after a Natural pageview, or an Artificial pageview with the next `trackPageview` command.

Once defined, custom vars are sent automatically with the next pageview (natural or artificial).

Defining a custom var with an index that already exists overrides its name and value.

### Examples

Defining a custom var in scope `visit` at index `5` with name `cname` and value `cvalue`.

```html
<script type="text/javascript">
  window._uxa.push(["setCustomVariable", 5, "cname", "cvalue", 2]);
</script>
```

Defining a custom var in scopes `visit` and `page` at index `6` with name `cname` and value `cvalue`.

```html
<script type="text/javascript">
  window._uxa.push(["setCustomVariable", 6, "cname", "cvalue"]);
</script>
```

Defining a custom var with the scope `nextPageOnly`.

```html
<script type="text/javascript">
  // either
  window._uxa.push(["setCustomVariable", 6, "cname", "cvalue", 4]);
  // or
  window._uxa.push(["setCustomVariable", 6, "cname", "cvalue", "nextPageOnly"]);
</script>
```

### Delete custom var command

* A custom var can be deleted by calling the command with an empty string value. The index parameter must match the custom var to delete.
* Custom vars with scope `nextPageOnly` are automatically deleted when the next natural or artificial page view is sent.

#### Examples

Deleting the custom var of name `cname`.

```html
<script type="text/javascript">
  window._uxa.push(["setCustomVariable", 5, "cname", ""]);
</script>
```

Deleting custom var of name `cname` from scope `visit`.

```html
<script type="text/javascript">
  window._uxa.push(["setCustomVariable", 6, "cname", "", 2]);
</script>
```

Deleting custom var of name `cname` from both scopes `page` and `visit` with an empty `scope` value.

```html
<script type="text/javascript">
  window._uxa.push(["setCustomVariable", 6, "cname", ""]);
</script>
```

## Verifying the sending of custom vars

To verify that **custom vars** have been sent, check the **`cvarp` parameter of the corresponding pageview**.

[Learn more about pageviews](https://docs.contentsquare.com/en/web/sending-pageviews/)
