# Variables

Variables define the **dynamic values** that can be used inside your triggers. While tags define what action happens and triggers define when it happens, variables provide the **data** those actions depend on (e.g., page URL, click text, user attributes).

By using variables, you can make your triggers more flexible and context-aware. For example, instead of hardcoding a page path, you can use a variable to capture the actual page URL at runtime.

{% hint style="info" %}

### Variable Lifecycle

1. **Definition** – A variable is created with a name and type.
2. **Reference** – Tags and triggers call the variable when evaluating conditions or firing actions.
3. **Resolution** – When the condition is met, the system resolves the variable to its current value (e.g., current URL, clicked element ID, user email).
   {% endhint %}

### Step 1: Open the Variables Tab

From your **Workspace**, select **Variables** in the left-hand menu.

You will see a list of existing variables with the following details:

* **Name** – the variable’s identifier.
* **Type** – the data source (e.g., URL, Data Layer Variable, Custom JavaScript).
* **References** – the triggers or tags where this variable is being used.
* **Last Edited** – when the variable was last modified.
* **Actions** – view, edit, or delete the variable.

<figure><img src="https://1642824329-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX6uilbEAw42gqsudlclY%2Fuploads%2FB40PPsTnx8BsrYOgtii1%2FScreenshot%202025-09-23%20at%2013.20.50.png?alt=media&#x26;token=d1197420-11d6-43ea-ac92-829dabac9b02" alt=""><figcaption></figcaption></figure>

### Step 2: Create a New Variable

1. Click **Create Variable**.
2. Enter a **Name** for your variable (choose something descriptive, like *Page URL* or *User Email*).
3. Select a **Type** from the dropdown menu. Options include:

**Utilities**:

* Constant – stores a fixed value.
* Date Time / Date Time Zone – captures the current time.
* Engagement – measures user time on site.
* Local DB – retrieves stored values from local storage.
* Browser – captures browser properties.
* Lookup Table – maps one value to another.
* Random Number – generates a random value.

**Page Variables**:

* 1st Party Cookie – retrieves cookie values.
* Data Layer Variable – pulls data from the data layer.
* Custom JavaScript – runs custom code.
* JavaScript Variable – references global JavaScript values.

**Page Elements**:

* DOM Element – captures attributes/text of an element on the page.

**Navigation**:

* URL – retrieves parts of the current page URL (full URL, path, query, etc.).

**Netmera Specifics**:

* Netmera User – retrieves user attributes managed by Netmera.

<figure><img src="https://1642824329-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX6uilbEAw42gqsudlclY%2Fuploads%2F5roPEqtIhQzSKPjikfmt%2FScreenshot%202025-09-23%20at%2013.21.23.png?alt=media&#x26;token=e857cb7a-d6b7-47e1-a8f7-00eaaf99598c" alt=""><figcaption></figcaption></figure>

### Step 3: Save and Reference the Variable

1. Click **Save** to create the variable.
2. Go to **Triggers** or **Tags** and use this variable in conditions or actions.
   * Example: Use the **Page Path** variable with the condition *contains /checkout* to fire a purchase event.
   * Example: Use the **Click Text** variable to fire a trigger only when a button with label *Subscribe* is clicked.

### Using Variables in Triggers

Variables can be applied to **filters** inside triggers, making conditions more dynamic. Instead of setting a fixed value, you can use variables (like Page URL, Click ID, or Event Name) to evaluate the trigger at runtime.

#### Example: Page Path Variable in a Trigger

In this example, the trigger is set up as follows:

* **Type:** Page View
* **Filter:** Page Path → contains → `/checkout`

This means the trigger will only fire **when the user views a page whose path contains `/checkout`**.

<figure><img src="https://1642824329-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX6uilbEAw42gqsudlclY%2Fuploads%2FQufyfbnY9BINHJFEwpxF%2FScreenshot%202025-09-23%20at%2014.20.35.png?alt=media&#x26;token=52eab92d-eda0-4dfe-83a9-bd336f34ed95" alt=""><figcaption></figcaption></figure>

### How to Import a Built-in Variable

Sometimes, instead of creating a variable from scratch, you can import a predefined **built-in variable**. These cover common use cases such as capturing API responses, referencing Netmera user attributes, or adding debugging utilities.

#### Step 1: Open the Variables Tab

From your **Workspace**, select **Variables** in the left-hand menu.

Click **Import Built-in Variable**. This opens a selection panel.

#### Step 2: Select Built-in Variable Type

In the import panel, you can choose from the following categories:

**API**

* Response Body – captures the body of an API response.
* API URL – captures the full API endpoint.
* Referrer URL – retrieves the referring page.
* API Path – captures the API path segment.
* Response Status – retrieves the HTTP response code.
* Request Body – captures the content of the API request.

**Netmera Specifics**

* Netmera User Tags – retrieves user tags from Netmera.
* Netmera User Segments – retrieves the segment(s) the user belongs to.
* Netmera User External ID – retrieves the user’s external identifier.
* Netmera User Gender – retrieves gender from the user profile.

**Utilities**

* Log Message – useful for debugging by printing values during Preview mode.

#### Step 3: Confirm Selection

Check the boxes for the built-in variables you want to import.

Click **Save and Continue**. The selected variables will now appear in your **Variables list** with their type and references.

<figure><img src="https://1642824329-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX6uilbEAw42gqsudlclY%2Fuploads%2F2myZunQFDyGH4WyPooW8%2FScreenshot%202025-09-23%20at%2013.23.43.png?alt=media&#x26;token=2cf96b09-e60f-4617-8bd4-fbc61521b943" alt=""><figcaption></figcaption></figure>
