How to Power Up Your Referral Program Using Branch’s Android SDK?
By: John Tan
Tags: Startup, Mobile, Android Sdk, Deep Linking

A referral rewards system is a fantastic tool to grow more high-quality users! We can help you acquire more users by incentivizing your users to share your app with friends while integrating Branch’s SDK. Here, I will show you how to build your referral system for your new ride-sharing app.

Here you will learn how to:

Integrate Branch’s Android SDK into your mobile app Build referral links to share earned rewards with users Reward referral rules on specific events triggered Review both referred and referring user’s credits Redeem credits in your app for users

Setting up Branch’s Android SDK

import Branch’s SDK to your build.gradle in the app folder.

Configure Branch Dashboard

Create and sign up an account on dashboard.branch.io. We can follow the guide to setting up your account and dashboard here.

Configure App

Add Branch to your AndroidManifest.xml and replace the existing values with the values from the Dashboard generated.

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="io.branch.branchandroid"

android:versionCode="4"

android:versionName="1.0.0" >



<uses-permission android:name="android.permission.INTERNET" />



<application

android:largeHeap="true"

android:allowBackup="true"

android:name="io.branch.branchandroid.CustomApplication"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name">

<activity

android:name="io.branch.branchandroid.MainActivity"

android:label="@string/app_name"

android:screenOrientation="portrait"

android:theme="@style/Theme.Transparent"

android:launchMode="singleTask" >

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

<!-- Branch URI scheme -->

<intent-filter>

<data android:scheme="branchandroid" android:host="open" />

<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />

<category android:name="android.intent.category.BROWSABLE" />

</intent-filter>

<!-- Branch App Links -->

<intent-filter android:autoVerify="true">

<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />

<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="https" android:host="se-john-tan.app.link" />

</intent-filter>

</activity>



<!-- Branch init -->

<meta-data android:name="io.branch.sdk.BranchKey" android:value="@string/branch_key" />

<meta-data android:name="io.branch.sdk.BranchKey.test" android:value="@string/branch_key_test" />

<!-- Branch testing (TestMode "true" to simulate fresh installs on dev environment) -->

<meta-data android:name="io.branch.sdk.TestMode" android:value="false" />



<!-- Branch install referrer tracking -->

<receiver android:name="io.branch.referral.InstallListener" android:exported="true">

<intent-filter>

<action android:name="com.android.vending.INSTALL_REFERRER" />

</intent-filter>

</receiver>

</application>

</manifest>

Initialize and start Branch session

public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

@Override

public void onStart() {

super.onStart();

Branch branch = Branch.getInstance();

// Branch init

branch.initSession(new Branch.BranchReferralInitListener() {

@Override

public void onInitFinished(JSONObject referringParams, BranchError error) {

if (error == null) {

// params are the deep linked params associated with the link that the user clicked -> was re-directed to this app

// params will be empty if no data found

// ... insert custom logic here ...

Log.i("BRANCH SDK", referringParams.toString());

} else {

Log.i("BRANCH SDK", error.getMessage());

}

}

}, this.getIntent().getData(), this);

}



@Override

public void onNewIntent(Intent intent) {

this.setIntent(intent);

}

}

Load Branch

public class CustomerApplication extends Application {

public void onCreate() {

super.onCreate();

//enabling auto session management

Branch.getAutoInstance(this);

}

}

Build a Referral Link to Share Earned Rewards

After we have configured and initialized Branch to load, we can build a referral link to identify the specific user who shares the link and the device we are tracking from.

//Identify the device

Branch.getInstance().setRequestMetadata("device_id", android123); //Identify the user

Branch.getInstance().getRequestMetadata("user_id", john-android123);

After identifying the device and user, we can create a link that the user can share. Any of the referrals from this link will be tracked among the users. We can use this piece of code whenever we want to refer to friends for your ride-sharing app. We can build this by creating a share deep link:

LinkProperties lp = new LinkProperties()

lp.setChannel("facebook")

lp.setFeature("sharing")

lp.setStage("new user")

lp.addControlParameter("$desktop_url", "http://desktop.com/rideshare/android123") BranchUniversalObject branchUniversalObject = new BranchUniversalObject;

BranchUniversalObject.generateShortUrl(this, lp, new Branch.BranchLinkCreateListener() {

@Override

public void onLinkCreate(String url, BranchError error) {

if (error == null) {

Log.i("BRANCH SDK", "got my Branch link to share: " + url);

}

}

}); ShareSheetStyle ss = new ShareSheetStyle(MainActivity.this, "Check out This New Ride Sharing App!", "This stuff is awesome: ")

.setCopyUrlStyle(ContextCompat.getDrawable(this, android.R.drawable.ic_menu_send), "Copy", "Added to clipboard")

.setMoreOptionStyle(ContextCompat.getDrawable(this, android.R.drawable.ic_menu_search), "Show more")

.addPreferredSharingOption(SharingHelper.SHARE_WITH.FACEBOOK)

.addPreferredSharingOption(SharingHelper.SHARE_WITH.EMAIL)

.addPreferredSharingOption(SharingHelper.SHARE_WITH.MESSAGE)

.setAsFullWidthStyle(true)

.setSharingTitle("Share With");



BranchUniversalObject.showShareSheet(this, lp, ss, new Branch.BranchLinkShareListener() {

@Override

public void onShareLinkDialogLaunched() {

}

@Override

public void onShareLinkDialogDismissed() {

}

@Override

public void onLinkShareResponse(String sharedLink, String sharedChannel, BranchError error) {

}

@Override

public void onChannelSelected(String channelName) {

}

});

Reward Referral Rules and Events

We can handle referral rewards for both the referring user and the referred new onboard user. Referral rules can be set up under the referral tab in Branch’s dashboard to determine the amount of credit to allocate to the referring user (the user who share the link), referred acting user (new on-boarded user), or all acting users (both referring and referred acting users). We can set up different rules for a specific event that is triggered by each user for a different set amount of credit by the events specified.

We can reward rules for users, such as rewarding 10 points when the referring user share a link to a friend to sign up as a new user and take his or her first ride for the first time. We can name this reward rule as “signup_referral”. The referring user will be awarded when his or her friend fires the event “signup_referral”.

When the referring user’s friend fires the link, this is what’s going to happen:

Branch.getInstance(getApplicationContext()).userCompletedAction(“signup_referral”);

This will trigger the event “signup_referral” when the new user clicks on Branch’s link to install the app and sign up an account. When this happens, the referring user will earn the reward. Therefore, the referring user receives the credit when his or her friend takes their first ride, and the referred acting user can also get credit for signing up for the first time. Branch will award the credit to each or all of the user automatically, based on the event that is set in your dashboard.

Review Rewards for Both Referred and Referring User

We can track users that trigger the different rules for each event. This can be done by looking at the analytics for each users' rewards and the number of users each of the users referred to under the Referral tab in the Branch’s dashboard, which should look like this:

Redeem Credits

We should allow users to redeem credits so we can get users to make them feel that signing up for your ride-sharing app is all worth it! We would need to get the number of credits each user has so we can redeem them and have a location in your ride-sharing app to show the balance and amount of credits the user has remaining.

In order to display the number of credits a user has, we can do the following:

Branch.getInstance().loadRewards(new BranchReferralStateChangedListener() {

@Override

public void onStateChanged(boolean changed, Branch.BranchError error) {

int credits = branch.getCredits();

}

});

We can set rules for the user to redeem the credits on the Branch dashboard. If we set a rule that in order for a user to redeem credits by having a minimum of 10 credits, we can do the following:

Branch.getInstance().redeemRewards(10);

If we want to get all of the users’ history of credits to see who has the highest rewards on your customized dashboard so that everyone can keep track of the reward rankings, we can do the following:

Branch.getInstance().getCreditHistory(new BranchListResponseListener() {

public void onReceivingResponse(JSONArray list, Branch.BranchError error) {

if (error != null) {

Log.i("BRANCH SDK", "branch load rewards failed. Caused by -" + error.message)

} else {

Log.i("BRANCH SDK", list);

}

}

});

There you go! Now we got your referral program working using Branch’s Android SDK and you can start integrating and having your users share the ride-sharing app with their friends!

Let me know what you think and we can discuss this further!

John Tan