- [Case Studies](https://www.mergado.com/category/case-studies)
- [eCommerce tips](https://www.mergado.com/category/ecommerce-tips)
- [Online Store Solutions and Platforms](https://www.mergado.com/category/online-store-solutions-and-platforms)
- [Mergado Pack](https://www.mergado.com/category/mergado-pack)
- [Mergado tips](https://www.mergado.com/category/mergado-tips)
- [Mergado News](https://www.mergado.com/category/mergado-news)
- [eCommerce News](https://www.mergado.com/category/ecommerce-news)
- [How to use Mergado](https://www.mergado.com/category/how-to-use-mergado)
- [Interviews with e‑commerce gurus](https://www.mergado.com/category/interviews-e-commerce-gurus)
- [Extensions](https://www.mergado.com/category/apps-bidding-image-marketing-and-more)
- [Expansion with Mergado](https://www.mergado.com/category/expansion-with-mergado)
- [Mergado Lifestyle](https://www.mergado.com/category/mergado-lifestyle)
 



 

 1. [  Home  ](https://www.mergado.com/)
2. [     Mergado Blog  ](https://www.mergado.com/blog)
3. [     How to use Mergado  ](https://www.mergado.com/category/how-to-use-mergado)
4. <a class="flex items-center gap-2 hover:underline" href="" itemid="" itemprop="item" itemscope="" itemtype="https://schema.org/Thing">    **Create custom macro in Mergado** </a>
 
  

 

#  **Create custom macro in Mergado** 

 

 

 [    ![](https://www.mergado.com/sites/default/files/perm/user-avatar/23021961102131189073595481259913287n.jpg)   Lukáš Horák  ](https://www.mergado.com/blog/lukas-horak) [How to use Mergado](https://www.mergado.com/category/how-to-use-mergado) 

8. 4. 2020

3 minutes read

 

 

 

 

 

  ![Create custom macro in Mergado](https://www.mergado.com/sites/default/files/field/image/vytvoreni-makra-eng.png)  

We have recently presented the option of [creating custom macros](https://www.mergado.com/custom-macros). Therefore, we will show you how to create such a macro. By learning how to add and set up macros, you can **automate many tasks in Mergado**.



 

 

 
                function tableOfContents() {
                  return {
                    headings_menu: [],
                    heading_active: '', // Added to track the active section
                    shouldBeSticky: false,

                    generateToC() {
                      const headings = document.querySelectorAll('.js-article-full-headings h2, .js-article-full-headings h3');
                      let headingMap = {};

                      headings.forEach((heading) => { // Use an arrow function to maintain `this` context
                        // Normalize heading text to remove diacritics, then replace non-alphanumeric characters with dashes
                        var normalizedText = heading.textContent.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); // Remove diacritics
                        var id = heading.id ? heading.id : normalizedText.trim().toLowerCase()
                          .split(' ').join('-').replace(/[^a-z0-9\-]/ig, ''); // Updated regex to replace non-alphanumeric characters
                        headingMap[id] = headingMap[id] !== undefined ? ++headingMap[id] : 0;

                        // Use the updated `id` with diacritics removed for the heading id and the TOC
                        const finalId = headingMap[id] ? `${id}-${headingMap[id]}` : id;
                        this.headings_menu.push({
                          id: finalId,
                          title: heading.textContent,
                          level: heading.tagName.toLowerCase(), // Track heading level
                          active: false, // Initially set active to false
                        });
                        heading.id = finalId;
                      });
                    },

                    checkStickyNeeded() {
                      const ul = this.$el.querySelector('ul');
                      if (ul) {
                        this.shouldBeSticky = ul.scrollHeight < window.innerHeight;
                      }
                    },

                    setActiveHeading() {
                      // disabled not working with active state on click
                      // add @scroll.window="setActiveHeading()" to the parent div

                      // const headings = document.querySelectorAll('.js-article-full-headings h2');
                      // let activeHeading = '';
                      // let closestHeadingDistance = Infinity;

                      // headings.forEach((heading) => {
                      //   const rect = heading.getBoundingClientRect();
                      //   const offset = rect.top - window.innerHeight / 2; // Consider heading in the middle of the screen as active

                      //   if (offset < 0 && Math.abs(offset) < closestHeadingDistance) {
                      //     activeHeading = heading.id;
                      //     closestHeadingDistance = Math.abs(offset);
                      //   }
                      // });

                      // // Update the active state in headings_menu
                      // if (activeHeading !== this.heading_active) {
                      //   this.headings_menu = this.headings_menu.map(item => ({
                      //     ...item,
                      //     active: item.id === activeHeading,
                      //   }));
                      //   this.heading_active = activeHeading;

                      // }
                    },

                    setActiveItem(clickedId) {
                      this.headings_menu.forEach(item => {
                        item.active = (item.id === clickedId);
                      });
                      this.heading_active = clickedId; // Optionally update the heading_active property if used
                    },
                  };
                }
               1. <a :class="{ 'border-r-[3px] border-secondary': item.active, 'text-sm': item.level === 'h3' }" :href="'#' + item.id" class="inline-block text-balance hover:underline p-0.5 pr-3">  — </a>
  



 

We have recently presented the option of [creating custom macros](https://www.mergado.com/custom-macros). Therefore, we will show you how to create such a macro. By learning how to add and set up macros, you can **automate many tasks in Mergado**.

## How to create a macro in Mergado

From the main Mergado page, go to the *Custom* *Macros* page and select **+ Create New**.



 

 [  ![](https://www.mergado.com/sites/default/files/perm/paragraph-image/creting-custom-macro-in-mergado-1.png)  ](https://www.mergado.com/sites/default/files/perm/paragraph-image/creting-custom-macro-in-mergado-1.png) 

### **Task:**

Let’s create a two-step macro for **Google DSA export** that hides cheap products and fills the CUSTOM LABEL element with **availability information and product manufacturers**.

This macro will be helpful for exports used in Google Ads for [DSA campaigns](https://www.mergado.com/dsa-campaigns).

### Instructions



 

- ### Step 1: Hide cheap products
    
      
    
     
    
     We can **define** parameters in a macro that can be customized to a particular export before it is run. In our case we define **two** **parameters**:
    
    
    - price [element](https://www.mergado.com/tag/elements)
    - element with the amount from which we consider the product as cheap
    
    Before running the macro, we can either **change or individually set both**.
    
    ![](/sites/default/files/users/creting-custom-macro-in-mergado-2.png)
    
    ##### *How to add parameters.*
    
    Now let’s add **two actions:**
    
    **1. Choose cheap products:**
    
    1\. Click *Add* *action* and choose *Create* *a query*.
    
    ![](/sites/default/files/users/creating-custom-macro-in-mergado-3.png)
    
    2\. When writing the query condition, use the previously defined macro **parameters** and write it as follows:
    
    ![](/sites/default/files/users/creating-custom-macro-in-mergado-4.png)
    
    **Note:** As soon as we enter the % sign for the condition, we will activate the **autocomplete**, and we just select a particular value.
    
    3\. **Name** and save the query.
    
    **2. Hide the selected query with a hiding rule:**
    
    1\. Click on *Add* *action* and select *Create* *rule*
    
    ![](/sites/default/files/users/creating-custom-macro-in-mergado-5.png)
    
    2\. Choose the *Hide* *product* [rule](https://www.mergado.com/tag/rules-in-mergado), **name** it, select a query of cheap products created by us, and save:
    
    ![](/sites/default/files/users/creating-custom-macro-in-mergado-6.png)
 
 

 

- ### Step 2: Fill CUSTOM LABEL
    
      
    
     
    
     We will return to the macro parameter table and **add** one more: the CUSTOM LABEL element.
    
    ![](/sites/default/files/users/creating-custom-macro-in-mergado-7.png)
    
    ##### *Adding a custom label element.*
    
    We add it so we can then **use** it in the rewriting rule (still within the macro).
    
    In addition to the macro parameters, we add two more: **the** **availability information and the product manufacturer**, which we will also use in the rewriting rule in the field for the new value.
    
    ![](/sites/default/files/users/creating-custom-macro-in-mergado-8.png)
    
    ##### *Adding parameters with availability information and product manufacturer.*
    
    Now we **create a rewriting rule:**
    
    1\. Click on *Add* *action* and select *Create* *rule*.
    
    2\. Choose the *Overwrite* rule, **name** it, set the query on **all** **products** (here we could create a different query in advance if appropriate), **select** the query of cheap products and in the field for the new value **insert** the variables from our parameters, more precisely, get the following variables (after entering the character %) by autocomplete:
    
    ![](/sites/default/files/users/creating-custom-macro-in-mergado-9.png)
    
    3\. This is **how it will look**:
    
    ![](/sites/default/files/users/creating-custom-macro-in-mergado-10.png)
    
    4\. **Save** the rule.
 
 

 

- ### Conclusion: Saving the macro
    
      
    
     
    
     Now we just **name** the whole macro, fill in the **description**, and **save** it.
    
    ![](/sites/default/files/users/creating-custom-macro-in-mergado-11.png)
    
    ##### *Adding a macro name and description.*
 
 

 

- ### Running a macro
    
      
    
     
    
     **1.** First, go to a **particular export**, specifically the Macros page:
    
    ![](/sites/default/files/users/creating-custom-macro-in-mergado-12.png)
    
    ##### Overview of available macros in a particular export.
    
    **2.** Then click through to the macro **detail**, check or modify the parameters and finally **run** the macro.
    
    ![](/sites/default/files/users/creating-custom-macro-in-mergado-13.png)
    
    ##### *Preview of the created macro before the final run.*
 
 

 

Although there are quite a few steps to create a new macro, the procedure is not difficult at all. Go through our tutorial — in a minute, you will learn how to create macros **like a pro**. Do you have **questions** regarding macros? Ask them in our [forum](https://forum.mergado.com/t/macros-in-mergado/266).

### **You could be interested in:**



 

 [    ![](https://www.mergado.com/sites/default/files/perm/image/ai_boost-1.jpg)  

### MASTER PROMPT TEMPLATE FOR ECOMMERCE

 

 ](https://www.mergado.com/blog/master-prompt-eshopy-b2c) 

 [    ![](https://www.mergado.com/sites/default/files/perm/image/uawc_cs_en.jpg)  

### How Feed Optimization Unlocked Meta Ads Performance without Increasing Ad Spend

 

 ](https://www.mergado.com/blog/feed-optimization-for-meta-ads) 

 [    ![](https://www.mergado.com/sites/default/files/perm/image/how_to_sell_successfully_on_idealo.jpg)  

### How to Sell Successfully on idealo

 

 ](https://www.mergado.com/blog/successful-sale-on-idealo) 

 

 

 [    ![](https://www.mergado.com/sites/default/files/perm/user-avatar/23021961102131189073595481259913287n.jpg)  ](https://www.mergado.com/blog/lukas-horak)###  [ Lukáš Horák ](https://www.mergado.com/blog/lukas-horak) 

Lukáš takes care of most of the Czech and English communication in Mergado. Through blogs, e‑mail, and social networks, he regularly supplies readers with e‑commerce news and news and tips from Mergado. In his time off, he enjoys simple things like badminton, digging the hidden gems of the 80’s, and seafood served with red wine.

 

 

 

 

 

 

 

 

 

## What you *might be interested in next*

 

 [    ![](https://www.mergado.com/sites/default/files/perm/image/shoptet-shopify-prevod-en.jpg)  

### How We Migrated an E‑Shop from Shoptet to Shopify with Mergado: A Complete Migration Without Data Loss

 

 ](https://www.mergado.com/blog/how-we-migrated-e-shop-shoptet-shopify-mergado-complete-migration-without-data-loss) 

 [    ![how to open large xml file article cover](https://www.mergado.com/sites/default/files/perm/image/mergado-nahledovky_na_blog-landscape-1200_x_628_px-5.png)  

### How to open large XML file

 

 ](https://www.mergado.com/blog/how-to-open-large-xml-file) 

 [    ![smart value insertion article](https://www.mergado.com/sites/default/files/perm/image/smart_insertion_value.png)  

### Introducing smart value insertion. It will speed up the creation of bulk rules

 

 ](https://www.mergado.com/blog/smart-value-insertion) 

 

 

 

## Don’t miss *anything*

 Sign up for our newsletter 

   

       

   By logging in, you agree that we will process your data by the [terms of personal data protection](https://www.mergado.com/cookies). 

  Thank you, you have successfully joined our subscriber's list. 

 

 

 
      function ml_webform_success_5807248() {
        var r = ml_jQuery || jQuery
        r('.ml-subscribe-form-5807248 .row-success').show(), r('.ml-subscribe-form-5807248 .row-form').hide()
      }