$npx -y skills add 40RTY-ai/shopify-admin-skills --skill shopify-admin-rfm-customer-segmentationRead-only: scores every customer on Recency, Frequency, and Monetary value to segment them into actionable groups (Champions, Loyal, At-Risk, Lost).
| 1 | ## Purpose |
| 2 | Performs full RFM (Recency, Frequency, Monetary) analysis across the entire customer base. Each customer is scored 1-5 on three dimensions — how recently they purchased, how often they purchase, and how much they spend — then classified into actionable segments: Champions, Loyal Customers, Potential Loyalists, At-Risk, Hibernating, and Lost. Read-only — no mutations. |
| 3 | |
| 4 | ## Prerequisites |
| 5 | - Authenticated Shopify CLI session: `shopify store auth --store <domain> --scopes read_orders,read_customers` |
| 6 | - API scopes: `read_orders`, `read_customers` |
| 7 | |
| 8 | ## Parameters |
| 9 | |
| 10 | | Parameter | Type | Required | Default | Description | |
| 11 | |-----------|------|----------|---------|-------------| |
| 12 | | store | string | yes | — | Store domain (e.g., mystore.myshopify.com) | |
| 13 | | days_back | integer | no | 365 | Lookback window for order history | |
| 14 | | segments | integer | no | 5 | Number of quintile buckets per dimension (3 or 5) | |
| 15 | | min_orders | integer | no | 1 | Minimum orders for a customer to be scored | |
| 16 | | tag_customers | boolean | no | false | If true, add RFM segment tag to customer (requires write_customers scope) | |
| 17 | | format | string | no | human | Output format: `human` or `json` | |
| 18 | |
| 19 | ## Safety |
| 20 | |
| 21 | > ℹ️ Read-only by default. If `tag_customers: true`, will add tags via customerUpdate mutation — use `dry_run: true` first. |
| 22 | |
| 23 | ## RFM Segment Definitions |
| 24 | |
| 25 | | Segment | R Score | F Score | M Score | Description | |
| 26 | |---------|---------|---------|---------|-------------| |
| 27 | | Champions | 5 | 5 | 5 | Best customers — recent, frequent, high spend | |
| 28 | | Loyal Customers | 3-5 | 4-5 | 4-5 | Consistent buyers with strong spend | |
| 29 | | Potential Loyalists | 4-5 | 2-3 | 2-3 | Recent buyers who could become loyal | |
| 30 | | New Customers | 5 | 1 | 1-2 | Just made first purchase | |
| 31 | | Promising | 4 | 1-2 | 1-2 | Recent but low frequency — nurture them | |
| 32 | | Need Attention | 3 | 3 | 3 | Average across all dimensions — slipping | |
| 33 | | About to Sleep | 2-3 | 2 | 2 | Below average recency and frequency | |
| 34 | | At Risk | 1-2 | 4-5 | 4-5 | Were great customers, haven't bought recently | |
| 35 | | Hibernating | 1-2 | 1-2 | 1-3 | Low on all dimensions — nearly lost | |
| 36 | | Lost | 1 | 1-2 | 1-5 | Haven't bought in a very long time | |
| 37 | |
| 38 | ## Workflow Steps |
| 39 | |
| 40 | 1. **OPERATION:** `orders` — query |
| 41 | **Inputs:** `query: "created_at:>='<NOW - days_back days>'"`, `first: 250`, select `createdAt`, `totalPriceSet`, `customer { id, email, firstName, lastName, numberOfOrders }`, pagination cursor |
| 42 | **Expected output:** All orders in window with customer linkage; paginate until complete |
| 43 | |
| 44 | 2. Aggregate per customer: |
| 45 | - **Recency** = days since last order |
| 46 | - **Frequency** = total number of orders in window |
| 47 | - **Monetary** = total spend in window |
| 48 | |
| 49 | 3. Score each dimension 1-5 using quintile bucketing: |
| 50 | - Sort all customers by each metric |
| 51 | - Divide into N equal-sized groups (quintiles) |
| 52 | - Assign scores (5 = best for recency [most recent], frequency [most frequent], monetary [highest spend]) |
| 53 | |
| 54 | 4. Map (R, F, M) score combination to named segment using the definitions above |
| 55 | |
| 56 | 5. **OPERATION:** `customers` — query (enrichment) |
| 57 | **Inputs:** Customer IDs from each segment for contact details |
| 58 | **Expected output:** Email, name, tags for top customers in each segment |
| 59 | |
| 60 | ## GraphQL Operations |
| 61 | |
| 62 | ```graphql |
| 63 | # orders:query — validated against api_version 2025-01 |
| 64 | query OrdersForRFM($query: String!, $after: String) { |
| 65 | orders(first: 250, after: $after, query: $query) { |
| 66 | edges { |
| 67 | node { |
| 68 | id |
| 69 | createdAt |
| 70 | totalPriceSet { shopMoney { amount currencyCode } } |
| 71 | customer { |
| 72 | id |
| 73 | |
| 74 | firstName |
| 75 | lastName |
| 76 | numberOfOrders |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | pageInfo { hasNextPage endCursor } |
| 81 | } |
| 82 | } |
| 83 | ``` |
| 84 | |
| 85 | ```graphql |
| 86 | # customers:query — validated against api_version 2025-01 |
| 87 | query CustomerDetails($query: String, $after: String) { |
| 88 | customers(first: 250, after: $after, query: $query) { |
| 89 | edges { |
| 90 | node { |
| 91 | id |
| 92 | |
| 93 | firstName |
| 94 | lastName |
| 95 | numberOfOrders |
| 96 | totalSpentV2 { amount currencyCode } |
| 97 | tags |
| 98 | createdAt |
| 99 | } |
| 100 | } |
| 101 | pageInfo { hasNextPage endCursor } |
| 102 | } |
| 103 | } |
| 104 | ``` |
| 105 | |
| 106 | ## Session Tracking |
| 107 | |
| 108 | **Claude MUST emit the following output at each stage. This is mandatory.** |
| 109 | |
| 110 | **On start**, emit: |
| 111 | ``` |
| 112 | ╔══════════════════════════════════════════════╗ |
| 113 | ║ SKILL: RFM Customer Segmentation ║ |
| 114 | ║ Store: <store domain> ║ |
| 115 | ║ Started: <YYYY-MM-DD HH:MM UTC> ║ |
| 116 | ╚══════════════════════════════════════════════╝ |
| 117 | ``` |
| 118 | |
| 119 | **After each step**, emit: |
| 120 | ``` |
| 121 | [N/TOTAL] <QUERY|MUTATION> |