Tags products where every available variant has cost/price below a threshold (default 0.60) with 'alto-margine'; removes the tag when margins drop; skips products with missing costs.
async def run(ctx): max_ratio = ctx.params.get("max_cost_ratio", 0.60) for product in await ctx.shopify.query(PRODUCTS_WITH_COSTS): variants = [v for v in product.variants if v.available] if any(v.unit_cost is None for v in variants):
How do you segment a Shopify catalog by profit margin?
To segment a Shopify catalog by profit margin, this template reads price and cost of goods on every variant, computes the margin, and tags products by band. The default flags products whose available variants all clear a 60% cost-to-price threshold, and both the bands and the threshold are yours to change. The tags flow anywhere tags reach: Google Shopping custom labels, ad segments, smart collections, reports. Products with a variant missing its cost are skipped, never guessed; the companion missing-cost check finds those first.
Shopify stores your cost per item but does not compute with it, so margin stays a number in a report while campaigns optimize for revenue. Run as code across the whole catalog, the same data becomes targeting. Every tag the run would write shows up in the report you approve, and the below-cost audit picks up where this leaves off.
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