# Working with Variables in Variations

Created: 28.11.2023\
Updated: 28.11.2023\
Author: Alexander Sugakov

Any HTML, CSS, or JS code element can be assigned a variable in the Gravity Field platform. Variables play a crucial role in streamlining campaign customization, allowing business users to adjust campaigns without relying on developers. This functionality empowers users to replace text, images, colors, and other design elements directly within the platform's interface. The use of variables facilitates the rapid templating of campaign variations, providing a more dynamic and user-friendly customization experience. For more details about templates, refer to the article [working-with-templates](https://developer.gravityfield.ai/lang/en/platform-interface/working-with-templates "mention")

## Creating Variables

<figure><img src="https://3786223776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgMtBULwktLmojWzNHUD1%2Fuploads%2FEfdFL0ZNUlp7np2MYX0R%2Fimage.png?alt=media&#x26;token=49aee4de-4e6e-48f9-9742-120f94bb212e" alt="" width="375"><figcaption></figcaption></figure>

To create a variable, you need to select the desired element, right-click on it, and choose "Add Variable" from the context menu.

<figure><img src="https://3786223776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgMtBULwktLmojWzNHUD1%2Fuploads%2FV77MsguBO6oO7Lsj1bAK%2Fimage.png?alt=media&#x26;token=492e0eaf-88bb-45a5-a889-7ac1c6f8295b" alt=""><figcaption></figcaption></figure>

In a panel opened on the right, you need to provide a name for the variable, configure its type, and set the parameters. The parameters of variables depend on the selected type.

## Variable Types

For all variable types, you can configure the variable's name, type, and a tooltip that will be displayed in the popover when hovering over the variable.

In the Gravity Field platform, the following variable types and additional parameters are available (in addition to the basic ones):

| Variable Type                           | Available Parameters                                 | Campaign Type |
| --------------------------------------- | ---------------------------------------------------- | ------------- |
| Text                                    | Default Value                                        | Front / API   |
| Image                                   | Default Value                                        | Front / API   |
| Dropdown List                           | Values for the list in the format key-value          | Front / API   |
| Color Palette                           | —                                                    | Front / API   |
| Number                                  | Default Value, Maximum and Minimum value constraints | Front / API   |
| Recommendation Strategy                 | Default Value                                        | Front         |
| CSS Selector                            | Default Value                                        | Front         |
| Social Proof Data (Product Performance) | Default Value                                        | Front         |

## Working with Variables

When you hover the mouse cursor over a variable, icons on the right side of the field allow you to delete or reconfigure the variable, and a tooltip appears above the variable's value.

**Text** — a variable that allows you to enter arbitrary text.<br>

<figure><img src="https://3786223776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgMtBULwktLmojWzNHUD1%2Fuploads%2FO3OnaKL4skRhSQiTzDL6%2Fimage.png?alt=media&#x26;token=71d690ac-fa15-4b2f-8722-a9a2fbdc5bf8" alt="" width="375"><figcaption></figcaption></figure>

**Image** — a variable that allows you to upload an image (video) up to 6 megabytes. The following file formats are supported: `tiff, pjp, pjpeg, jfif, tif, gif, svg+xml, bmp, png, jpeg, svgz, jpg, webp, ico, mp4`

**Dropdown List** — a variable that allows you to choose one of the pre-configured values set when creating the variation.

<figure><img src="https://3786223776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgMtBULwktLmojWzNHUD1%2Fuploads%2FQBWsla4N8LUGWskVt2my%2Fimage.png?alt=media&#x26;token=d5e628aa-5c55-4676-bcdb-e73b688785e6" alt="" width="375"><figcaption></figcaption></figure>

**Color Palette** — a variable that allows you to choose a color from the palette or specify it in HEX or RGB formats. You can also select the color transparency level.

<figure><img src="https://3786223776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgMtBULwktLmojWzNHUD1%2Fuploads%2F1L9uGMtah3i9UELlsjCy%2Fimage.png?alt=media&#x26;token=dece3535-2219-4a8e-b4b5-cc31b8d053ed" alt="" width="375"><figcaption></figcaption></figure>

**Number** — a variable that allows you to enter any number. When configuring the variable, you can set the maximum and minimum allowable values.

<figure><img src="https://3786223776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgMtBULwktLmojWzNHUD1%2Fuploads%2F1kCMSxwKytNpuK7rA1Qk%2Fimage.png?alt=media&#x26;token=c77f2aa2-dd67-4f04-af2e-6e4609f872c0" alt="" width="375"><figcaption></figcaption></figure>

**Recommendation Strategy** — a variable that allows you to choose any of the recommendation strategies created in the section.

**CSS Selector** — a variable that allows you to enter an arbitrary CSS selector.

**Social Proof Data (Product Performance)** — a variable that returns Social Proof data for a product. The variable will only return data on the product page. It will provide information on sales or views of the product for the selected period. Available periods: day, two days, week, two weeks, month.

## Grouping Variables

Variables can be grouped for convenience. Variable groups can be collapsed and expanded in the interface. A new variable group is created by clicking the "+ Variables Group" button.

For a group, you can configure the name, color, and also check the variables that will be added to it.

<figure><img src="https://3786223776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgMtBULwktLmojWzNHUD1%2Fuploads%2FwFcUQwqxZ2c4uc3g4PoQ%2Fimage.png?alt=media&#x26;token=09a2e8d8-3c70-4830-983b-d67c4b2bf5fd" alt=""><figcaption></figcaption></figure>

Settings for the created group can be managed by clicking on the button with switches that appears when you hover over the group name.

<figure><img src="https://3786223776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgMtBULwktLmojWzNHUD1%2Fuploads%2F78WWj2aFaQ35XyChAOKq%2Fimage.png?alt=media&#x26;token=243e6170-f7c7-45d7-906f-ea17cc016cb1" alt="" width="375"><figcaption></figcaption></figure>
