What is the proper way to create user invite codes using Branch?

Asked on March 7, 2017 in Technical.

I’ve been combing through the Branch.io Android docs and haven’t come up with how to create user invite codes. I’ve gotten the basic Branch referral system working ok, but I’d like to assign each user a custom invite code similar to what you see with Uber and Airbnb.

UberEATS Uber

My current implementation looks like this:

    mSmsBranchUniversalObject = new BranchUniversalObject()
            .addContentMetadata("userId", mUserId);

    mSmsLinkProperties = new LinkProperties()

    mSmsBranchUniversalObject.generateShortUrl(getActivity(), mSmsLinkProperties, new Branch.BranchLinkCreateListener() {
        public void onLinkCreate(String url, BranchError error) {
            if (error == null) {
                mSmsShareLink = url;

public void smsShare() {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:"));
    intent.putExtra("sms_body", getString(R.string.share_sms, mSmsShareLink));

The following implementation gets me a link that looks something like this:


But I’d like to share something like: ADAM98 (see screenshot above), and have the user enter it at checkout etc.

Now creating an invite code manually for each user isn’t much work, I could take the 1st four characters of the user’s username and append some random characters to it. But then what do I do with it? I assumed that I would simply need to pass this code to .setAlias(mUserInviteCode) on mSmsLinkProperties.

Am I on the right track here? What is the proper flow to implement this? How do you handle this invite code once received on the install?

Malcolm McFly Inc. — Developer
1 Answer(s)
Answered on March 8, 2017.

We actually used to offer a referral code feature exactly as you’ve described, but deprecated it a while back in favor of a referral link system. The reason why is actually quite interesting: our partner apps found codes unnecessary and a lot of extra work. The way Branch handles referrals is fundamentally different and far more user-friendly, so you actually don’t need to make the user enter a code at all.

Traditional app referral process

  1. Inviting User gets a code
  2. Inviting User gives a code to a friend (Invited User) and says ‘go download this app and enter my code!’
  3. Invited User hopefully downloads the app, hopefully finds out how to enter a code, hopefully enters the code correctly
  4. Inviting User gets a reward

As you can see, plenty of places where that process can go wrong.

Branch referral process

  1. Inviting User gets a link
  2. Inviting User sends the link to a friend (Invited User)
  3. Invited User clicks the link, is sent directly to the Play Store, downloads the app, and automatically triggers the referral redemption logic without any manual work
  4. Inviting User gets a reward

This works because Branch tracks the user who originally created the link, and can report back on that when the new user successfully downloads/purchases/whatever else the first time after opening the link. It is a much simpler and more seamless process, and the Branch referral infrastructure is so reliable that it ‘just works’.

Here is the documentation page for setting this up: https://dev.branch.io/features/referral-programs/