Generate unique referral code php

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

<?php
use Illuminate\Support\Str;
function generateReferralCode($str) {
// get random number min & max 4 digit
$randomNumber = rand(1000, 9999);
// get the first 4 character and trim whitespace
$strName = trim(substr($str, 0, 4));
// get str length
$strLen = strlen($strName);
// If str length less then 4 add missing x character by random str
$substrName = $strLen < 4 ? $strName . Str::random(4 - $strLen) : $strName;
// make name uppercase and concat with the random number
$referral = strtoupper($substrName) . $randomNumber;
return $referral;
}

If you’ve ever been invited to a referral program, you’ve come across a referral code example. Referral codes are sent to everyone who participates in the program and are key to a well-run referral marketing campaign.

What is a referral code?

A referral code (or referral tracking code) is a unique combination of numbers and/or letters used to identify the participants in a customer referral program.

Referral codes are assigned to every customer (the referrer) as soon as they join a program. Unique referral codes track and connect every step of the process, from when a customer sends a referral to whether these referrals end up making a purchase.

Most importantly, these unique referral codes automatically distribute any program rewards to the customer and referral (the referred customer).

6 referral code examples to learn from

Let’s start getting a better picture of how a referral code works by going over a few popular referral code examples. In most cases, referral codes follow a standard format, with the code found at the end of the entire referral link.

Example 1: Zipcar

A good example of a referral code is the one used by Zipcar. The company’s referral program assigns each customer their own referral link, which they can instantly start sharing with others.

As highlighted in the screenshot below, you can see the unique referral code is found at the end of the referral link.

Generate unique referral code php

Example 2: Airbnb

Airbnb is a company known for its referral program. In this referral code example, they combine the user’s name with a series of numbers to create a unique referral code.

Just like Zipcar, the referral code is added at the end of the entire referral link.

Generate unique referral code php

Example 3: Ibotta

Ibotta is another company that offers a popular refer-a-friend program. However, this referral code example is a slightly different. It’s just a unique code, without a link.

With this type of referral code, the referral (the new user) will have to download the company’s app and manually type in the code. The program also offers the option to invite friends through social media, which automatically adds the referral code to the new user’s first purchase.

Generate unique referral code php

Example 4: Dropbox

Dropbox grew to be a household name thanks to its popular referral program. It launched with a dual-sided reward structure, giving free storage space to both the customer and the referral. This motivated everyone to use the product and refer even more people – the reward was baked into Dropbox’s customer acquisition and growth!

This referral code example is a bit more complex than the previous ones we’ve seen. But since Dropbox runs a purely online product and referral program, customers don’t have to worry about manually typing in the code. All they have to do is copy and paste to send it to their friends and family.

Generate unique referral code php

Example 5: Evernote

As a freemium note-taking app, Evernote can’t really offer any discounts or freebies. Instead, its referral program rewards points that can be used toward a premium account (three referrals = 10 free months of premium).

Like Dropbox, Evernote’s referral code is rather long (so long, it got cut off in our screenshot). But since it’s also an online app, it’s still easy for users to participate in the referral program. All they have to do is copy and paste the referral code to share it with their friends.

Generate unique referral code php

Example 6: Morning Brew

Morning Brew is a daily email that doesn’t actually sell anything, but invites subscribers to share the good news with others. A subscriber’s referral status is included at the bottom of every email, along with a “Click to Share” button and clickable referral code.

Like most of the online referral code examples we’ve seen, Morning Brew’s referral code is placed at the end of a referral link. Since the referral process is completely online, subscribers may not even notice the referral code. They can simply refer others to the email in a few clicks.

Generate unique referral code php

Why would someone use a referral code?

Referral codes make the entire process easier and more efficient for everyone involved.

Rather than having to manually log every participant and reward, a referral code automates and tracks every step of your referral program.

As for your customers, if your referral programs offer a reward incentive for every successful referral (e.g., free products, cash, gift cards), a referral code makes it easy for existing customers and referrals to get their reward. By using the code when they make their first order, the reward will automatically be sent to the customer and/or referral.

Referral codes make sure your program runs as promised, and gives loyal customers and brand advocates a good experience so they can continue generating word of mouth for your business.

How does a referral code work?

Now that you know what a referral code is and why you should use them, let’s go over how these codes fit into your entire referral program process.

Step 1: Create a referral program

As you may have guessed, you’ll need to first create a referral program (also called a refer-a-friend program). For example, you can reward current customers $25 in store credit for every referral, or offer a $50 Amazon gift card for every new customer they send to your business. For more ideas, we have another article that covers everything you need to know about the best referral program examples.

Step 2: Assign a referral code to the customer

As soon as a customer joins your referral program, they should immediately be issued a unique referral code. (This is a point of high engagement with your customer, and you want to help them start referring right away!)

The referral code essentially ties the customer to every referral they send, and distributes any referral incentives they earn through the program. Referral codes also allow you to track other data about your program, so you can gauge how well it’s doing.

Step 3. Encourage customers to share the code

A big part of running a referral program is motivating your customers to share their referral code.

Thanks to all the social media platforms and messaging apps, it’s become extremely easy for people to send referral codes to their network. Some of the most popular channels are email and social media posts or messages.

But even your best customers won’t always have your referral program on top of mind. Add a small banner in the footer of your newsletters or on the thank-you page after checkout. A big part of running a successful referral program is regular promotion.

Some referral programs allow customers to share their referral code in person, usually through a printed referral card or flyer. In these cases, it’s best if the code is something simple, like the customer’s name, rather than a lengthy alphanumeric combination. This makes it easy for the referral  to remember the code when they make a purchase.

Step 4. Track or collect the referral code during purchase

The final step is to collect the referral code after every successful sale.

This is easy for online transactions, such as in ecommerce stores or subscriptions. You can simply use links and cookies to track these referrals for you.

For offline transactions, you have a few other options. You can have the referral or your staff to manually enter the code during the checkout process (which is why it’s best to keep in-person codes simple). You can also create a dedicated landing page on your site to collect the referral code during purchase. Keep in mind, you’ll still need to find a way to connect the code to the customer and the referral.

Offline or multi-step sales often have more a complex referral process. Using referral program software can make the entire set-up and experience much easier.

For more information, read our step-by-step guide on how to set up a referral tracking system and download our referral tracking spreadsheet to get your program started.

How do you make a referral code?

As a business, it’s up to you to generate referral codes for your customers. You can use software to automate the process, or you can manually create the referral codes yourself.

If you choose to do it yourself, plan to keep an updated record of all the referral codes. You can create a spreadsheet, use accounting software, a CRM, or the like. (We have another post that breaks down the step-by-step process of referral tracking.)

No matter how you decide to create your referral code, here are some best practices to follow:

  • Keep the referral code easy to read and case insensitive.
  • Try not to use O’s, zeros, capital I’s, or lower case L’s. These are easily confused with one another.
  • Personalize the referral code for the customer, not the brand.
  • Keep the referral code short enough to be memorable, but long enough to be unique (especially if customers will be sharing the code in person).
  • Keep your referral codes in the same format for each referral program.

Keep everything organized and in one place with our free referral tracking template

Is a referral code required to run a referral program?

Technically, no. But if you’re dealing with a number of customers and referrals, it’s highly recommended.

Imagine having to track of every customer who joins your program, and every referred friend they send to your business. You also need to check which referred friend actually ends up making a purchase, and immediately reward the referring customer.

Now, imagine this happening several times per customer. No matter how simple your referral marketing strategy is, there are a lot of details to take care of so it runs smoothly.

Referral codes can automate most of these steps for you. They also formalize your referral marketing program, make sure all the rewards are sent on time, and establish more customer loyalty and trust, even if you choose to not use extra graphic designs or software.

Common referral code questions

Once you launch your referral program, it’s normal to get an influx of questions about how it works or where customers can get their referral codes.

To lessen any customer confusion, we recommend providing a referral program FAQ or knowledge base. Include any screenshots or images that will help your customers better understand the referral process. (Some businesses also find it helpful to create a few FAQ explainer videos.)

Giving customers all they need to know about your referral program will not only save you hours of  customer support inquiries, it’s also a great way to refine all the smaller details of your referral program before launch. Here are a few common questions to include about referral codes:

  • Do you have a referral code?
  • How do I get my referral code?
  • Do I have to create or generate my own referral code?
  • Where do I enter my referral code?
  • How do I enter my referral code?
  • How do I share my referral code?
  • What if I forget or lose my referral code?
  • Where can I promote my referral code?
  • How does the referral promo code work?
  • Where can I retrieve my referral code?
  • Why would someone else use my referral code?
  • What do I do after receiving a referral code?
  • How can I find a referral code for registration?
  • Will I be notified when someone uses my referral code?
  • How do I use a referral code to sign up for an account?
  • What if a customer I referred forgets to use my referral code?

Note: Some of the above questions might not be relevant to your referral program. Run through the list and only include the ones that will be of help to your customers.

Referral code takeaways

As you can see, referral codes are a key component in every successful referral campaign. Without them, it will be a lot harder for marketers to track the referrals, connect these referrals to the customer who sent them, and give customers the referral rewards they deserve.

Now that you know more about referral codes, and have seen some referral code examples, it’s time to start thinking about the best ways to integrate them into your own referral program or digital marketing campaigns.

How do you get a unique referral code?

How do you make a referral code?.
Keep the referral code easy to read and case insensitive..
Try not to use O's, zeros, capital I's, or lower case L's. ... .
Personalize the referral code for the customer, not the brand..

How to create a referral code in PHP?

If you want your referrer code to be only numbers, perhaps generating a unique code is not the best idea. Instead you can save the code in a database, start from 000001 and work your way up. In this case you're guaranteed to have unique codes since you know all the previous codes.

How do I get a referral URL?

To do this, go to Dashboard > Generate Referral Link and input the destination page. Note that this address needs to begin with the same domain address you created when signing up to Refersion, also displayed on this pop-up. After entering the destination page, select an affiliate and click Generate.

What is referral code example?

In other words, a referral code is a type of special ID – a unique combination of numbers and letters that's assigned to a person, the referrer, who wants to participate in a referral program, such as a refer-a-friend program.