$npx -y skills add 40RTY-ai/shopify-admin-skills --skill shopify-admin-top-product-performanceRank products by revenue, units sold, and refund rate over a date range by aggregating order line items.
| 1 | ## Purpose |
| 2 | Ranks products by revenue, units sold, and refund rate for a given date range by aggregating order line items and refund line items across all orders in the period. Useful for identifying top performers and products with high refund rates. Read-only — no mutations are executed. |
| 3 | |
| 4 | ## Prerequisites |
| 5 | - Authenticated Shopify CLI session: `shopify auth login --store <domain>` |
| 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 | | format | string | no | human | Output format: `human` or `json` | |
| 14 | | dry_run | bool | no | false | Preview operations without executing mutations | |
| 15 | | date_range_start | string | yes | — | Start date in ISO 8601 (e.g., `2025-01-01`) | |
| 16 | | date_range_end | string | yes | — | End date in ISO 8601 (e.g., `2025-01-31`) | |
| 17 | | top_n | integer | no | 20 | Number of top products to show in the ranked output | |
| 18 | | sort_by | string | no | revenue | Ranking metric: `revenue`, `units`, or `refund_rate` | |
| 19 | |
| 20 | ## Workflow Steps |
| 21 | |
| 22 | 1. **OPERATION:** `orders` — query |
| 23 | **Inputs:** `first: 250`, `query: "created_at:>='<date_range_start>' created_at:<='<date_range_end>'"`, pagination cursor |
| 24 | **Expected output:** All orders in range with line items (`title`, `quantity`, `originalTotalSet`, `refundableQuantity`) and refund line items; paginate until `hasNextPage: false`; aggregate in-memory per product: sum `originalTotalSet` for gross revenue, sum refund amounts for net revenue, sum quantities for units sold, compute refund rate |
| 25 | |
| 26 | ## GraphQL Operations |
| 27 | |
| 28 | ```graphql |
| 29 | # orders:query (for product revenue) — validated against api_version 2025-01 |
| 30 | query OrdersForProductPerformance($first: Int!, $after: String, $query: String) { |
| 31 | orders(first: $first, after: $after, query: $query) { |
| 32 | edges { |
| 33 | node { |
| 34 | id |
| 35 | createdAt |
| 36 | lineItems(first: 50) { |
| 37 | edges { |
| 38 | node { |
| 39 | title |
| 40 | quantity |
| 41 | variant { |
| 42 | id |
| 43 | sku |
| 44 | product { |
| 45 | id |
| 46 | title |
| 47 | } |
| 48 | } |
| 49 | originalTotalSet { |
| 50 | shopMoney { amount currencyCode } |
| 51 | } |
| 52 | refundableQuantity |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | refunds { |
| 57 | refundLineItems(first: 50) { |
| 58 | edges { |
| 59 | node { |
| 60 | quantity |
| 61 | lineItem { |
| 62 | variant { |
| 63 | id |
| 64 | product { id title } |
| 65 | } |
| 66 | } |
| 67 | subtotalSet { |
| 68 | shopMoney { amount currencyCode } |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | pageInfo { |
| 77 | hasNextPage |
| 78 | endCursor |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | ``` |
| 83 | |
| 84 | ## Session Tracking |
| 85 | |
| 86 | **Claude MUST emit the following output at each stage. This is mandatory.** |
| 87 | |
| 88 | **On start**, emit: |
| 89 | ``` |
| 90 | ╔══════════════════════════════════════════════╗ |
| 91 | ║ SKILL: top-product-performance ║ |
| 92 | ║ Store: <store domain> ║ |
| 93 | ║ Started: <YYYY-MM-DD HH:MM UTC> ║ |
| 94 | ╚══════════════════════════════════════════════╝ |
| 95 | ``` |
| 96 | |
| 97 | **After each step**, emit: |
| 98 | ``` |
| 99 | [N/TOTAL] <QUERY|MUTATION> <OperationName> |
| 100 | → Params: <brief summary of key inputs> |
| 101 | → Result: <count or outcome> |
| 102 | ``` |
| 103 | |
| 104 | **On completion**, emit: |
| 105 | |
| 106 | For `format: human` (default): |
| 107 | ``` |
| 108 | ══════════════════════════════════════════════ |
| 109 | OUTCOME SUMMARY |
| 110 | Orders processed: <n> |
| 111 | Products ranked: <n> |
| 112 | Date range: <start> to <end> |
| 113 | Sort by: <revenue|units|refund_rate> |
| 114 | Errors: 0 |
| 115 | Output: none |
| 116 | ══════════════════════════════════════════════ |
| 117 | ``` |
| 118 | |
| 119 | For `format: json`, emit: |
| 120 | ```json |
| 121 | { |
| 122 | "skill": "top-product-performance", |
| 123 | "store": "<domain>", |
| 124 | "started_at": "<ISO8601>", |
| 125 | "completed_at": "<ISO8601>", |
| 126 | "dry_run": false, |
| 127 | "steps": [ |
| 128 | { "step": 1, "operation": "OrdersForProductPerformance", "type": "query", "params_summary": "<date_range_start> to <date_range_end>", "result_summary": "<n> orders processed", "skipped": false } |
| 129 | ], |
| 130 | "outcome": { |
| 131 | "orders_processed": 0, |
| 132 | "products_ranked": 0, |
| 133 | "date_range_start": "<date_range_start>", |
| 134 | "date_range_end": "<date_range_end>", |
| 135 | "sort_by": "revenue", |
| 136 | "results": [], |
| 137 | "errors": 0, |
| 138 | "output_file": null |
| 139 | } |
| 140 | } |
| 141 | ``` |
| 142 | |
| 143 | ## Output Format |
| 144 | Ranked table displayed inline (no CSV), truncated to `top_n` entries: |
| 145 | |
| 146 | | Rank | Product | Units Sold | Gross Revenue | Refunded Amount | Net Revenue | Re |