Joins sales and returns per product over a rolling window, recomputes margin net of returns, and tags products that only look profitable with 'returns-negative', so feeds and campaigns can treat them differently.
async def run(ctx): window = ctx.params.get("days", 90) sold = await ctx.orders.units_sold(days=window) returned = await ctx.orders.units_returned(days=window) for product_id, units in sold.items():
How do you measure profit after returns on Shopify?
To measure profit after returns on Shopify, this template joins sales and returns per product over a rolling window, recomputes margin net of the return rate and its per-unit loss, and tags products that only look profitable. A product with strong sales and a 40% return habit reads as a winner in every standard report; net of shipping both ways and the units you cannot resell, it can be your quietest loss. The window length and the loss model are parameters, so apparel can count differently than electronics.
This is a join across orders, returns and costs that a spreadsheet does once and never again. As code it re-runs weekly, and the returns-negative list arrives with the math visible per product. Feeds and campaigns can then treat those products differently the same day you approve the tags.
Last updated August 24, 2026
If you run a sharper version of this template, or something it inspired, send it in. We review every application and publish the good ones, credited to you or your agency.
AI writes real Python or TypeScript, a dry run rehearses it, you approve, it deploys.
Free plan · no card · 🇪🇺 EU data residency