How to implement the Referral system with Branch.io

[亡魂溺海] 提交于 2019-12-01 13:52:26
portfoliobuilder

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

public class YourApplication extends Application {
@Override
    public void onCreate() {

        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.

Branch branch = 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,
                new Branch.BranchReferralInitListener() {

                    @Override
                    public void onInitFinished(JSONObject jsonObject, BranchError branchError) {
                        if (FrameworkUtils.checkIfNull(branchError)) {
                            try {
                                // get and set referral code for current user
                                String 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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!