Tracking & Attribution · September 2026 · 5 min read
Tracking Affiliate Sales by Discount Code in Shopify: A Complete Guide
Why coupon-code attribution often outperforms referral links for influencer programs, how Shopify webhooks make it work, and the edge cases that quietly lose you commissions if you don't think about them.
If your affiliate program relies entirely on referral links, you're likely missing 30–60% of attributable sales from your influencer audience. A creator with 50,000 Instagram followers doesn't get a "link in bio" click from most of their viewers — those viewers see the post, remember the code, and search your brand directly when they're ready to buy. The link never got clicked, but the sale was driven by the affiliate.
Discount-code attribution fixes this. The customer applies the code at checkout, the affiliate gets credited, and everyone wins. This guide covers how it actually works on Shopify, when it's better than link tracking, and the surprisingly common failure modes that will cost you commissions if you don't set it up carefully.
How discount-code affiliate tracking works on Shopify
The mechanism is simple enough to fit in three sentences. You create a Shopify discount code in your admin (say SARAH10). You map that code to an affiliate in your affiliate platform. When a customer checks out and applies SARAH10, Shopify's order webhook fires with the discount code in the payload, your affiliate platform sees it, and records a conversion for Sarah.
The clean part of this flow is that it doesn't depend on cookies, JavaScript, or browser state at all. The attribution lives entirely in the Shopify order payload, which arrives at your affiliate platform server-side via webhook. That means it survives Safari ITP, ad blockers, incognito mode, and customers switching devices — none of those matter when the signal is the discount code itself.
The webhook payload
When Shopify fires the Order Creation webhook, the JSON includes a discount_codes array that looks like this:
"discount_codes": [
{
"code": "SARAH10",
"amount": "10.00",
"type": "percentage"
}
]
Your affiliate platform reads this array, looks up the code in its mapping, and either finds an affiliate (and records the conversion) or doesn't (and silently moves on). That's the entire flow.
When discount codes beat referral links
Both methods have a place. Coupon codes win clearly in these situations:
- Instagram & TikTok influencers. Stories, Reels, and TikTok videos don't allow clickable links inline. The creator says "use code SARAH10 for 10% off" — that's the entire CTA. No link click happens but the attribution still works.
- YouTube reviewers. Description links exist, but only 5–10% of viewers actually click them. The code in the video itself gets remembered and used.
- Podcast hosts. "Use code POD15 at checkout" is the only practical attribution for audio. Trying to track podcast attribution via clickable links is nearly impossible.
- Long-cycle purchases. When the gap between hearing about your brand and buying is weeks, even a first-party cookie can expire or get cleared. A code the customer remembers (or saves in their notes app) outlasts any cookie.
- Cross-device shoppers. Customer hears about you on her phone, buys on her laptop two days later. Cookies don't cross devices. Codes do, because they're in her head.
Referral links still beat coupons when the affiliate is a content site or newsletter where the click is the natural CTA, and when you don't want to offer a discount at all (giving every affiliate sale a 10% off automatically erodes margin).
For most Shopify stores, running both is the right answer. Each affiliate gets a referral link and a unique coupon code. They use whichever fits the channel they're promoting on.
Setting it up step by step
- Create the discount in Shopify. Admin → Discounts → Create discount → Discount code. Set the percentage or fixed amount (10–15% is standard). Set the code (typically the affiliate's name or handle, all caps). Set usage limits if you want.
- Decide on stacking behaviour. Shopify lets you toggle whether affiliate discount codes can stack with other site-wide discounts. Almost always disable stacking — otherwise affiliates get credited when shoppers used a site-wide sale code too.
- Map the code in your affiliate platform. Most platforms have a "Coupon code" field on the affiliate's profile. Paste the exact code you created in Shopify (case-sensitive). Some platforms verify in real-time that the code exists in your Shopify store.
- Test the round trip. Open an incognito window, add an item to cart, apply the code at checkout, complete the order (use a real card, refund yourself after). Within 30 seconds, the conversion should appear in your affiliate dashboard attributed to that affiliate. If it doesn't, check the webhook delivery log in Shopify and your platform's incoming webhook log.
- Share with the affiliate. Send them their code along with their referral link. Tell them which channels each performs better on.
Edge cases that quietly cost you commissions
Five attribution failures we see repeatedly when reviewing programs:
1. Both a referral link and a coupon code on the same order
Customer clicks Sarah's link, browses, leaves. Two days later comes back to buy and uses Mike's coupon code that he posted on Instagram. Who gets the commission?
Different platforms answer this differently. Some give credit to the link (first-touch), some to the coupon (last-touch), some flag it as a conflict for you to resolve. Decide on an attribution priority before this comes up — first-touch via link or last-touch via coupon — and configure it explicitly in your platform settings. Don't let it default.
2. Codes containing reserved characters
Avoid codes with spaces, dashes, or symbols. Stick to alphanumeric. Some systems strip non-alphanumeric characters before matching, others don't, and inconsistent handling causes silent attribution misses.
3. Codes assigned to multiple affiliates
A merchant accidentally creates code SAVE10 as a site-wide discount, then later assigns the same code to an affiliate. Now every site-wide sale is being attributed (and commissioned). Always use codes that are clearly affiliate-specific — the affiliate's name or handle works.
4. Customer applies the code but the discount doesn't apply
If your code has restrictions (minimum order value, specific product collections, customer eligibility) and the cart doesn't meet them, Shopify shows "code not applicable" but does not include the code in the order's discount_codes array. The attribution gets lost. If you want to credit the affiliate for the intent even when the discount doesn't apply, you'll need a different mechanism (a cart attribute hook, generally).
5. Coupon refund handling
When a customer returns an item from an order that used an affiliate coupon, you want the affiliate's commission to reverse proportionally. Some affiliate platforms handle this automatically via Shopify refund webhooks. Others require manual reversal. Check your platform's refund behaviour before launching — paying commissions on refunded orders bleeds money slowly and is hard to catch in monthly reports.
How to think about discount-code commission rates
When you're paying both a discount to the customer and a commission to the affiliate, the maths get complicated quickly. Three approaches stores typically use:
- Commission on post-discount subtotal (standard). Customer pays $90 after a 10% discount on a $100 item. Affiliate's 15% commission is calculated on the $90 = $13.50. Most platforms default to this.
- Commission on pre-discount subtotal. Same scenario, commission calculated on the $100 = $15. More generous to affiliates, harder on margins.
- Flat commission per converted code use. Affiliate gets a fixed $5 (or whatever) every time their code is used, regardless of order value. Simpler accounting; can be a bad deal for affiliates driving large orders.
For most stores, commission on post-discount subtotal is the right balance. Set it explicitly in your platform — leaving it on the default without thinking is how most surprises happen.
Where to go from here
If you're setting up your first affiliate program from scratch, our setup guide covers the full flow and includes coupon attribution as step 5. If you're picking software, the platform handling of coupon refunds and code conflicts is one of the unflashy features that actually matters — our alternatives comparison covers the major options.
AffRef supports both link and coupon attribution out of the box, with configurable attribution priority, auto-reversing on Shopify refund webhooks, and conflict flagging when both a link and a coupon hit the same order. 7-day free trial here if you want to try it for the test setup above.