$npx -y skills add 40RTY-ai/shopify-admin-skills --skill shopify-admin-discount-cost-trendRead-only: tracks total discount dollars given over configurable time buckets (week/month/quarter), broken down by discount type and code.
| 1 | ## Purpose |
| 2 | Tracks how much money the store gave away in discounts over time, bucketed by week, month, or quarter, and broken down by discount code and discount type (percentage / fixed amount / free shipping / automatic). Answers: "is our discount spend trending up or down, and which campaigns are driving it?" Read-only — no mutations. Complements `discount-roi-calculator` (per-discount return) with a longitudinal view of total cost. |
| 3 | |
| 4 | ## Prerequisites |
| 5 | - Authenticated Shopify CLI session: `shopify store auth --store <domain> --scopes read_orders` |
| 6 | - API scopes: `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 | | period | string | no | month | Bucket size: `week`, `month`, or `quarter` | |
| 14 | | periods_back | integer | no | 12 | Number of buckets to report | |
| 15 | | top_codes | integer | no | 10 | Top discount codes to break out individually; remainder grouped as `other` | |
| 16 | | include_shipping_discounts | bool | no | true | Whether to count shipping discounts in the totals | |
| 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. |
| 22 | |
| 23 | ## Workflow Steps |
| 24 | |
| 25 | 1. Compute window from `period` × `periods_back` (e.g., `month` × 12 → last 12 calendar months starting from the first day of the bucket 11 months ago) |
| 26 | |
| 27 | 2. **OPERATION:** `orders` — query |
| 28 | **Inputs:** `query: "created_at:>='<window_start>' financial_status:paid"`, `first: 250`, select `createdAt`, `discountCodes`, `currentTotalDiscountsSet`, `totalDiscountsSet`, `cartDiscountAmountSet`, `discountApplications { allocationMethod, targetType, value, ... on DiscountCodeApplication { code }, ... on AutomaticDiscountApplication { title }, ... on ManualDiscountApplication { title } }`, `shippingLines { discountAllocations { allocatedAmountSet } }`, pagination cursor |
| 29 | **Expected output:** All paid orders in the window with discount data; paginate until `hasNextPage: false` |
| 30 | |
| 31 | 3. For each order, attribute discount cost: |
| 32 | - `cart_discount` = `currentTotalDiscountsSet.shopMoney.amount` |
| 33 | - `shipping_discount` = sum of `shippingLines.discountAllocations.allocatedAmountSet` (only if `include_shipping_discounts: true`) |
| 34 | - `total_discount` = cart_discount + shipping_discount |
| 35 | - Attribute by code: prefer first `discountApplications.code` for code discounts, `title` for automatic / manual |
| 36 | |
| 37 | 4. Bucket each order into its period (week-of-year, year-month, or year-quarter) and aggregate: |
| 38 | - Total discount cost per bucket |
| 39 | - Per discount code per bucket |
| 40 | - Per discount type per bucket (percentage, fixed_amount, shipping, automatic) |
| 41 | |
| 42 | 5. Identify top codes by total cost across the window; aggregate the rest as `other` |
| 43 | |
| 44 | ## GraphQL Operations |
| 45 | |
| 46 | ```graphql |
| 47 | # orders:query — validated against api_version 2025-01 |
| 48 | query DiscountCostTrend($query: String!, $after: String) { |
| 49 | orders(first: 250, after: $after, query: $query) { |
| 50 | edges { |
| 51 | node { |
| 52 | id |
| 53 | name |
| 54 | createdAt |
| 55 | discountCodes |
| 56 | currentTotalDiscountsSet { shopMoney { amount currencyCode } } |
| 57 | totalDiscountsSet { shopMoney { amount currencyCode } } |
| 58 | cartDiscountAmountSet { shopMoney { amount currencyCode } } |
| 59 | discountApplications(first: 10) { |
| 60 | edges { |
| 61 | node { |
| 62 | allocationMethod |
| 63 | targetType |
| 64 | targetSelection |
| 65 | value { |
| 66 | ... on PricingPercentageValue { percentage } |
| 67 | ... on MoneyV2 { amount currencyCode } |
| 68 | } |
| 69 | ... on DiscountCodeApplication { code } |
| 70 | ... on AutomaticDiscountApplication { title } |
| 71 | ... on ManualDiscountApplication { title description } |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | shippingLines(first: 5) { |
| 76 | edges { |
| 77 | node { |
| 78 | title |
| 79 | discountAllocations { |
| 80 | allocatedAmountSet { shopMoney { amount currencyCode } } |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | pageInfo { hasNextPage endCursor } |
| 88 | } |
| 89 | } |
| 90 | ``` |
| 91 | |
| 92 | ## Session Tracking |
| 93 | |
| 94 | **Claude MUST emit the following output at each stage. This is mandatory.** |
| 95 | |
| 96 | **On start**, emit: |
| 97 | ``` |
| 98 | ╔══════════════════════════════════════════════╗ |
| 99 | ║ SKILL: Discount Cost Trend ║ |
| 100 | ║ Store: <store domain> ║ |
| 101 | ║ Period: <period> × <periods_back> ║ |
| 102 | ║ Started: <YYYY-MM-DD HH:MM UTC> ║ |
| 103 | ╚════════════════════════════════════════ |