Method of customer segmentation

Highlighted
New Member
6 0 0

Hi,

 

As part of the app we're building, I need to segment Shopify customers by multiple dimensions such as:

 

- Customers who have spent at least X.

- Customers who have purchased from collection X.

- Customers who haven't ordered since X.

 

I considered using the customer query endpoint, but it doesn't seem like it has the capability to perform these queries.  Unless there are undocumented fields?

 

The only way I can think of achieving this is to keep a local copy of all customers and orders.  Is this appropriate?

 

Thanks.

0 Likes
Highlighted
Shopify Staff
Shopify Staff
293 53 40

Hi @shane_developer 

 

With the API you'd be able to achieve some of your list. The spent over X and last ordered date. In regards to a specific collection, it would require an additional query to get the orders belonging to a customer and loop over the products. Otherwise, as you've mentioned having local data could work. Typically in the admin for customer segmentation we have merchants utilize tags for customer groups. 

Vix | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 


0 Likes
Highlighted
New Member
6 0 0

Hi @vix

 

Thanks for your reply!  I will keep it simple and use the capabilities of the query endpoint for now. :)

 

In reference to "last order date", I have tried to use the customer query endpoint, and also the Admin UI, the perform this query:

last_order_date:<2020-01-01

As per the documentation, this should be supported.  However, it doesn't work (the query executes as if this filter didn't exist), and if I attempt to save it as a CustomerSavedSearch, I receive a 422 error:

{"errors":{"query":["is invalid, 'last_order_date' is not a valid filter"]}}

The use case is to find customers that haven't purchased for at least X months, so they can be added to a marketing list.

 

Is this intentional?  Do you have any suggestions for achieving this goal?

 

Thanks!

0 Likes
Shopify Staff
Shopify Staff
293 53 40

Hi @shane_developer 

 

Please use order_date vs. last_order_date. This will be comprehensive of a first_order_date and last_order_date and should result in the exact information you are looking for. I will update the docs to match. 

 

Apologies for any confusion! 

Vix | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 


0 Likes
Highlighted
New Member
6 0 0

Hi @vix 

 

Unfortunately I don't think this is a solution.  It seems, in general, `order_date` is very broken.

 

Take, for example, this example:

 

Bob placed an order on 2020-01-23 and 2020-01-26.  Here are some example queries:

 

order_date:2020-01-25

Returns Bob - why?  Is it because the 25th is between his first and last order?

 

NOT order_date:2020-01-25

Also returns Bob - why?  He can't have ordered and not ordered on the same date surely?

 

I tried to implement a query to check who last ordered before the 25th:

 

order_date:<2020-01-25 AND NOT order_date:>2020-01-26

However this doesn't returns the expected results, as the NOT part of the query doesn't seem to do much.

 

If this does work properly, can you please provide a working example of querying all customers where their last order was before a specific date?

0 Likes
Highlighted
New Member
6 0 0

Hi again,

 

Notwithstanding my previous reply, I have managed to find a work-around that suits my current use case.

 

I can test to see which customers placed their last order on a specific date using the following (pseudo) logic.

A = search("order_date:2020-01-26")
B = search("order_date:>2020-01-27")
CustomersIWant = all customers in A that are not in B

Unfortunately joining this into one query such as:

order_date:2020-01-26 AND NOT order_date:>2020-01-27

yields different results.

0 Likes