# JS Variable criterion

JS variable is a triggering criterion that enables defining a [segment](/assets-library/creating-and-managing-segments.md).

To learn how to create a segment, please refer to this [article](/web-experimentation-and-personalization/targeting-step/how-to-create-a-segment-who-section.md).

## 📖 Definition <a href="#h_01hhpygwdzt9fhcmk07n3wtz6n" id="h_01hhpygwdzt9fhcmk07n3wtz6n"></a>

The weather criterion enables you to verify a specific JS variable of your choice.

## 🔎 How does it work? <a href="#h_01hhpyw4abkqmjd1yk9a78xfk5" id="h_01hhpyw4abkqmjd1yk9a78xfk5"></a>

Our tag is doing <kbd>`window.variableName`</kbd> to search for a specific variable like anyone could do through the browser console.

## ⚙️ Configuration <a href="#h_01hhpygwdz33kbshnj8m6kc4rn" id="h_01hhpygwdz33kbshnj8m6kc4rn"></a>

You will need first to configure the right operator ABTasty will have to look after. Only two are available on that use case: `is` and `is not`.

Once you have made your choice, you can declare the variable, AB Tasty will have to look for when parsing the DOM of the page. It has to **strictly respect the naming convention** that you used to be able to securely detect it.

Then, you have to choose from a second operator list. Depending on the type of data your JS is manipulating, you can either choose:

* **`equals`**
* **`contains`**
* **`is regular expression`**
* **`lower than` (strictly)**
* **`higher than` (strictly)**
* **`is declared`**

<figure><img src="/files/4fdfKH4dvJeiNmEVpUXh" alt="" width="563"><figcaption></figcaption></figure>

To finalize your configuration, you will need to declare the right variable value you are expecting to have to fire the campaign.

The JS variable criteria allows you to mix up different variables with both a `some` and `all` calculation approach, giving you a wide range of possibilities to create highly personalized triggers.

As your variable could be used and transformed through your visitor navigation, three options are offered to check this trigger at the right moment:

* **`When the page loads`**: means our tag will not be able to check new declared values between two pages visited.
* **`Every {X} ms until the conditions are met`**: meaning our tag will operate a regular check to detect any changes on that specific variable if the condition is not met at tag execution.
* **`According to a custom JS event`**: you can find everything in[ our developer documentation ](https://developers.abtasty.com/docs/tag/tag-javascript-events#targeting-check-or-recheck-)about the custom event that allows you to restart the targeting verification.

## 💡 Use case <a href="#h_01hhpygwdzjzx1fv7jaam165c0" id="h_01hhpygwdzjzx1fv7jaam165c0"></a>

<figure><img src="/files/WUj0eD6p8gW5oDIhYDVe" alt=""><figcaption></figcaption></figure>

Let’s imagine that you set up a boolean `productInteraction` variable in your code base to know if a specific visitor has already interacted with one of your products (for example size, a shipping verification, or anything that could grow your business).

In AB Tasty, you can then create a trigger based on that JS variable, and use it in one of your campaigns to wait for one of these interactions to trigger it.

**Need additional information?**

Submit your request at <product.feedback@abtasty.com>

Always happy to help!

<img src="/files/NgQcDfVEsMIj8oNgifgp" alt="" width="146">


---

# 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.abtasty.com/assets-library/creating-and-managing-triggers/list-of-trigger-criteria/js-variable-criterion.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.
