A discount code tells you where a sale came from. A referral code tells you who sent it. That single difference is why referral codes are worth understanding before you launch one.
In this guide, we'll cover what a referral code actually is, how it works step by step, a few real ecommerce examples you can learn from, and how to set one up on your own store, whether you use an app or build it into checkout yourself. Also, we'll get into the parts most guides skip: how to stop people from gaming it, and how to tell if it's actually working.
What Is a Referral Code?
A referral code is a unique string of characters, usually letters and numbers, that identifies who referred a new customer. Think `SARAH20`, `GET15`, or `JAMIE-R3F`. The code looks a lot like a regular coupon, but it's doing something a coupon can't: it's linked to an individual, so every sale made with it is attributed back to whoever shared it.
That attribution is the whole point. When a friend checks out with Sarah's code, your store records two things at once - the discount the friend used, and the fact that Sarah is the one who sent them. Both people can then be rewarded for the introduction.
A referral code can take a few shapes:
- A name-based code like `SARAH20`, which feels personal and is easy to share out loud.
- A generic code like `FRIEND15`, where everyone gets the same code, but it's still tracked to the sharer's account behind the scenes.
- A coded string like `R3F-8K2P`, used when you want each code to be unique and hard to guess.
Before we go further, it helps to clear up two comparisons people constantly mix up: referral codes versus referral links, and referral codes versus discount and affiliate codes.
Referral Code vs. Referral Link
These two do the same job - they just travel differently. A referral code is something a customer types in, making it great for sharing in person, over the phone, or anywhere a clickable link won't work. A referral link carries the same attribution but does so via a URL, so the friend clicks instead of typing, and the code is applied automatically at checkout.
Most modern referral programs hand customers both and let them pick. The link is lower-friction online; the code travels better offline. You rarely have to choose one over the other.
Referral Code vs. Discount Code vs. Affiliate Code
This is where the real confusion lives, because all three can produce a discount at checkout. The difference is what they're attached to and who they're built for.
| **Tied to** | An existing customer | A campaign or sale | A partner or creator |
|---|---|---|---|
| Who shares it | Your customers | Your marketing team | External affiliates |
| Tracks | *Who* referred the buyer | *Where* the sale came from | Which partner drove the sale |
| Reward sides | Both the referrer and the friend | The buyer only | The affiliate (usually a commission) |
| Best for | Turning customers into advocates | Running a time-boxed promotion | Scaling reach through paid partners |
The takeaway is simple. A discount code is one-sided and tied to a campaign. An affiliate code pays an outside partner a commission. A referral code is two-sided and tied to a real customer — it rewards the person who shares and the friend who buys. That two-sided, person-linked design is exactly what makes referral codes worth setting up, and it's why the rest of this guide focuses on them.
How a Referral Code Works
A referral code seems simple to the customer, but a few things happen behind the scenes to ensure the right person is credited. Here's the full loop, from the moment a code is created to the moment both people get rewarded.
- A code is created and assigned. When a customer joins your program (or sometimes right after their first order), your store generates a unique code and ties it to their account. This is the link that makes attribution possible later.
- The customer shares it. They send the code or link to a friend — by text, email, social, or just saying it out loud. Because it's theirs, anything bought with it traces back to them.
- The friend redeems it. The friend enters the code at checkout or clicks the link, and it is applied automatically. They get their reward, usually a discount on their first order.
- Your store validates and attributes the sale. The system checks that the code is real, that it meets any conditions you've set (like a minimum order), and that it's a genuinely new customer. Then it records the referrer behind the sale.
- Both sides get rewarded. Once the order clears, the referrer earns their reward - store credit, points, a discount, or a free product — and the friend keeps theirs. The loop is complete, and the referrer now has a reason to share again.
Notice that step four is doing quite important work. Validation is where a good program blocks self-referrals and fake orders, and determines when a reward unlocks. We'll come back to that in the fraud section, because it's the difference between a program that grows your store and one that just leaks budget.
To make this less abstract, let's look at how a few real stores use referral codes.
Referral Code Examples That Work for Ecommerce
The best way to understand referral codes is to see how real brands structure them. Here are some examples that you can learn from.
1. Rothy's - a symmetrical give-and-get
Rothy's, the direct-to-consumer footwear brand, runs one of the cleanest referral structures you'll find: the friend gets $20 off their first order with a cart over $50, and the referrer earns a $20 reward code once that order goes through, also usable on a cart over $50. Both sides get the same thing.
Why the mechanics work: The matched $20-for-$20 reward is easy to explain and feels fair, which makes it easy to share. The $50 minimum on both ends is the smart part - it keeps the program from being drained by tiny throwaway orders.
One thing to watch: A flat $20 fits Rothy's price point. If your average order is much lower, a percentage discount may better protect your margins.
2. MeUndies - an asymmetric reward with a minimum
MeUndies, the direct-to-consumer underwear brand, gives each side a different reward: the friend takes 20% off their first order, and the referrer earns $20 in store credit once that order ships and clears a $12 minimum. The two halves don't match, and that's deliberate.
Why the mechanics work: A percentage-off discount feels generous to a first-time buyer, while store credit pulls an existing customer back to spend again. The $12 minimum quietly blocks the most common abuse - people self-referring with a tiny order just to farm credit.
One thing to watch: Store credit only motivates if your catalog is broad enough to spend it on. For a single-product store, a straight discount may convert better.
3. Casper - a percentage reward with a yearly cap
Casper, the direct-to-consumer mattress brand, runs a generous give-and-get - the friend gets 30% off, and the referrer earns a reward (typically a gift card) for each verified referral. The detail worth copying is the ceiling: an advocate can earn up to $599 in rewards per calendar year.
Why the mechanics work: The annual cap keeps the program generous for normal customers while stopping a handful of power-sharers from quietly draining your budget. It's a guardrail that lets you offer a big reward without unlimited exposure.
One thing to watch: Thirty percent off a mattress fits Casper's margins. Check yours before matching a discount that size - a percentage that works for one category can sink another.
Across all three, the same pattern holds: reward both sides, tie the payout to a real purchase, and build in a guardrail — a minimum order, or a yearly cap — so the program can't be drained. If you want a deeper bank of examples across industries, we've broken down two dozen of them in our guide to referral program examples. For now, let's get into building your own.
How to Create a Referral Code for Your Store
There are two realistic paths here, depending on whether you'd rather set this up in an afternoon or build it into your own checkout. We'll cover both, then share a few tips that apply either way.
Option 1: Use a Referral or Loyalty App (No-Code)
For most Shopify merchants, this is the practical choice. A referral app handles the parts that are genuinely fiddly to build yourself: generating unique codes for every customer, tracking who referred whom, validating orders, and releasing rewards automatically. You set the rules; the app runs the loop.
A typical setup looks like this:
- Install the app and connect it to your store.
- Set the rewards — what the friend gets, and what the referrer earns.
- Add the conditions — a minimum order value, who qualifies as a new customer, and when the reward unlocks.
- Place the widget where customers will see it: the post-purchase page, their Customer Account, or a thank-you email.
This is the part of the workflow Joy is built for. As a Shopify-native loyalty and referral app, it generates per-customer referral codes, lets you set the reward rules without touching code, and ties referrals into the same points system your customers already earn from. Because it runs natively, it speaks Shopify — orders, tags, Customer Accounts — so the data stays clean. It's one option among several, but if you're already thinking about loyalty, keeping referrals in the same place saves you from stitching two tools together.
Option 2: Build It Into Your Checkout or Signup Flow
If you have development resources and want full control, you can build referral codes directly into your store. This usually means generating a unique code per customer, storing the referrer-to-buyer relationship in your own database or in Shopify metafields, validating the code at checkout, and triggering rewards through Shopify Flow or a custom script once an order is confirmed.
The upside is total control over the logic and the look. The honest tradeoff: you're now maintaining attribution, fraud checks, and reward fulfillment yourself, and those edge cases add up fast. Most stores find that an app pays for itself here - but if your program has unusual rules, building it can be the right call.
Tips for Creating Effective Referral Codes
Whichever path you take, a few choices make a referral code work better in practice:
- Keep code short and readable. `SARAH20` gets shared out loud; `R3F-8K2P-99XQ` does not. Personal, memorable codes travel further.
- Reward both sides. A code that only benefits the friend gives your customer no reason to share. Two-sided rewards are what keep the loop turning.
- Tie the reward to a real order. Release the referrer's reward after the friend's order clears, not when they sign up. This protects you and rewards real revenue.
- Decide on expiry deliberately. A gentle expiry can nudge action, but too short and it feels stingy. Match it to how long your customers normally take to buy.
- Surface the code where it'll be seen. The post-purchase moment, when a customer is happiest, is the single best place to show a referral code.
Setting the program up is the easy part, though. Keeping it clean is where some stores get caught out, so let's talk about abuse.
How to Prevent Referral Code Fraud
Any program that gives money away will eventually attract people trying to game it. Referral codes are no exception, but the common abuse patterns are well understood, and most are easy to design out from the start.
The three you'll see most often:
- Self-referral. Someone uses their own code on a second account to collect both rewards. The fix is to block rewards when the referrer and buyer share an email, address, or payment detail, and to only count genuinely new customers.
- Fake or throwaway orders. People place a tiny order, claim the reward, then cancel or refund. A minimum order value, plus releasing the reward only after the refund window closes, shuts this down.
- Public code dumping. A code meant for friends ends up posted on a coupon site, turning your referral program into a public discount. Per-customer codes and reasonable usage limits keep this contained.
The thread running through all three fixes is the same: control when and under what conditions a reward unlocks. This is where doing it through an app helps, because the rules are built in rather than having to code and maintain them. With Joy, for example, its rule engine lets you hold a referral reward until the order clears and confirm the buyer is a new customer before anything pays out, so the obvious abuse routes are closed by default.
A clean program is good. But you still need to know whether it's actually doing anything, so let's look at how to measure it.
How to Measure Referral Performance
A referral program is easy to launch and easy to ignore once it's live. To know whether yours is pulling its weight, track a few numbers over time rather than a single vanity metric. Here are the four that matter, with the formulas, so you can calculate them from your own data rather than relying on a benchmark.
Referral participation rate tells you how many of your customers actually share. If almost nobody is sharing, the problem is visibility or the reward, not the program itself.
Participation rate = (Customers who shared a code ÷ Total eligible customers) × 100
Referral conversion rate tells you how persuasive a referral is once it's shared. Referred friends usually convert well, because they arrive with a recommendation already in hand.
Conversion rate = (Referred orders ÷ Referral codes shared) × 100
Share of revenue from referrals tells you how much the program actually contributes. This is the number to watch month over month to see if it's growing.
Referral revenue share = (Revenue from referred orders ÷ Total revenue) × 100
Referral CAC tells you what a referred customer costs you, which is the total reward you paid out per new customer acquired. Compare it to what you spend acquiring customers through ads — referrals are often cheaper.
Referral CAC = Total reward cost ÷ New customers acquired through referrals
One honest note on benchmarks. You'll see a lot of impressive-sounding referral statistics floating around - "people trust recommendations X% of the time," and so on. A surprising number of those trace back to studies from 2011 and 2012 that get relabeled every year, so we're not going to hand you one here. Your own numbers, tracked over a few months, will tell you more than any recycled industry average. Watch the trend, not the absolute, and adjust your reward or placement when participation stalls.
With the measurement side covered, let's close out the most common questions.
Frequently Asked Questions
What is a referral code?
A referral code is a unique string of letters and numbers tied to a specific customer. When they share it, and a friend buys, your store can see exactly who made the introduction and reward both people. It looks like a coupon but tracks who sent the sale, not just where it came from.
How is a referral code different from a promo code?
A promo or discount code is one-sided and tied to a campaign — anyone who has it gets the same deal, and only the buyer benefits. A referral code is two-sided and tied to an individual customer, so it rewards both the person who shares it and the friend who uses it.
Where do I get a referral code?
As a shopper, you usually find your code in your account, in a post-purchase message, or in a "refer a friend" section after you buy. As a merchant, you generate codes for your customers either through a referral app or by building the logic into your store.
Do referral codes expire?
They can — it's up to the merchant. Many programs add a gentle expiry to encourage action, while others leave codes open-ended. If you're running a program, match the expiry to how long your customers normally take between purchases.
Can I create a referral code without coding?
Yes. A referral or loyalty app generates unique codes, tracks attribution, and automatically releases rewards, with no development required. Building it yourself is an option if you want full control, but for most stores, an app is faster and easier to maintain.
Should the referrer or the friend get the reward?
Both. A one-sided reward gives your customer little reason to share. Two-sided programs - where the friend gets a discount, and the referrer earns credit or points - are what keep the loop running.
How do I stop people from abusing referral codes?
Block rewards when the referrer and buyer share details such as an email or address, require a minimum order, count only new customers, and release the reward after the refund window closes. Most referral apps include these controls by default.
Do I need a separate app for referrals if I already have a loyalty program?
Not necessarily. Some loyalty apps, including Joy, handle referrals and points in the same place, so referral rewards can feed straight into the points your customers already earn. Keeping both in a single tool saves you from having to sync two systems.
In conclusion
A referral code is a small mechanism with an outsized payoff: it turns one happy customer into the introduction that brings the next. Set the reward, add a guardrail, place the code where customers can see it, and let the loop run.
If you'd rather not build it from scratch, see how a referral code works alongside points in one place — explore Joy. And if you're still deciding what to offer, browse our referral program examples by industry first.














