Build a customer segment template extension
A customer segment template extension is an extension that is displayed in the template drawer of the customer segment editor.
This guide is the first part in a two-part tutorial series on how to build a feature using customer segment template extensions and an admin action in the Use segment modal. This guide demonstrates how to build a customer segment template extension that enables users to create a segment based on a custom query your app provides. The customer segment template extension displays in the template drawer of the customer segment editor under the segment details page.

Anchor to What you'll learnWhat you'll learn
In this tutorial, you'll learn how to do the following tasks:
-
Create a customer segment template extension that is displayed in the template drawer of customer segment editor in the Shopify admin.
-
Run the extension locally and test it on a development store.
Anchor to RequirementsRequirements
-
You've created a Partner account and a development store.
-
Your app is using Shopify CLI 3.48 or higher.
Anchor to Step 1: Create a new extensionStep 1: Create a new extension
To create your customer segment template extension, you can use Shopify CLI to generate a starter extension.
-
Navigate to your app directory:
Terminal
cd <directory> -
Run the following command to create a new admin action extension:
Terminal
shopify app generate extension --template customer_segment_template --name loyal-customers-template --flavor reactThe command creates a new extension template in your app's
extensions
directory with the following structure:Customer segment template structure
extensions/loyal-customers-template├── README.md├── locales│ ├── en.default.json // The default locale for the extension│ └── fr.json // The French language translations for the extension├── package.json├── shopify.extension.toml // The config file for the extension└── src└── CustomerSegmentTemplate.jsx // The code that defines the action's UI and behavior
Anchor to Step 2: Build the extension's UIStep 2: Build the extension's UI
Complete the following steps to build the extension's UI.
Anchor to Review the configurationReview the configuration
The extension's .toml
file stores the extension's static configuration. To have the template appear in the template drawer of the customer segment editor, validate that the target
is set to admin.customers.segmentation-templates.render
. For a full list of targets and the locations where they display in the Shopify admin, refer to the admin extension configuration reference.
shopify.extension.toml
Anchor to Create the UICreate the UI
This tutorial uses the React implementation of admin UI extensions. If you want to create JavaScript-only extensions, then you'll need to use the provided API from the root object.
Customer segment template extensions are rendered using Remote UI, which is a fast and secure remote-rendering framework. Because Shopify renders the UI remotely, components used in the extensions must comply with a contract in the Shopify host.
Unlike other UI extensions, customer segment template extensions don't support the entire range of UI components. They're designed to operate in conjunction with the CustomerSegmentTemplate
component.
You can view the source of your extension in the src/CustomerSegmentTemplate.jsx
file. This file defines a functional React component that's exported to run at the extension's target. The CustomerSegmentTemplate
component is specifically designed for customer segment template extensions and has already been imported for you. All the template extensions that you create for your application will be displayed under your application's category.
The extension point in the component export must match the extension point defined in your .toml
file, or the extension won't render.
If the template refers to a metafield, the metafield needs to exist in our database or the extension won't render.
To build your customer segment template, you need to populate the CustomerSegmentTemplate
component's title
, description
, query
, queryToInsert
and createdOn
props. For a list of all the component's props and their descriptions, refer to the CustomerSegmentTemplate
component reference.
Add the following code to src/CustomerSegmentTemplate.jsx
:
src/CustomerSegmentTemplate.jsx
The validity of the query's syntax is not verified and needs to be tested in the customer segment editor.
To update the title and description of the template, edit the corresponding title
and description
values in the locale files.
Locales
locales/en.default.json
{
"title": "Loyal customers",
"description": "Use this template to identify your loyal customers, you can reward them with discounts, or award them loyalty points!"
}
{
"title": "Clients fidèles",
"description": "Utilisez ce modèle pour identifier vos clients fidèles. Vous pouvez les récompenser avec des remises ou leur attribuer des points de fidélité!"
}
You can create queries using your own metafields. You could choose to query your loyal customers by using a loyalty points metafield. For example, customers that have already 10 loyalty points could be considered as loyal customers. Once the segment is created, an additional number of loyalty points could be awarded to these customers.
Anchor to Step 3: Test the extensionStep 3: Test the extension
After you've built the extension, you can test it by completing the following steps.
-
Navigate to your app directory:
Terminal
cd <directory> -
To build and preview your app, either start or restart your server with the following command:
Terminal
shopify app dev
- Press
p
to open the developer console. - In the developer console page, click on the preview link for the loyalty points template extension.
The template drawer of the customer segment editor opens on the customer index page.

-
To use your extension, click the Use this template button:
-
Validate the query inside the customer segment editor:
Anchor to Next stepsNext steps
- Complete the next guide in this tutorial series by building an action extension in the Use segment modal. This will allow your app to use the newly created customer segment.