> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mention-me.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Segmentation

> How to segment customers using Shopify Metafields or custom JavaScript logic to show different Mention Me experiences.

<Note>The following instructions are for **Brand Referral**, which is **not currently available** on the free Tier of the Shopify App. [Contact us to know more](https://help.mention-me.com/hc/en-gb/requests/new?ticket_form_id=20114637802909).</Note>

Segmenting your customers allows you to show different Mention Me experiences to different users. The app automatically includes localisation data, and additional segmentation can be added within the app.

Two methods are supported:

1. **Shopify Metafields** (recommended)
2. **Custom segmentation** using JavaScript logic

## Supported Metafields (Recommended)

Shopify Metafields let you define custom customer metadata. Mention Me can use these values to show different experiences.

Metafields must be explicitly added to the Mention Me app in advance — Shopify does not automatically send them by default.

<Warning>Metafields must already exist on the customer record *before* they complete their transaction. Otherwise, Shopify won't pass them to Mention Me.</Warning>

Automatically supported Customer Metafields:

* **mention-me.segment** — Mention Me Segment
* **loyaltylion.loyalty\_tier** — Loyalty Lion Loyalty Tier

### Requesting a New Metafield

Raise a support ticket providing both the **namespace** and **key**.

To find the namespace and key:

<Steps>
  <Step title="Open Metafields settings">
    In your Shopify Admin, go to **Settings > Metafields and metaobjects**.

    <img src="https://mintcdn.com/mentionme/GjiDi6ZwHP27Pu0w/images/knowledge/shopify/28555018117021.png?fit=max&auto=format&n=GjiDi6ZwHP27Pu0w&q=85&s=b746ec50a207c240518526b7e35fb697" alt="Shopify admin Settings showing Metafields and metaobjects" width="2276" height="1632" data-path="images/knowledge/shopify/28555018117021.png" />
  </Step>

  <Step title="Select Customers">
    <img src="https://mintcdn.com/mentionme/GjiDi6ZwHP27Pu0w/images/knowledge/shopify/28555018118301.png?fit=max&auto=format&n=GjiDi6ZwHP27Pu0w&q=85&s=a7ea9643b0be88d0e79dbe4ae09f53b4" alt="Selecting Customers metafield category" width="2276" height="1632" data-path="images/knowledge/shopify/28555018118301.png" />
  </Step>

  <Step title="Select the metafield">
    Select the metafield you'd like Mention Me to use.

    <img src="https://mintcdn.com/mentionme/GjiDi6ZwHP27Pu0w/images/knowledge/shopify/28555018118941.png?fit=max&auto=format&n=GjiDi6ZwHP27Pu0w&q=85&s=6dd61e60a435b219d005266d6d868dd8" alt="Selecting a customer metafield for Mention Me" width="2260" height="1618" data-path="images/knowledge/shopify/28555018118941.png" />
  </Step>

  <Step title="Copy the namespace and key">
    Copy the "Namespace and key" (e.g., `mention-me.segment`).

    <img src="https://mintcdn.com/mentionme/GjiDi6ZwHP27Pu0w/images/knowledge/shopify/28555018119325.png?fit=max&auto=format&n=GjiDi6ZwHP27Pu0w&q=85&s=f7db97e7f2d3ea272fced65b480df9d8" alt="Metafield namespace and key value" width="2262" height="1074" data-path="images/knowledge/shopify/28555018119325.png" />
  </Step>
</Steps>

Mention Me will add this to the app and begin including it in data from Shopify when available.

## Custom Segmentation with Code

<Note>**Advanced feature.** If you need guidance, [contact Mention Me support](https://help.mention-me.com/hc/en-gb/requests/new).</Note>

You can create a segment dynamically using the contents of the user's cart by writing JavaScript logic. This is handled via a script input in the Mention Me Shopify app settings.

Example: Segment users depending on which product variants are in their cart.

```javascript theme={null}
const getSegment = (currentSegment, cartLines) => {
  const lineItems = cartLines || [];
  const segments = [];

  lineItems.forEach((item) => {
    switch (item.merchandise.id) {
      case "gid://shopify/ProductVariant/11102677025151":
        segments.push("Segment_A");
        break;
      case "gid://shopify/ProductVariant/11102667653503":
        segments.push("Segment_B");
        break;
      case "gid://shopify/ProductVariant/11883500654975":
        segments.push("Segment_C");
        break;
    }
  });

  const priority = ["Segment_A", "Segment_B", "Segment_C"];
  for (const seg of priority) {
    if (segments.includes(seg)) {
      return { segment: seg };
    }
  }

  return { segment: null };
};

return getSegment(segment, cartLines);
```

Full documentation and sandbox examples are available inside the Mention Me admin.

## Can I Use Tags or Other Shopify Attributes?

Shopify does not allow direct access to tags or other customer properties at checkout time. You cannot segment directly using tags.

You may be able to use **Shopify Flow** to assign a metafield to customers dynamically based on tags. However:

* Shopify Flow is asynchronous — your flow must complete before the customer checks out
* Only values set before checkout are passed to Mention Me
* Consult a Shopify expert when building a Flow-based process
