Tag Customer based on Collection Purchase

Topic summary

A user wants to automatically tag customers who purchase from specific collections, noting that products can belong to multiple collections. They’re seeking an automated solution rather than manual segmentation.

Proposed Solutions:

  • Flow with Run Code: One approach uses Shopify Flow’s “Run code” action triggered on order creation. The code queries all collections associated with purchased products, extracts collection titles (or metafield values), de-duplicates them, and applies them as customer tags. Complete code examples provided for input query, output schema, and JavaScript logic.

  • Simple Flow Condition: Another suggestion involves creating a Flow automation that checks if a collection title matches specific criteria when an order is created, then adds corresponding customer tags via conditional logic.

  • Clarification Question: One responder asked whether the goal is tagging based on collection page visits (requiring custom pixel tracking of customer journey URLs) versus tagging based on which collections the purchased products belong to.

The discussion remains open with multiple technical approaches offered, though the original poster hasn’t confirmed which solution fits their needs.

Summarized with AI on October 29. AI used: claude-sonnet-4-5-20250929.

Hey all,

I’m trying to find out how I can tag a customer once they have ordered from a certain collection? I have collections setup, with unique URLs wich I’m relying heavily on to filter certain customers to certain groups. I’d like the tag these customers once they have purchased from a collection. Also note that specific products and across multiple collections. I really would like to just attach a tag to each Collection group.

Shopify support has said that I should create Segments, but I’m not sure if this is the right way to go about it. I can’t see how to automate tags for a segment group? I also thought this could be a Flow, but there doesn’t seem to be many Collection attributes on there.

Any ideas or suggestions?

1 Like

Hi @ckgdesign ,

I’m not familiar with how segments work for purchases from specific collections so I can’t speak to that.

But with Flow, you could achieve this using a Run code step that finds the collections and adds some aspect of the collection as a customer tag. I used the Collection title for this example, but you could store the tag value in a Collection metafield or use something else.

Here is the structure of the Workflow:

And here is the code step’s setup and code:

Input:

query{
  order {
    lineItems {
      product {
        collections {
          title
        }
      }
    }
  }
}

Output:

"The output of Run Code"
type Output {
  "The list of tags to add to the customer"
  tags: [String!]
}

Code:

export default function main(input) {
  const titles = input.order.lineItems.reduce((acc, lineItem) => {
    const productTitles = lineItem.product.collections.map(collection => collection.title);
    return [...acc, ...productTitles];
  }, []);

    // De-duplicate the titles so they can be used as tags
  const uniqueTitles = [...new Set(titles)];

  return {
    tags: uniqueTitles,
  }
}

Hope that helps get you started!

It sounds like you’re wanting to classify them based on the collection page they visited prior to checkout? Not based on the collection a product belongs to since some products belong to multiple?

This can be done by looking at the urls in the customer journey, but that generally only works off of the first url they land on, not every url they visit leading up to a purchase. I think you might need a custom pixel built to track the level of granularity you would need for that.

You can do that by creating an automation on Flow: when an order is created check if the collection title equals to x, then add customer tags.