Skip to content Skip to sidebar Skip to footer

How To Implement The Referral System With Branch.io

I've followed the documents, I don't know what's wrong, I would really appreciate some insight. Manifest: <

Solution 1:

It is tough to figure out what is wrong without you mentioning if you are receiving errors, or failing to connect to Branch (log the tag "branch"), ect.

Here are some tips though for implementation. First, you should initialize in your Application class, not in onStart(). And if you have no Application class, then initialize in onCreate() only

publicclassYourApplicationextendsApplication {
@OverridepublicvoidonCreate() {

        Branch.getAutoInstance(this); // instantiate branch

    }
}

Depending upon what you are using, lets say you are using referral codes you need an identity which I see you set. This is done referencing a Branch object.

Branchbranch= Branch.getInstance(context);

// set identity
branch.setIdentity("your user id");

After this, you can begin retrieving information such as receiving a referral code

branch.getReferralCode(null, defaultRefereeReward, null, Branch.REFERRAL_BUCKET_DEFAULT,
                Branch.REFERRAL_CODE_AWARD_UNLIMITED, Branch.REFERRAL_CODE_LOCATION_BOTH,
                newBranch.BranchReferralInitListener() {

                    @OverridepublicvoidonInitFinished(JSONObject jsonObject, BranchError branchError) {
                        if (FrameworkUtils.checkIfNull(branchError)) {
                            try {
                                // get and set referral code for current userString currentCode = jsonObject.getString("referral_code");

                                // you can store the code in a model class if want   ReferralInfoModel.setCurrentReferralCode(currentCode);

                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        } else {
                            Logger.e(TAG, branchError.getMessage());
                        }
                    }
                });

There are other methods you can use to track history such as

Branch.getCreditHistory()

I think the biggest reason things may not be working for you is that you do need to make your requests asynchronously. Use AsynTask. Hit the Branch url that you have.

For more examples refer to other posts: How to generate referral code using Branch.io Metrics?

And the documentation: https://github.com/BranchMetrics/Branch-Android-SDK#register-an-activity-for-direct-deep-linking-optional-but-recommended

And you can contact Branch directly to confirm your implementation. Cheers!

Post a Comment for "How To Implement The Referral System With Branch.io"