$npx -y skills add 40RTY-ai/shopify-admin-skills --skill shopify-admin-customer-spend-tier-taggerCalculates lifetime spend per customer and applies tier tags (Bronze/Silver/Gold/Platinum) based on configurable thresholds.
| 1 | ## Purpose |
| 2 | Queries all customers, calculates their lifetime spend using order history, and assigns a spend-tier tag (Bronze/Silver/Gold/Platinum by default). Enables VIP segmentation for loyalty programs, exclusive offers, and CX prioritization without a third-party loyalty app. Extends the existing `loyalty-segment-export` skill with a write step. |
| 3 | |
| 4 | ## Prerequisites |
| 5 | - Authenticated Shopify CLI session: `shopify store auth --store <domain> --scopes read_customers,read_orders,write_customers` |
| 6 | - API scopes: `read_customers`, `read_orders`, `write_customers` |
| 7 | |
| 8 | ## Parameters |
| 9 | |
| 10 | | Parameter | Type | Required | Default | Description | |
| 11 | |-----------|------|----------|---------|-------------| |
| 12 | | store | string | yes | — | Store domain (e.g., mystore.myshopify.com) | |
| 13 | | tiers | object | no | see below | Spend thresholds per tier (in store currency) | |
| 14 | | tag_prefix | string | no | tier | Tag prefix (e.g., `tier:bronze`, `tier:silver`) | |
| 15 | | remove_old_tiers | bool | no | true | Remove existing tier tags before applying new ones | |
| 16 | | dry_run | bool | no | true | Preview without executing mutations | |
| 17 | | format | string | no | human | Output format: `human` or `json` | |
| 18 | |
| 19 | Default tiers (store currency): |
| 20 | ``` |
| 21 | bronze: $0–$249 |
| 22 | silver: $250–$999 |
| 23 | gold: $1,000–$4,999 |
| 24 | platinum: $5,000+ |
| 25 | ``` |
| 26 | |
| 27 | ## Safety |
| 28 | |
| 29 | > ⚠️ `tagsAdd` adds tags to customer records visible to staff and used by marketing segments. If `remove_old_tiers: true`, existing tier tags matching `tag_prefix` are removed before new ones are applied. Run with `dry_run: true` to review the tier distribution before committing. |
| 30 | |
| 31 | ## Workflow Steps |
| 32 | |
| 33 | 1. **OPERATION:** `customers` — query |
| 34 | **Inputs:** `first: 250`, select `id`, `amountSpent`, pagination cursor |
| 35 | **Expected output:** All customers with lifetime spend; paginate until `hasNextPage: false` |
| 36 | |
| 37 | 2. Assign tier to each customer based on `amountSpent.amount` vs. `tiers` thresholds |
| 38 | |
| 39 | 3. **OPERATION:** `orders` — query (optional — for verification of spend figures) |
| 40 | |
| 41 | 4. **OPERATION:** `tagsAdd` — mutation |
| 42 | **Inputs:** Customer `id`, `tags: ["<tag_prefix>:<tier>"]` |
| 43 | **Expected output:** Updated customer tags; `userErrors` |
| 44 | |
| 45 | ## GraphQL Operations |
| 46 | |
| 47 | ```graphql |
| 48 | # customers:query — validated against api_version 2025-01 |
| 49 | query CustomerSpendLevels($after: String) { |
| 50 | customers(first: 250, after: $after) { |
| 51 | edges { |
| 52 | node { |
| 53 | id |
| 54 | displayName |
| 55 | defaultEmailAddress { |
| 56 | emailAddress |
| 57 | } |
| 58 | amountSpent { |
| 59 | amount |
| 60 | currencyCode |
| 61 | } |
| 62 | numberOfOrders |
| 63 | tags |
| 64 | } |
| 65 | } |
| 66 | pageInfo { |
| 67 | hasNextPage |
| 68 | endCursor |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | ``` |
| 73 | |
| 74 | ```graphql |
| 75 | # orders:query — validated against api_version 2025-01 |
| 76 | query CustomerOrderHistory($customerId: String!, $after: String) { |
| 77 | orders(first: 250, after: $after, query: $customerId) { |
| 78 | edges { |
| 79 | node { |
| 80 | id |
| 81 | totalPriceSet { |
| 82 | shopMoney { |
| 83 | amount |
| 84 | currencyCode |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | pageInfo { |
| 90 | hasNextPage |
| 91 | endCursor |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | ``` |
| 96 | |
| 97 | ```graphql |
| 98 | # tagsAdd:mutation — validated against api_version 2025-01 |
| 99 | mutation TagsAdd($id: ID!, $tags: [String!]!) { |
| 100 | tagsAdd(id: $id, tags: $tags) { |
| 101 | node { |
| 102 | id |
| 103 | } |
| 104 | userErrors { |
| 105 | field |
| 106 | message |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | ``` |
| 111 | |
| 112 | ## Session Tracking |
| 113 | |
| 114 | **Claude MUST emit the following output at each stage. This is mandatory.** |
| 115 | |
| 116 | **On start**, emit: |
| 117 | ``` |
| 118 | ╔══════════════════════════════════════════════╗ |
| 119 | ║ SKILL: Customer Spend Tier Tagger ║ |
| 120 | ║ Store: <store domain> ║ |
| 121 | ║ Started: <YYYY-MM-DD HH:MM UTC> ║ |
| 122 | ╚══════════════════════════════════════════════╝ |
| 123 | ``` |
| 124 | |
| 125 | **After each step**, emit: |
| 126 | ``` |
| 127 | [N/TOTAL] <QUERY|MUTATION> <OperationName> |
| 128 | → Params: <brief summary of key inputs> |
| 129 | → Result: <count or outcome> |
| 130 | ``` |
| 131 | |
| 132 | If `dry_run: true`, prefix every mutation step with `[DRY RUN]` and do not execute it. |
| 133 | |
| 134 | **On completion**, emit: |
| 135 | |
| 136 | For `format: human` (default): |
| 137 | ``` |
| 138 | ══════════════════════════════════════════════ |
| 139 | OUTCOME SUMMARY |
| 140 | Customers processed: <n> |
| 141 | Bronze: <n> (<pct>%) |
| 142 | Silver: <n> (<pct>%) |
| 143 | Gold: <n> (<pct>%) |
| 144 | Platinum: <n> (<pct>%) |
| 145 | Tags applied: <n> |
| 146 | Errors: <n> |
| 147 | Output: tier_tagging_<date>.csv |
| 148 | ══════════════════════════════════════════════ |
| 149 | ``` |
| 150 | |
| 151 | For `format: json`, emit: |
| 152 | ```json |
| 153 | { |
| 154 | "skill": "customer-spend-tier-tagger", |
| 155 | "store": "<domain>", |
| 156 | "started_at": "<ISO8601>", |
| 157 | "dry_run": true, |
| 158 | "tier_distribution": { "bronze": 0, "silver": 0, "gold": 0, "platinum": 0 }, |
| 159 | "tags_applied": 0, |
| 160 | "errors": 0, |
| 161 | "ou |