$npx -y skills add 40RTY-ai/shopify-admin-skills --skill shopify-admin-customer-cohort-analysisRead-only: groups customers by first-purchase month and tracks repeat purchase rate and revenue per cohort.
| 1 | ## Purpose |
| 2 | Groups customers by the month of their first purchase and tracks how each cohort performs over time: how many customers repurchase, how many orders they place, and how much revenue each cohort generates in subsequent months. Cohort analysis is the gold standard for measuring retention and the health of a subscription or loyalty program. Read-only — no mutations. |
| 3 | |
| 4 | ## Prerequisites |
| 5 | - Authenticated Shopify CLI session: `shopify store auth --store <domain> --scopes read_customers,read_orders` |
| 6 | - API scopes: `read_customers`, `read_orders` |
| 7 | |
| 8 | ## Parameters |
| 9 | |
| 10 | | Parameter | Type | Required | Default | Description | |
| 11 | |-----------|------|----------|---------|-------------| |
| 12 | | store | string | yes | — | Store domain (e.g., mystore.myshopify.com) | |
| 13 | | cohort_months | integer | no | 6 | Number of months of cohorts to analyze | |
| 14 | | follow_months | integer | no | 3 | Number of months to follow each cohort after acquisition | |
| 15 | | format | string | no | human | Output format: `human` or `json` | |
| 16 | |
| 17 | ## Safety |
| 18 | |
| 19 | > ℹ️ Read-only skill — no mutations are executed. Safe to run at any time. |
| 20 | |
| 21 | ## Workflow Steps |
| 22 | |
| 23 | 1. **OPERATION:** `customers` — query |
| 24 | **Inputs:** `query: "created_at:>='<NOW - cohort_months months>'"`, `first: 250`, select `id`, `createdAt`, `numberOfOrders`, pagination cursor |
| 25 | **Expected output:** Customers acquired in the cohort window |
| 26 | |
| 27 | 2. **OPERATION:** `orders` — query |
| 28 | **Inputs:** `query: "created_at:>='<NOW - cohort_months + follow_months months>'"`, `first: 250`, select `customer { id }`, `createdAt`, `totalPriceSet`, pagination cursor |
| 29 | **Expected output:** All orders to build per-customer purchase timeline |
| 30 | |
| 31 | 3. Group customers by first-order month (cohort); for each cohort, calculate repeat purchase rate and total revenue in months 1, 2, 3+ |
| 32 | |
| 33 | ## GraphQL Operations |
| 34 | |
| 35 | ```graphql |
| 36 | # customers:query — validated against api_version 2025-01 |
| 37 | query CohortCustomers($query: String!, $after: String) { |
| 38 | customers(first: 250, after: $after, query: $query) { |
| 39 | edges { |
| 40 | node { |
| 41 | id |
| 42 | createdAt |
| 43 | numberOfOrders |
| 44 | amountSpent { |
| 45 | amount |
| 46 | currencyCode |
| 47 | } |
| 48 | defaultEmailAddress { |
| 49 | emailAddress |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | pageInfo { |
| 54 | hasNextPage |
| 55 | endCursor |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | ``` |
| 60 | |
| 61 | ```graphql |
| 62 | # orders:query — validated against api_version 2025-01 |
| 63 | query CohortOrders($query: String!, $after: String) { |
| 64 | orders(first: 250, after: $after, query: $query) { |
| 65 | edges { |
| 66 | node { |
| 67 | id |
| 68 | createdAt |
| 69 | totalPriceSet { |
| 70 | shopMoney { |
| 71 | amount |
| 72 | currencyCode |
| 73 | } |
| 74 | } |
| 75 | customer { |
| 76 | id |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | pageInfo { |
| 81 | hasNextPage |
| 82 | endCursor |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | ``` |
| 87 | |
| 88 | ## Session Tracking |
| 89 | |
| 90 | **Claude MUST emit the following output at each stage. This is mandatory.** |
| 91 | |
| 92 | **On start**, emit: |
| 93 | ``` |
| 94 | ╔══════════════════════════════════════════════╗ |
| 95 | ║ SKILL: Customer Cohort Analysis ║ |
| 96 | ║ Store: <store domain> ║ |
| 97 | ║ Started: <YYYY-MM-DD HH:MM UTC> ║ |
| 98 | ╚══════════════════════════════════════════════╝ |
| 99 | ``` |
| 100 | |
| 101 | **After each step**, emit: |
| 102 | ``` |
| 103 | [N/TOTAL] <QUERY|MUTATION> <OperationName> |
| 104 | → Params: <brief summary of key inputs> |
| 105 | → Result: <count or outcome> |
| 106 | ``` |
| 107 | |
| 108 | **On completion**, emit: |
| 109 | |
| 110 | For `format: human` (default): |
| 111 | ``` |
| 112 | ══════════════════════════════════════════════ |
| 113 | CUSTOMER COHORT ANALYSIS |
| 114 | Cohort months analyzed: <n> |
| 115 | Total customers tracked: <n> |
| 116 | |
| 117 | Cohort Acquired M+1 Repeat M+2 Repeat M+3 Repeat |
| 118 | ────────────────────────────────────────────────────────── |
| 119 | 2026-01 <n> <pct>% <pct>% <pct>% |
| 120 | 2026-02 <n> <pct>% <pct>% <pct>% |
| 121 | Output: cohort_analysis_<date>.csv |
| 122 | ══════════════════════════════════════════════ |
| 123 | ``` |
| 124 | |
| 125 | For `format: json`, emit: |
| 126 | ```json |
| 127 | { |
| 128 | "skill": "customer-cohort-analysis", |
| 129 | "store": "<domain>", |
| 130 | "cohorts": [], |
| 131 | "output_file": "cohort_analysis_<date>.csv" |
| 132 | } |
| 133 | ``` |
| 134 | |
| 135 | ## Output Format |
| 136 | CSV file `cohort_analysis_<YYYY-MM-DD>.csv` with columns: |
| 137 | `cohort_month`, `customers_acquired`, `repeat_purchasers`, `repeat_rate_pct`, `total_revenue`, `revenue_per_customer`, `month_offset` |
| 138 | |
| 139 | ## Error Handling |
| 140 | | Error | Cause | Recovery | |
| 141 | |-------|-------|----------| |
| 142 | | `THROTTLED` | API rate limit exceeded | Wait 2 seconds, retry up to 3 times | |
| 143 | | Insufficient history | Store newer than cohort window | Analyze available months only | |
| 144 | | Guest checkout orders | No customer record | Exclude from cohort tracking | |
| 145 | |
| 146 | ## Best Practices |
| 147 | - A healthy ecommerce business typically sees 20–40% of first-month customers repeat within 90 |