How it works

Follow these 10 simple steps to start auto-tagging products based on SKU patterns

Shopify logo icon

Product Created

App connector: Shopify • Time to complete: 0 minutes (Auto-configured)
Why this matters: Without this trigger watching for new products, the workflow never fires and your tagging rules sit idle, meaning new inventory arrives in your store without any organizational structure.

This trigger monitors your Shopify store and activates whenever you create a new product. It captures the complete product data including all variants and their SKUs, which get passed to the pattern-matching steps. The trigger fires immediately after you save a new product in Shopify, processing tags before you even navigate away from the product page. No configuration needed—this works automatically once you activate the workflow.

Tags Mapping To SKU Patterns

App connector: Transform • Time to complete: 2 minutes
Why this matters: This is where you define your entire tagging strategy—without accurate pattern rules here, products either get tagged incorrectly or not at all, defeating the purpose of automation.

This mapping step defines the relationship between SKU patterns and product tags. You create rows where the "Destination" field contains the tag name you want to apply, and the "Source" field contains the SKU pattern to match. For example, mapping "Panda" to "PANDA-" means any SKU starting with "PANDA-" gets the "Panda" tag. The mapping supports partial matches, so "TOWEL" catches "BEACH-TOWEL-001" and "HAND-TOWEL-SM" equally well.

Add one row for each tag you want to automate. Common examples include brand prefixes (NIKE-, ADIDAS-), product categories (SHIRT, PANT, SHOE), or seasonal codes (SS24, FW24). The pattern matching is case-sensitive, so "PANDA-" and "panda-" are treated as different patterns.

Create array of patterns to loop over

App connector: Code • Time to complete: 0 minutes (Auto-configured)
Why this matters: The workflow needs to check every pattern against every variant, and without converting your mapping into a loopable format, it could only check one pattern total instead of all your rules.

This custom code transforms your tag-to-pattern mapping into an array structure that the loop steps can iterate through. It takes each row from your mapping and creates an object containing both the tag name and its pattern, then bundles all these objects into a single array. This conversion happens automatically and requires no input from you—the code simply reformats data so the next steps can process it efficiently.

const Mesa = require('vendor/Mesa.js');

module.exports = new class {
  script = (payload, context) => {
    const vars = context.steps;

    // Create an array of tags and patterns
    let array = [];
    for (let tag in vars.transform) {
      array.push({
        "tag": tag,
        "pattern": vars.transform[tag]
      });
    }

    Mesa.output.next({"array": array});
  }
}

This code loops through your mapping and builds an array that subsequent steps can iterate through to test each pattern.

Loop over variants

App connector: Loop • Time to complete: 0 minutes (Auto-configured)
Why this matters: Products often have multiple variants (sizes, colors, materials), and each variant has its own SKU that might match different patterns, so this loop ensures every variant gets checked individually rather than just the first one.

This loop processes each product variant separately by iterating through the variants array from the trigger. If your new product is a t-shirt with small, medium, and large sizes, this creates three separate processes—one for each size. Each variant's data (especially its SKU) gets passed to the pattern-checking steps. Products with only one variant still go through this loop once, maintaining consistency in how the workflow processes all products.

Loop over patterns

App connector: Loop • Time to complete: 0 minutes (Auto-configured)
Why this matters: This nested loop is what allows one variant to receive multiple tags—without it, each variant would only be checked against one pattern and you'd miss important categorization like a product being both "Organic" and "Cotton."

This second loop runs inside the variant loop and checks each variant against every pattern rule you defined. For each variant, it iterates through the array created in step 3, testing one pattern at a time. If you have 10 pattern rules and a product with 3 variants, this creates 30 individual pattern-checking processes. This nested approach ensures comprehensive tagging where a single product can match multiple patterns and receive all applicable tags.

Check regex match of pattern and sku

App connector: Code • Time to complete: 0 minutes (Auto-configured)
Why this matters: This is the actual intelligence of the workflow—it determines whether a variant's SKU matches the current pattern being tested, and if this logic fails, products either get over-tagged with irrelevant tags or miss tags they should receive.

This custom code uses regular expressions to compare the variant's SKU against the current pattern. It takes the pattern from the loop and tests whether the SKU starts with or contains that pattern. The code returns a match indicator (1 for match, 0 for no match) that the next filter uses to decide whether to continue. If a variant doesn't have a SKU assigned, the code throws an error with instructions to add one, preventing the workflow from proceeding with incomplete data.

const Mesa = require('vendor/Mesa.js');

module.exports = new class {
  script = (payload, context) => {
    const vars = context.steps;

    let pattern = vars.loop_2.pattern;
    let tag = vars.loop_2.tag;

    // Check regex match of pattern and tag
    let regex = new RegExp(`${pattern}.*`, 'g');
    if (vars && vars.loop && vars.loop.sku) {
      let match = vars.loop.sku.match(regex);
      Mesa.log.info("match", match);

      let isMatch = (match !== null);    
      Mesa.trigger.setTaskExternalData({
        label: "SKU " + vars.loop.sku + " matches pattern " + pattern + ": " + isMatch,
      });  

      Mesa.output.next({"is_match": isMatch});
    } else {
      throw new Error(`No product variant SKU found. Please add a SKU for product variant ${vars.loop.title}. Then replay this task.`);
    }
  }
}

The regex pattern uses .* which means "followed by anything," so "PANDA-" matches "PANDA-001," "PANDA-BAMBOO," or any other SKU starting with that prefix.

Filter: If it matches

App connector: Filter • Time to complete: 0 minutes (Auto-configured)
Why this matters: This filter prevents the workflow from trying to tag products that don't match the current pattern, which would waste API calls and potentially cause errors trying to add irrelevant tags.

This filter checks the match indicator from the previous step and only allows the workflow to continue if it equals 1 (meaning a match was found). When the SKU doesn't match the current pattern, this filter stops processing for this pattern and moves to the next one in the loop. This gate-keeping prevents unnecessary API calls and ensures only relevant tags get applied to products.

Retrieve Product

App connector: Shopify • Time to complete: 0 minutes (Auto-configured)
Why this matters: The workflow needs to check the product's current tags before adding new ones, and the trigger data might not include the most up-to-date tag list if someone manually edited tags while this workflow was running.

This step fetches the complete, current product data from Shopify to get the latest tag list. Even though the trigger provided initial product data, this retrieval ensures accuracy by grabbing real-time information directly from your store. The step specifically targets the product using its ID and returns all fields, but the workflow primarily uses the tags field to check what tags already exist.

Filter: Check for tag

App connector: Filter • Time to complete: 0 minutes (Auto-configured)
Why this matters: Adding duplicate tags creates messy product data and can cause issues with collection rules or app integrations that expect clean, unique tag lists.

This filter checks whether the matching tag already exists on the product by examining the tags string from the retrieve step. If the product already has "Panda" as a tag, this filter stops the workflow from adding it again. Only products missing the tag pass through this filter to the add tag step. This prevents duplicate tags from accumulating each time you edit and re-save a product.

Shopify logo icon

Product Add Tag

App connector: Shopify • Time to complete: 0 minutes (Auto-configured)
Why this matters: This is where the actual tagging happens—all the previous logic was just determining whether to reach this point, and without this action, products would remain untagged despite matching your patterns.

This step adds the matched tag to the product in Shopify. It takes the tag name from the current loop iteration and appends it to the product's existing tags without removing any tags that were already there. The action completes immediately and the tag appears on the product in your Shopify admin. After this step, the workflow returns to the pattern loop to check if any remaining patterns also match this variant.

Make it your own

Customize this workflow even further:

Add multiple pattern variations for one tag
Create several mapping rows that all point to the same tag, like mapping both "ORGANIC-" and "ORG-" to the "Organic" tag, catching products regardless of which SKU naming convention was used.
Trigger on product updates instead of creates
Change the trigger to "Product Updated" so the workflow re-evaluates tags whenever you modify product details or SKUs, keeping your tagging current even when you reorganize your SKU structure.
Send notifications for unmatched products
Add a Filter step after the loops that checks if any tags were added, then use Email or Slack to alert you about products that didn't match any patterns, highlighting potential SKU naming issues.
Create collections based on new tags
Extend this workflow by adding steps that check for newly added tags and automatically assign products to matching collections, fully automating your catalog organization from SKU to storefront.

Frequently asked questions

What happens if a product's SKU matches multiple patterns?
The product receives all matching tags. For example, if you have patterns for "ORGANIC-" → "Organic" and "COTTON-" → "Cotton," a product with SKU "ORGANIC-COTTON-SHIRT-001" gets both the "Organic" and "Cotton" tags applied automatically.
Can I use this for existing products or only new ones?
This template triggers on product creation only, so it tags new products as they're added. To tag existing products, change the trigger to "Product Updated" and make a minor edit to each product (like updating the description), which will trigger the workflow to evaluate and tag based on current SKU patterns.
What if my SKU doesn't have a consistent prefix pattern?
The pattern matching looks for your specified text anywhere in the SKU, not just at the beginning. So a pattern of "TOWEL" will match "BEACH-TOWEL-001," "TOWEL-HAND-SM," or "COTTON-TOWEL-WHITE." Just ensure your pattern text is unique enough to avoid false matches.
What is a template?
Templates are pre-made workflows by our team of experts. Instead of building a workflow from scratch, these have all the steps needed to complete the task.
Can I personalize a template?
Yes! Every step can be customized to meet your exact requirements. Additionally, you can even add more steps and make it more sophisticated.
Are templates free?
Yes! Our entire library containing hundreds of templates are free to use and customize to your exact needs.

Ready to start auto-tagging products based on SKU patterns?

Join thousands who've automated their work and saved an average of 3.5 hours every week.

Start with this template — It's free
7-day free trial • 11 min setup • Cancel anytime