正确跟踪Play商店上的安装引荐 [英] Properly tracking install referrals on Play Store

查看:301
本文介绍了正确跟踪Play商店上的安装引荐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的任务:我想跟踪应用安装的引用ID,并将其传递给后端.

I have a simple task: I want to track the referral id of an app install and pass it to backend.

我做了什么:我创建了一个带有附加参数referrer的链接,并将其附加到邀请链接上.打开它后,javascript会检测该浏览器是否为Android移动浏览器,然后准备一个intent并发出对该意图的重定向.在准备意图时,从网址中提取referrer字段,并将其附加到intent中,如下所示:

What I did: I created a link with an extra parameter referrer and appended it to the invite link. When it is opened, the javascript detects if the browser is an Android mobile browser and then prepares an intent and issues a redirect to that intent. While preparing the intent, referrer field is extracted from the url and appended to the intent like this:

intent://scan/#Intent;scheme=com.example.android;package=com.example.android&referrer=4;end

这是我的BroadCastReceiver代码:

public class InstallReferrerReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        TinyDB tinyDB = new TinyDB(context);
        String referrer = intent.getStringExtra("referrer");
        tinyDB.putString(AppConstants.REFERRAL_ID, referrer);
        tinyDB.putBoolean(AppConstants.REFERRAL_SENT, false);
    }
}

因此,基于上述intent,我期望得到referrer的值是4.但是我得到的值是这个字符串utm_source=google-play&utm_medium=organic

So, what I expect to get here as the value of referrer is 4 based on the above intent. But the value that I am getting is this String utm_source=google-play&utm_medium=organic

我在做错什么,如何解决它以获取referrer字段的正确值?

What am I doing wrong and how can I fix it to get the correct value for referrer field?

修改

安装该应用程序后,在创建URL或从referrer字段提取值时,我没有任何问题.

I don't have any issues in creating the url or extracting values from referrer field once the app is installed.

在移动浏览器中单击或直接在任何浏览器中打开邀请链接后,我将使用上面的内容要么打开该应用程序(如果已安装),要么在Play商店应用程序上打开该应用程序的页面,以供用户安装".

Once the invite link is clicked through any button click or opened directly in the mobile browser, I use the above to "either open the app if it is already installed or open the app's page on Play Store app for users to install it".

问题是,我应该如何通过上述意图将邀请者字段的值从邀请链接传递到Play商店应用,以便Play商店接收该值并将其在安装时传递给应用.

The issue is, how should I pass the value of referrer field from the invite link to the Play Store app through the above intent so that the Play Store receives this value and passes it to the app when it is installed.

推荐答案

您需要正确测试它,我正在发布我的用例,希望它可以解决您的问题:)

You need to test it properly, I am posting mine use case, hope it will solve your problem :)

参考网址-

https://play.google.com/store/apps/details?id=com.mypackage&referrer=utm_source%3Dmobisoc%26utm_content%3D{transaction_id}%26utm_campaign%3D1

接收推荐的代码-

public static final String KEY_UTM_SOURCE = "utm_source";
public static final String KEY_UTM_CONTENT = "utm_content";
public static final String KEY_UTM_CAMPAIGN = "utm_campaign";
public void onReceive(Context context, Intent intent) {
    Utils.log("Referral Received");
    try {
        String referrer = intent.getStringExtra("referrer");
        if (referrer != null && !referrer.equals("")) {
            Utils.log("Referral Received - " + referrer);
            String[] referrerParts = referrer.split("&");
            String utmSource = getData(KEY_UTM_SOURCE, referrerParts);
            String utmContent = getData(KEY_UTM_CONTENT, referrerParts);
            String utmCampaign = getData(KEY_UTM_CAMPAIGN, referrerParts);
            if (utmSource != null && utmSource.equals("mobisoc")) {
                sendLogToMobisocServer(context, utmContent);
            } else if (utmSource != null && utmSource.equals("app_share")) {
                RawStorageProvider.getInstance(context).dumpDataToStorage(RaghuKakaConstants.REFFERAL_FOR, utmContent);
            }
            updateRKServerForReferral(context, utmSource, utmCampaign, utmContent);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

private String getData(String key, String[] allData) {
    for (String selected : allData)
        if (selected.contains(key)) {
            return selected.split("=")[1];
        }
    return "";
}

现在是最重要的部分测试.您可以在本地测试引荐.仅需要连接手机,即可使用adb shell打开外壳程序提示符.并播放推荐数据. 这是命令序列示例-

Now the most important part testing. You can test the referral locally. Just you need to attach your phone, open the shell prompt by using adb shell. And broadcast the referral data. Here are the command sequence example -

C:\Users\Neo\Desktop>adb shell
$ am broadcast -a com.android.vending.INSTALL_REFERRER -n com.mypackage/<className of your ReferralReceiver with package> --es "referrer" "utm_source%3Dmobisoc%26utm_content%3D{transaction_id}%26utm_campaign%3D1"

其他-

https://play.google.com/store/apps/details?id=com.mypackage& referrer = utm_source%3Dmobisoc%26utm_content%3D {transaction_id}%26utm_campaign% 3D1

只看我的链接.如果用户将通过该链接转到Playstore,然后安装该应用.然后,在首次启动该应用程序时,将自动触发onReceive方法,并且您将在Referrer =之后获取所有数据.

Just see my link. If user will go to the playstore via that link, and install the app. Then first time when the app will launch, your onReceive method will be fired automatically, and you will get all the data after referrer=.

广播-

$ am broadcast -a com.android.vending.INSTALL_REFERRER -n com.mypackage/<className of your ReferralReceiver with package> --es "referrer" "utm_source%3Dmobisoc%26utm_content%3D{transaction_id}%26utm_campaign%3D1"

要进行测试,您无需在Playstore上发布您的应用,只需将调试点放在onReceive的第一点,以调试模式启动,并触发我发布的命令序列,您将在引荐来源网址"之后获取所有数据"标签.因此,通过此操作,您可以决定在创建引荐来源链接时需要添加哪些数据.

For testing it you no need to publish your app on playstore, Just put a debug point on first point of onReceive, launch in debug mode, and fire the command sequences I have posted, you will get all the data after "referrer" tag. So by this you can decide what data you need to add while creating the referrer link.

如果需要进一步澄清,请告诉我:)

Let me know in case of more clarification you need :)

这篇关于正确跟踪Play商店上的安装引荐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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