AI agent that catches discount codes eating your margin
A discount code that "drove $50k in revenue" sounds like a win until you check what it actually cost you. Most of that revenue might have converted at full price anyway. Some of it might be going to customers who were never supposed to see the code in the first place. And none of your dashboards are built to tell the difference, because they stop at revenue attributed to the code and never touch the margin that code quietly ate. This is discount-code cannibalization, and it's one of the most common ways ecommerce brands overstate their real profitability.
Building an AI agent to catch this isn't about replacing your promo strategy. It's about giving your team a system that watches every code in real time, compares it against what would have happened without it, and flags the ones bleeding margin before finance finds out three months later during a P&L review.
Why discount tracking lies to you
Standard reporting treats every order with a code as incremental revenue the code "caused." That's rarely true. A repeat customer who buys from you every month doesn't need 15% off to convert — they were coming back regardless. When they use a code, you're not gaining a sale, you're giving away margin on a sale you already had.
- Codes get credit through last-touch attribution even when the customer was already in checkout before applying it
- Influencer or affiliate codes leak onto public coupon sites and get used by audiences they were never built for
- Stacked promotions (a code plus a sitewide sale) compound the discount without anyone tracking the combined margin hit
- Expired or "internal only" codes keep getting redeemed weeks after they should have stopped working
None of this shows up if you're only measuring revenue attributed to a code. You need to measure margin lost relative to a baseline of what would have happened anyway.
What the agent needs to watch
An agent that can actually catch cannibalization needs access to more than the coupon table. It needs a joined view across several data sources, updated close to real time:
- Order-level data: code used, customer ID, order value, SKUs purchased, and current COGS per SKU
- Customer history: new vs. repeat status, average order value before this transaction, purchase frequency
- Code metadata: intended audience, channel of origin, expiration date, stacking rules
- Usage velocity: redemption rate over time compared to the expected curve for that code's audience size
This is a data engineering problem before it's an AI problem. If your COGS numbers are stale, or your customer table doesn't reliably flag repeat buyers, the agent will flag noise instead of real leaks. Get the joins right first — orders to customers to product costs to code logs — before you build any logic on top.
Building the flagging logic
Once the data is joined, the agent runs a handful of concrete rules instead of a vague "watch for weirdness" model. Specificity is what makes this useful.
- Repeat-customer discount rate: if a code shows a disproportionate share of redemptions from customers who already purchase at full price on a regular cadence, flag it as cannibalizing rather than incremental
- Margin floor breach: calculate net margin per order after the discount and COGS; flag any code pushing net margin below a set threshold, whether that's 10% or breakeven, depending on the category
- Leak detection: compare actual redemption velocity against the expected curve for the code's intended audience size; a spike suggests the code escaped onto a public coupon site or got shared in a group chat
- Cohort baseline comparison: instead of assuming all code revenue is incremental, compare AOV and conversion rate for code users against a matched cohort of similar customers who didn't use a code, in the same time window
The cohort comparison is the piece most teams skip, and it's the one that actually answers the real question: would this customer have bought anyway? Without it, you're guessing. With it, you get a defensible number for how much of the discount was genuinely necessary to close the sale.
From flag to action
The agent's job is not to auto-kill codes. Promo strategy involves tradeoffs a rules engine shouldn't make alone — a leaking influencer code might still be worth keeping if it's bringing in enough new customers to offset the margin hit. The agent's job is to surface the decision with the numbers attached, not to make the call.
- Push an alert with the specific code, the dollar amount of margin bled over a defined window, and whether the pattern looks like cannibalization, leak, or intended repeat-customer promo
- Include a recommended action: cap total redemptions, restrict to new customers only, set an early expiration, or leave it alone with a documented rationale
- Log the outcome after action is taken — did revenue drop when the code was killed, or did only the discounted-and-not-incremental revenue disappear
That last point matters more than people expect. Teams get nervous about killing a "high revenue" code even when it's cannibalizing margin, because the top-line number looks scary in isolation. Tracking what actually happens after you restrict a leaking code builds the internal case for trusting the agent's flags next time.
The pipeline underneath the agent
None of this works off a spreadsheet pull once a month. You need a pipeline that keeps COGS current as suppliers change pricing, keeps customer identity resolved across channels so "repeat customer" actually means something, and ingests code usage logs fast enough to catch a leak within hours instead of after the code has already been posted everywhere. The agent is a thin layer of logic sitting on top of that pipeline — it's only as sharp as the data feeding it.
If you're already running a warehouse with clean order, customer, and cost tables, adding this agent is mostly a matter of writing the join logic and the threshold rules. If you're not, building the agent forces you to fix the underlying data gaps you were probably going to need to fix anyway.
Discount codes aren't the enemy. Blind spots in margin tracking are. An agent that flags cannibalization doesn't tell you to stop discounting — it tells you which discounts are actually buying you something and which ones are just quietly taxing sales you already had. That's the difference between a promo calendar built on guesses and one built on real numbers.