如何使用Branch.io实现引荐系统 [英] How to implement the Referral system with Branch.io

查看:172
本文介绍了如何使用Branch.io实现引荐系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照文档操作,不知道出了什么问题,我将不胜感激.

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

清单:

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

<application
    ...
    android:name="io.branch.referral.BranchApp">
    <meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_123456789asdf" />
    <activity
        ...>
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter android:label="indexed_on_SEO">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data
                android:scheme="http"
                android:host="www.schoolminder.info"
                android:pathPrefix="/home"/>
        </intent-filter>
        <intent-filter>
            <data
                android:scheme="http"
                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>
    </activity>

    <receiver
        android:name="io.branch.referral.InstallListener"
        android:exported="true">
        <intent-filter>
            <action android:name="com.android.vending.INSTALL_REFERRER" />
        </intent-filter>
    </receiver>

</application>

活动

@Override
protected void onStart() {
    super.onStart();
    Branch branch = Branch.getInstance();

    branch.initSession(new Branch.BranchReferralInitListener(){
        @Override
        public void onInitFinished(JSONObject referringParams, BranchError error) {
            if (error == null) {
                Log.i("MyApp", "deep link data: " + referringParams.toString());
            } else {
                Log.i("MyApp", error.getMessage());
            }
        }
    }, this.getIntent().getData(), this);

    String userID = new BigInteger(130, new SecureRandom()).toString(32);
    Branch.getInstance().setIdentity(userID);
}

@Override
protected void onNewIntent(Intent intent) {
    this.setIntent(intent);
}

发出邀请时的片段:

    BranchUniversalObject branchUniversalObject = new BranchUniversalObject()
            .setCanonicalIdentifier("item/12345")
            .setContentIndexingMode(BranchUniversalObject.CONTENT_INDEX_MODE.PUBLIC)
            .addContentMetadata("property1", "blue")
            .addContentMetadata("property2", "red");

    LinkProperties linkProperties = new LinkProperties()
            .setChannel("facebook")
            .setFeature("sharing");

    branchUniversalObject.generateShortUrl(getActivity(), linkProperties, new Branch.BranchLinkCreateListener() {
        @Override
        public void onLinkCreate(String url, BranchError error) {
            if (error == null) {
                link = url;
            }
        }
    });

    Branch.getInstance(getActivity().getApplicationContext()).loadRewards(new                                   Branch.BranchReferralStateChangedListener() {
        @Override
        public void onStateChanged(boolean changed, BranchError error) {
            int credits = Branch.getInstance().getCredits();
            Branch.getInstance().redeemRewards(credits);
            Log.i("MyApp", credits+"");
        }
    });

我在Branch Dashboard设置中处理了每个平台的链接.

I dealt with the links for each platform on the Branch Dashboard settings.

发生的事情是,当我将此链接发送给某人时,它会按预期打开Play商店,他可以下载它,但是我没有获得任何积分,也没有显示任何推荐用户而不是影响者,所以我一定做错了.

What's happening is, when I send this link to someone, it opens the Play Store as expected and he can download it, but I don't get the credits, and it doesn't show any Referred users not Influencers so I must be doing something wrong.

推荐答案

要弄清楚问题出在哪儿,而又不提是否收到错误或无法连接到Branch(记录标签"branch"),这是很难的,

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.

这里有一些实现技巧.首先,您应该在Application类中进行初始化,而不是在onStart()中进行初始化.如果没有Application类,则仅在onCreate()中初始化

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

    }
}

取决于您使用的是什么,可以说您正在使用推荐代码,您需要一个我看到的设置的身份.这是通过引用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()

我认为事情可能对您不利的最大原因是您确实需要异步发出请求.使用AsynTask.点击您拥有的分支网址.

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.

有关更多示例,请参阅其他文章:如何生成使用Branch.io指标推荐代码?

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

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

您可以直接与Branch联系以确认您的实施.干杯!

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

这篇关于如何使用Branch.io实现引荐系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆