Skip to content

Shopify tutorials for the person running the store. Orders, discounts, fulfilment, returns.

Segment customers by location in Shopify

A Toronto-only pickup event, a Montreal French-language email, a Vancouver shipping notice: each one starts with the customers who live there. Shopify's segment editor filters on the city in a customer's address, using a country-province-city code. This tutorial builds a Toronto segment from a store of 214 customers.

Written · Shopify admin, desktop steps · 4 minutes read

The worked example

Customers in Toronto61
Customers in Vancouver38
Customers in Montreal19
Customers elsewhere96
All customers214
Toronto share28.50%

Download the location worksheet: location-segment.csv (99 bytes, md5 03f1ba551a9bdcaece33adb2918b9685).

A worksheet of customers by city: Toronto, Vancouver, Montreal, and everywhere else, adding to the store total of 214.

1Open the segment editor

From your Shopify admin, go to Customers, click Segments, then click Create segment. The query editor opens with the default query in place.

2Add the city filter

Click into the WHERE area, pick the filter customer_cities, pick the operator CONTAINS, and pick the value CA-ON-Toronto. The value is a code, not a typed city name: CA for Canada, ON for Ontario, then Toronto. The full line reads WHERE customer_cities CONTAINS 'CA-ON-Toronto'.

3Run the query and read the count

Click Run query. The matching customers list below the editor and the count shows above it. The worked example shows 61 Toronto customers out of 214. If the city you want does not appear in the suggestions, your store may have no customers there yet.

4Add a second city with OR if you need it

Optional: to cover two cities in one segment, add OR customer_cities CONTAINS 'CA-BC-Vancouver'. The OR connector widens the group to customers in either city.

5Save the segment

Review the AI-generated description, then click Save segment, name it Toronto customers, and click Save.

The arithmetic

The store's 214 customers, grouped by the city on their default address.

CityCustomersShare of the store
Toronto, ON6128.50%
Vancouver, BC3817.76%
Montreal, QC198.88%
Elsewhere9644.86%
All customers214100.00%

61 plus 38 plus 19 plus 96 equals 214. Toronto's share is 61 divided by 214, which is 28.50%.

Held at the counter

The value is a code, not a name. Typing Toronto on its own does not match the filter. Use the suggested value in the form CA-ON-Toronto, country code, province code, then city.

The filter reads the address on file. A customer who moved and never updated their profile still sits in the old city. Location segments are only as current as the addresses in your customer list.

A missing filter usually means no data. If the city filter you expect does not appear in the suggestions, the store has no matching customer data yet, and typing the filter in by hand can return an Invalid expression error instead of an empty result.

Sources