$npx -y skills add 40RTY-ai/shopify-admin-skills --skill shopify-admin-customer-acquisition-cost-by-sourceRead-only: estimates customer acquisition cost (CAC) per traffic source by joining order count per landing site / referrer with configurable ad spend.
| 1 | ## Purpose |
| 2 | Estimates customer acquisition cost (CAC) for each traffic source by combining the number of new-customer orders attributed to a landing page / referrer with a configurable ad spend input per source. Output answers: "for every dollar spent on source X, how many new customers did we acquire and at what unit cost?" Read-only — no mutations. Provides the data foundation for paid-media budget reallocation. |
| 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 | 30 | Lookback window for orders to attribute | |
| 14 | | ad_spend | object | no | {} | Map of source name → spend in store currency, e.g. `{"google": 4500, "meta": 3200, "tiktok": 1800}` | |
| 15 | | new_customers_only | bool | no | true | Count only first-order customers as "acquired" | |
| 16 | | min_orders_per_source | integer | no | 5 | Minimum orders for a source to be reported | |
| 17 | | format | string | no | human | Output format: `human` or `json` | |
| 18 | |
| 19 | ## Safety |
| 20 | |
| 21 | > ℹ️ Read-only skill — no mutations are executed. Safe to run at any time. Ad spend values are caller-provided; this skill does not pull from any ad platform. |
| 22 | |
| 23 | ## Workflow Steps |
| 24 | |
| 25 | 1. **OPERATION:** `orders` — query |
| 26 | **Inputs:** `query: "created_at:>='<NOW - days_back days>'"`, `first: 250`, select `customer { id, numberOfOrders }`, `customerJourneySummary { firstVisit { landingPage referrerUrl source } }`, `landingPageUrl`, `referrerUrl`, `totalPriceSet`, pagination cursor |
| 27 | **Expected output:** All orders in the window with referral and customer attribution; paginate until `hasNextPage: false` |
| 28 | |
| 29 | 2. Group orders by normalized source. Resolution order: |
| 30 | - `customerJourneySummary.firstVisit.source` if present |
| 31 | - Else parse domain from `referrerUrl` |
| 32 | - Else parse `landingPageUrl` UTM params (utm_source) |
| 33 | - Else bucket as `direct` |
| 34 | |
| 35 | 3. If `new_customers_only: true`, drop orders where `customer.numberOfOrders > 1` so each customer is counted once |
| 36 | |
| 37 | 4. Aggregate per source: `orders_count`, `new_customers_count`, `revenue_attributed` |
| 38 | |
| 39 | 5. Join with `ad_spend` map: `cac = ad_spend[source] / new_customers_count`. Sources without spend data report `cac: null` (organic / unattributed) |
| 40 | |
| 41 | 6. Filter to sources with `orders_count >= min_orders_per_source` |
| 42 | |
| 43 | ## GraphQL Operations |
| 44 | |
| 45 | ```graphql |
| 46 | # orders:query — validated against api_version 2025-01 |
| 47 | query OrdersWithAttribution($query: String!, $after: String) { |
| 48 | orders(first: 250, after: $after, query: $query) { |
| 49 | edges { |
| 50 | node { |
| 51 | id |
| 52 | name |
| 53 | createdAt |
| 54 | landingPageUrl |
| 55 | referrerUrl |
| 56 | customerJourneySummary { |
| 57 | firstVisit { |
| 58 | landingPage |
| 59 | referrerUrl |
| 60 | source |
| 61 | sourceType |
| 62 | utmParameters { |
| 63 | source |
| 64 | medium |
| 65 | campaign |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | totalPriceSet { |
| 70 | shopMoney { |
| 71 | amount |
| 72 | currencyCode |
| 73 | } |
| 74 | } |
| 75 | customer { |
| 76 | id |
| 77 | numberOfOrders |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | pageInfo { |
| 82 | hasNextPage |
| 83 | endCursor |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | ``` |
| 88 | |
| 89 | ## Session Tracking |
| 90 | |
| 91 | **Claude MUST emit the following output at each stage. This is mandatory.** |
| 92 | |
| 93 | **On start**, emit: |
| 94 | ``` |
| 95 | ╔══════════════════════════════════════════════╗ |
| 96 | ║ SKILL: Customer Acquisition Cost by Source ║ |
| 97 | ║ Store: <store domain> ║ |
| 98 | ║ Started: <YYYY-MM-DD HH:MM UTC> ║ |
| 99 | ╚══════════════════════════════════════════════╝ |
| 100 | ``` |
| 101 | |
| 102 | **After each step**, emit: |
| 103 | ``` |
| 104 | [N/TOTAL] <QUERY|MUTATION> <OperationName> |
| 105 | → Params: <brief summary of key inputs> |
| 106 | → Result: <count or outcome> |
| 107 | ``` |
| 108 | |
| 109 | **On completion**, emit: |
| 110 | |
| 111 | For `format: human` (default): |
| 112 | ``` |
| 113 | ══════════════════════════════════════════════ |
| 114 | CAC BY SOURCE (<days_back> days) |
| 115 | Orders analyzed: <n> |
| 116 | New customers acquired: <n> |
| 117 | Total ad spend (input): $<amount> |
| 118 | Blended CAC: $<amount> |
| 119 | |
| 120 | By Source (sorted by CAC ascending): |
| 121 | google Customers: <n> Spend: $<n> CAC: $<n> |
| 122 | meta Customers: <n> Spend: $<n> CAC: $<n> |
| 123 | direct Customers: <n> Spend: — CAC: organic |
| 124 | referral Customers: <n> Spend: — CAC: organic |
| 125 | |
| 126 | Output: cac_by_source_<date>.csv |
| 127 | ══════════════════════════════════════════════ |
| 128 | ``` |
| 129 | |
| 130 | For `format: json`, |