Variables in Mergado#

I. Variables in Mergado Editor#

1. What are variables in Mergado#

Variables in Mergado Editor represent placeholders for specific values from elements. They are “holders” for data that differs from product to product and that you want to further process or use in rules.

  • A variable can have a different value for each product.
  • A typical example is the element PRICE_VAT, whose value changes across products.
  • You can create a variable manually – for example, if you need to extract part of the text from a name or description.
  • In addition to user variables, there are also special system variables, such as @MERGADO_ID.

Mergado works directly with elements as the source of values. Variables are a supplementary tool for situations where you need to extract only a specific part of a text or further process values.

2. How variables work#

Variables are used for text extraction and subsequent use, primarily in rules. The basic principle is simple:

  1. The user selects an element that contains the desired information.
  2. They enter a regular expression that selects a specific part of the text from that element.
  3. This part is saved as the variable’s value.
  4. The variable is then used in a rule – Mergado inserts the correct value for each product individually.
  5. For system variables (e.g. @MERGADO_ID), the same approach applies – in rules, they are used wrapped in percent signs: %@MERGADO_ID%.

Variables allow you to work even with data that is not well structured in the feed.

3. Why and when to use variables#

Variables are suitable wherever you need to work with part of a text, create new values, or fill in missing information.

A. Setting values in rules#

Variables are often used to add or modify element values. Using regular expressions, you can extract just part of the text and save it as a variable, which you then insert into another element.

B. Assembling and modifying data#

Variables allow you to combine values from multiple sources into a single result. A typical use case is assembling a product name from a combination of several elements and variables (e.g. manufacturer, type, size).

C. Extracting data into PARAM elements#

If products do not contain parameters in the PARAM element, but properties are listed in the name or description, you can use a regular expression to extract them into variables and then save them as standardized parameters. This approach is universal – it works regardless of what specific values appear in the text.

D. Using the system variable @MERGADO_ID#

@MERGADO_ID is a unique product identifier that Mergado uses for internal identification. Users can leverage it especially in situations where:

  • ITEM_ID or g:id values are missing or duplicated,
  • a unique URL needs to be created by adding #@MERGADO_ID,
  • images cached by comparison shopping engines need to be refreshed.

The @MERGADO_ID value can be written to any element using an Rewrite rule.

Section summary#

Variables in Mergado are used for extracting and further processing values from elements. The user selects an element, defines a regular expression to extract the desired part of the text, and saves it as a variable. This variable can then be used in rules, when assembling names, creating parameters, or modifying URLs. Variables are suitable wherever you need to work with variable or unstructured text and convert it into a unified format.


II. Types of variables in Mergado#

1. User variables#

User variables represent values extracted from elements that can differ from product to product. They are most commonly used in situations where you need to extract only a specific part of the text from a name or description.

Creating user variables#

User variables are managed on the Variables page using the New variable button. The process is as follows:

  • you select the element from which the variable should be derived,
  • you enter a regular expression that specifies the part of the text to capture,
  • you verify in the test field that the expression works correctly,
  • you save the captured text under the chosen variable name.
  • using a single regular expression, you can create multiple variables at once
    • if you use parentheses in the regular expression, each set of parentheses is evaluated as a separate group, and each group can be saved as a separate variable
    • typically, for example, when an image URL element contains multiple URLs separated by commas and you need to extract each URL into a separate variable

Example#

In a Google feed, the product description in the element g:description contains product dimensions, for example “150x50”, where the first value represents width and the second length: <g:description>Product description, dimensions: 150x50</g:description>

The goal is to extract these values and save them into two separate parameters: Width and Length.

A. Creating the variables#

  1. On the Variables page, click New variable.
  2. In the Element field, select the element g:description from the list.
  3. In the Regular expression field, enter an expression that captures both dimensions: (\d+)x(\d+)
  4. The Test text field will display a random value from the selected element, so you can immediately see whether the expression works. Using the arrow icons, you can load additional samples.
  5. If the regular expression captures any part of the text, a section with fields for entering variable names will appear below. If the expression has multiple groups, a separate field is displayed for each one.

In our case, the following fields will appear:

  • Full match: “150x50”
    • You can ignore this field or save it as a variable, for example dimensions, if you need the whole string.
  • Group 1: “150” Name it width.
  • Group 2: “50”
    • Name it length.
  1. Click Save. This gives you two new variables: width and length.

B. Setting parameters using a rule#

  1. On the Rules page, create a new rule of the Set product parameters type.
  2. In the first column, select the product query for which you want to set the parameters.
  3. Enter:

First parameter:

  • Parameter name: Width
  • Parameter value: %width%

Second parameter:

  • Parameter name: Length
  • Parameter value: %length%
  1. Save the rule, apply it, and then regenerate the project.

C. Result in the output feed#

<g:description>Product description, dimensions: 150x50</g:description> <g:attribute_detail> <g:attribute_name>Width</g:attribute_name> <g:attribute_value>150</g:attribute_value> </g:attribute_detail> <g:attribute_detail> <g:attribute_name>Length</g:attribute_name> <g:attribute_value>50</g:attribute_value> </g:attribute_detail>

Primary purpose#

User variables are used primarily for:

  • extracting a specific part of text from elements with longer or unstructured content,
  • extracting values such as size, color, volume, technical parameters, or other product properties,
  • adding or creating parameters in the PARAM element,
  • populating other elements using rules, such as Set product parameters or Overwrite.

This approach is universal – it works for any color variants, sizes, or other values that may appear in the feed.

2. System variables#

System variables form a special set of variables that are built into Mergado. Users do not create them manually.

Fixed set#

On the Variables page, you will find a Special variables table listing all available system variables. Currently, there is a single system variable: @MERGADO_ID

What @MERGADO_ID means and how it works#

  • @MERGADO_ID is an internal unique product ID.
  • It is a numeric value that is unique for each product.
  • In rules, it is used wrapped in percent signs: %@MERGADO_ID%.

Typical uses of @MERGADO_ID#

  • as a replacement for missing or duplicate values in the ITEM_ID or g:id elements,
  • for creating unique URLs by adding #@MERGADO_ID,
  • for “refreshing” images – changing image URLs by appending #@MERGADO_ID triggers re-fetching by comparison shopping engines,
  • for writing into any element using an Overwrite rule.

3. Using elements as variables#

In Mergado, you can directly use element values in rules without needing to create a custom variable. Simply enter the element name wrapped in percent signs, for example:

  • %PRODUCTNAME%
  • %MANUFACTURER%
  • %DESCRIPTION%

This way, you can work with the complete content of an element. This mechanism functionally resembles a variable, but you do not need to create one separately.

When an element is sufficient#

Using an element in a rule is sufficient when:

  • you want to use the entire element value,
  • you are not extracting part of the text,
  • you are working with clear and well-structured content.

When to create a user variable#

It is appropriate to create a user variable when:

  • you need to extract only a specific part of the text (e.g. “XL” from a long name),
  • you are working with a description that contains various values mixed in a single text,
  • you do not want to create dozens of queries or rules for each specific color, size, or other variant,
  • you need a universal solution that will work even when new values are added to the feed.

In these cases, a regular expression allows you to create a variable that extracts exactly the information you need.


III. Working with variables in Mergado#

A. Managing variables#

Variables are managed on the Variables page in the main menu of Mergado Editor. This page serves as a central overview of all variables in the project:

  • User variables – variables created by the user.
  • Special variables – system variables listed in the Special variables table.
  • Creating new variables – done by clicking New variable.

Variable management also includes the ability to edit or delete a variable.

B. Creating user variables – workflow#

The process for creating a new user variable:

  1. Click the “New variable” button on the Variables page.

  2. Select the source element from which the variable should be created.

  3. Enter a regular expression (mask) that specifies the part of the text to extract.

  4. Test the expression:

    • The Test text field displays a random value from the selected element.
    • The test text can be refreshed using the double arrow icon.
    • Click Test expression.
  5. Adjust and test until the correct text selection is found.

    • For working with regular expressions, you can also use the external tool regex101.com.
  6. Save the variable – name the captured text parts and confirm by clicking Save variable.

This process allows you to efficiently extract specific information from any text in an element and then use it in rules.

C. Using variables in rules#

Variables are used primarily in rules, where they serve as a source of values for writing into other elements.

Syntax#

  • A variable is written in a rule as %VARIABLE_NAME%.
  • The same syntax applies to the system variable: %@MERGADO_ID%.
  • The value of an entire element can be used directly, for example:
    • %PRODUCTNAME%, %MANUFACTURER%, %DESCRIPTION%.
    • or as a combination of two: %URL% %@MERGADO_ID%

Typical usage#

1. Rewrite rule Used for assembling new values – for example, composing a product name from multiple sources: %MANUFACTURER% %PRODUCTNAME% %PARAM_SIZE%

2. Set product parameters rule Used for populating the PARAM element. If the parameter value is stored in a variable, it is entered on the right side of the rule.

D. Using variables in queries (selections)#

Variables are not used directly in query syntax. However, queries often define the group of products to which a rule with a variable is then applied.

Example workflow:

  • you create a product query that contains a certain property in the name,
  • you apply a rule to this selection that uses a variable created with a regular expression.

Example#

Some product names contain sizes that you need to extract and save as a new “Size” parameter. Sample product name: “Adidas t-shirt ABC, color red, size XL”

  1. Creating a variable - Create a variable from the source element (e.g. g:title). Using a regular expression, capture the part of the text representing the product size, i.e. “XL”. Save the variable under a name, for example product_size.
  2. Creating a product query - Create a selection of products that contain a size in the name. You can use, for example, a condition like: g:title CONTAINS "size" (depending on the actual structure of your product names).
  3. Creating a rule – two possible approaches

Approach A: Rewrite rule

Use this when you want to manually assemble the parameter structure using elements.

  • in the Element field, enter: g:attribute_detail { g:attribute_name = "Size" } | g:attribute_value (if the “Size” parameter does not yet exist, Mergado will create it automatically)
  • in the New value field, enter: %product_size%

Approach B: Set product parameters rule

Use this when you want to create the parameter simply using a form.

  • in the Parameter name field, enter: Size
  • in the Parameter value field, enter: %product_size%

This way, the extracted size is saved as a standardized parameter that can be further used in export formats or rules.

E. Displaying and exporting variables#

Displaying values#

  • System variable @MERGADO_ID:
    • The values of the system variable @MERGADO_ID can be displayed on the Products page.
    • In the table view, you can add a column with @MERGADO_ID values using the Mergado icon.
  • User variables
    • User variable values can only be displayed after inserting the variable into an element using a rule.
    • Element values created from a variable can be checked either on the Products page or in the Elements -> Element values -> List element values section.

Export to CSV#

  • Just like viewing, exporting variable values is only possible as values of the element into which the variable was inserted using a rule, or if it is the system variable @MERGADO_ID:

    • On the Products page, switch to the table view, select the correct element, and click Download CSV.
    • Select the option Columns from table – this will also download the variable values that were displayed in the table.

IV. Use cases and common mistakes#

1. Typical use cases#

a) Adding product parameters#

Values listed in the name or description (e.g. size, color, volume, material) can be extracted into a user variable using a regular expression. The values obtained this way are then written into the PARAM element using the Set product parameters rule.

b) Creating a new product name#

To modify or unify product names, you can assemble new element content from multiple variables and elements. A typical example of use in an Overwrite rule:

%MANUFACTURER% %PRODUCTNAME% %size%

where MANUFACTURER and PRODUCTNAME are standard elements and size is a user variable. The result is a structured and consistent product name.

c) Removing extracted data from the name#

If parameters were extracted from the name and moved to PARAM, you may need to remove them from the original product name. This is done using a Find & Replace rule with a regular expression.

This approach is common, for example, with formats that require a clean name without sizes or colors.

d) Using @MERGADO_ID as a unique key#

@MERGADO_ID is used primarily for:

  • replacing missing or duplicate identifiers (ITEM_ID, g:id),
  • creating unique URLs (e.g. by appending #@MERGADO_ID to the end of the address),
  • forcing images to be re-fetched by comparison shopping engines.

This system variable is written into elements using an Overwrite rule.

2. Common mistakes and how to fix them#

Variable returns empty values#

  • The regular expression does not match the actual text.
  • Solution: adjust the expression and test it on multiple cases in Mergado or in regex101.com.

Expression captures too much text#

  • The regular expression is too broad.
  • Solution: make the pattern more specific, possibly using anchors, groups, or range limitations.

Selected element does not contain the required data#

  • The variable was created from the wrong element.
  • Solution: verify which element actually contains the information and adjust the variable accordingly.

Rule did not affect the data#

  • The rule may not have been applied, or it was applied to a different query.
  • Solution: check the rule application and verify the output in the Elements -> Element values -> List element values section.

Duplicate identifiers#

  • Some services require a unique identifier.
  • Solution: use %@MERGADO_ID% to overwrite or supplement the target element that contains duplicates.

FAQ#

What is a variable in Mergado?#

A variable is a stored value obtained from an element that you can use in rules and other data modifications.

What are variables used for?#

They are used for extracting values from elements, adding parameters, creating new values, or standardizing data.

What is the difference between an element and a variable?#

An element is the original value from the feed. A variable is a part of that value obtained using a regular expression.

When should I use a variable and when is an element sufficient?#

Use a variable when you need to extract and use part of the text. Use an element when you want to work with its entire value.

How is a variable created?#

A variable is created on the Variables page using the “New variable” button. You select the element that contains the needed data and enter a regular expression to target the part of the text to extract. You then test the expression on a sample value and adjust it as needed until it matches the desired result. Finally, you name the captured value and save it as a variable.

Do I need to create a variable for every element I want to work with?#

No. If you need to use the entire content of an element, you do not need to create a variable.

Can I create multiple variables at once?#

Yes. If the regular expression contains multiple groups (parentheses), each can be saved as a separate variable using a single form.

What is the system variable @MERGADO_ID?#

It is an internal unique product identifier that is automatically available.

What is @MERGADO_ID used for?#

For filling in missing or duplicate identifiers, creating unique URLs, forcing images to be re-fetched in the target system, etc.

How do I use a variable in a rule?#

You insert it in the format %VARIABLE_NAME%.

How do I insert @MERGADO_ID into a rule?#

You write it in the format %@MERGADO_ID%.

Can I use a variable in a query (selection)?#

No, variable syntax is not used in queries. A query only serves to define the products to which a rule with a variable will be applied.

Where do I manage variables?#

On the Variables page in the project’s main menu.

Can I edit or delete a variable later?#

Yes, you can make edits and deletions in the variables overview.

How do I know my regular expression works?#

Use the Test text in the variable creation dialog or test the expression on regex101.com.

What should I do if the variable returns empty values?#

Adjust the regular expression so that it matches the text structure in the element. You can also contact our technical support.

Why did my variable not appear in the result?#

Check that the rule was applied and that the variable matches the element content.

How do I check the variable’s value for a product?#

The simplest way is to view the product in the table view on the Products page and add a column with the relevant element or @MERGADO_ID. Element values created from a variable will only be visible after creating and applying a rule. You can also use the value listing in the Elements -> Element values -> List element values section. This tool shows the exact element content as it was written after rule application. This lets you easily verify whether the variable works as expected.

Can I export variable values to CSV?#

Yes, just use the Columns from table option when exporting CSV.

Why did the regular expression capture too much text?#

The expression is too broad. Restrict it with more specific groups or anchors.

How do I get extracted values into the product name?#

Create a variable, then insert it into an Rewrite rule as a combination of the name and the variable.

How do I remove an extracted value from the name?#

Use a Find and replace rule with an appropriate regular expression.

Can variables be used for working with URLs?#

Yes, you can also use variables for modifying URLs. A typical example is appending the value %@MERGADO_ID% to the end of a URL, creating a unique address (for example, for variant products or images). This approach is also used when you need to force comparison shopping engines to re-fetch images. In rules, URLs are assembled using the same syntax as other text values.

What if a product does not have a parameter in the PARAM element?#

Extract the value from the name or description using a variable and add it using the Set product parameters rule.

Do I need a separate regular expression for each property?#

No. A well-designed expression with groups can extract different properties separately (e.g. all sizes or colors).

Can a variable contain multiple values?#

No. A variable is a set of values that contains exactly one or no value for each product.

What should I do if I have duplicate values in ITEM_ID?#

If the feed is missing a unique identifier, you can replace it with the system variable @MERGADO_ID. Using an Rewrite rule, you set %@MERGADO_ID% into the ITEM_ID or g:id element, ensuring that each product gets a unique value. This approach is reliable and recommended for projects where identifiers are repeated, inconsistent, or contain invalid values. Changes take effect after applying the rules and subsequently updating the output feed.

Is using variables computationally expensive?#

No, variables are evaluated during rule application and have no negative impact on the normal operation of the project.

🇨🇿 🇬🇧 🇩🇪 🇭🇺