Android推介跟踪不适用于Google play [英] Android referral tracking not working with Google play

查看:170
本文介绍了Android推介跟踪不适用于Google play的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试针对Google Play下载转介跟踪进行跟踪
在上传到Google Play之前,当我尝试使用下面的脚本测试应用程序时,其工作正常,并且正在接收推荐字符串。

  adb shell 
广播-a com.android.vending.INSTALL_REFERRER -n< my.myPackage> /.& lt; path.up.until.my.CustomBroadcastReceiver> --esreferrerutm_source%3Dentity%26utm_medium%3Dsocial%26utm_campaign%3Dwo_referrer%26referrerId%3D173%26entity%3Dfacebook%26email%3Dmideeshp%40email.com

运行此代码后,我将解码引用字符串,并根据引用字符串更新服务器。但是当我将这个应用程序部署到Google play时,我没有从Google play获取任何推荐字符串。我使用Google Analytics(分析)V2进行分析跟踪和引荐跟踪。

下面是我自定义的BroadcastReceiver。

  public class InstallReferrerReceiver extends BroadcastReceiver {
private static final String TAG =InstallReferrerReceiver;
$ b $ @Override
public void onReceive(Context context,Intent intent){

HashMap< String,String> values = new HashMap< String,String>();
if(intent.hasExtra(referrer)){
Toast.makeText(context,Inside app refferal,5000).show();

String url = intent.getStringExtra(referrer);
final String referrer = URLDecoder.decode(url,UTF-8);
String referrers [] = referrer.split(&);
int i = 0;
for(String referrerValue:referrers){
String keyValue [] = referrerValue.split(=);
values.put(URLDecoder.decode(keyValue [0],UTF-8),
URLDecoder.decode(keyValue [1],UTF-8));
Log.i(+ i,keyValue [0] +=+ keyValue [1]);


新的AsyncTask< String,String,JSONObject>(){

@Override
保护void onPreExecute(){
super .onPreExecute();
}

@Override
protected JSONObject doInBackground(String ... params){
// TODO自动生成的方法存根
字符串referrerUrl = ?MyserverUrl行动= storerefer和放大器; +推荐人;
Log.i(purl address,referrerUrl);
JSONObject json = RestJsonClient.connect(referrerUrl);
返回json;
}

@Override
保护无效onPostExecute(JSONObject结果){
// TODO自动生成方法存根
尝试{
if (result == null){
Log.i(json null,12);
} else {
字符串状态,错误;
status = result.getString(status);
error = result.getString(error);
if(status.equals(success)){
Log.i(referrer,referrer status success);

if(status.equals(failure)){
Log.i(referrer,referrer status failure);

$ b $ catch(JSONException e){
e.printStackTrace();
} catch(Exception e){
e.printStackTrace();
}
super.onPostExecute(result);
}
} .execute();

catch(例外e){
}
}

AndroidManifest.xml

 <?xml version =1.0encoding =utf-8?> ; 
< manifest xmlns:android =http://schemas.android.com/apk/res/android
package =my.package.name
android:versionCode = 4
android:versionName =1.2.1>

支持屏幕
android:anyDensity =true
android:largeScreens =true
android:normalScreens =true
android:resizeable =true
android:smallScreens =true/>

< uses-sdk
android:minSdkVersion =8
android:targetSdkVersion =19/>

< uses-feature
android:name =android.hardware.telephony
android:required =false/>
< uses-feature
android:name =android.hardware.touchscreen
android:required =false/>
< uses-feature
android:glEsVersion =0x00020000
android:required =true/>

<使用权限android:name =android.permission.INTERNET/>
< uses-permission android:name =android.permission.ACCESS_NETWORK_STATE/>
< uses-permission android:name =android.permission.WRITE_EXTERNAL_STORAGE/>
< uses-permission android:name =android.permission.RECEIVE_BOOT_COMPLETED/>
<使用权限android:name =android.permission.READ_CONTACTS/>
<使用权限android:name =android.permission.READ_PHONE_STATE/>
< uses-permission android:name =android.permission.RECEIVE_SMS/>
< uses-permission android:name =android.permission.SEND_SMS/>
<使用权限android:name =android.permission.GET_ACCOUNTS/>
<使用权限android:name =android.permission.WAKE_LOCK/>
< uses-permission android:name =my.package.name.permission.C2D_MESSAGE/>
< uses-permission android:name =com.google.android.c2dm.permission.RECEIVE/>
< uses-permission android:name =android.permission.ACCESS_NETWORK_STATE/>
< uses-permission android:name =android.permission.VIBRATE/>
< uses-permission android:name =android.permission.RECEIVE_SMS/>

< permission
android:name =my.package.name.permission.C2D_MESSAGE
android:protectionLevel =signature/>

< application
android:allowBackup =true
android:icon =@ drawable / ic_launcher
android:label =@ string / app_name
android:theme =@ android:style / Theme.Black.NoTitleBar>
< activity
android:name =my.package.name.Splash
android:configChanges =orientation | keyboardHidden | screenSize
android:label =@ string / app_name
android:windowSoftInputMode =stateHidden>
< intent-filter>

< category android:name =android.intent.category.LAUNCHER/>
< / intent-filter>
< / activity>

< receiver
android:name =my.package.name.InstallReferrerReceiver
android:exported =true>
< intent-filter>
< / intent-filter>
< / receiver>

< receiver
android:name =com.google.android.gcm.GCMBroadcastReceiver
android:permission =com.google.android.c2dm.permission.SEND >
< intent-filter>

< category android:name =my.package.name/>
< / intent-filter>
< / receiver>

< service android:name =my.package.name.GCMIntentService/>
< / application>



我该如何获取您可以编写这个简单的收件人:

  public class DetectInstall extends BroadcastReceiver {

private String referrerId;
$ b $ @Override
public void onReceive(Context context,Intent intent){

if((null!= intent)
&&( intent.getAction()。equals(com.android.vending.INSTALL_REFERRER))){
Log.e(Message,App is getting first first time ..);
referrerId = intent.getStringExtra(referrer);


$ b $ / code $ / pre>

}



然后在清单中添加接收器标签,如下所示:

 < application 

android:hardwareAccelerated =true
android:icon =@ drawable / ic_bmg
android:label =@ string / app_name
android:screenOrientation = portrait
android:theme =@ style / AppTheme>
< receiver
android:name =。DetectInstall
android:exported =true>
< intent-filter>
< / intent-filter>
< / receiver>

然后您需要将referrer参数发送到google playstore网址如下所示:



https ://play.google.com/store/apps/details?id = you.package.name& hl = en& referrer = you 将在安装应用程序时首次获得此文件。



引用者字段是必需的,无论您传入引荐者字段中的任何字符串,您都将在广播收件人中获得它。


I am trying to implement referral tracking on downloads from the Google play. Before uploading to Google Play, when I tried testing the app using below script, its working fine and i am getting referral string.

adb shell 
am broadcast -a com.android.vending.INSTALL_REFERRER -n <my.myPackage>/.<path.up.until.my.CustomBroadcastReceiver> --es "referrer" "utm_source%3Dentity%26utm_medium%3Dsocial%26utm_campaign%3Dwo_referrer%26referrerId%3D173%26entity%3Dfacebook%26email%3Dmideeshp%40email.com"

After running this code, I am decoding the referral string and my server getting updated according to the referral string. But when I deployed this app to Google play, I am not getting any referral string from Google play. I am using Google Analytics V2 for both analytic tracking and referral tracking.

Below one is my custom BroadcastReceiver.

public class InstallReferrerReceiver extends BroadcastReceiver {
private static final String TAG = "InstallReferrerReceiver";

@Override
public void onReceive(Context context, Intent intent) {

    HashMap<String, String> values = new HashMap<String, String>();
    try {
        if (intent.hasExtra("referrer")) {
            Toast.makeText(context, "Inside app refferal", 5000).show();

            String url = intent.getStringExtra("referrer");
            final String referrer = URLDecoder.decode(url, "UTF-8");
            String referrers[] = referrer.split("&");
            int i = 0;
            for (String referrerValue : referrers) {
                String keyValue[] = referrerValue.split("=");
                values.put(URLDecoder.decode(keyValue[0], "UTF-8"),
                        URLDecoder.decode(keyValue[1], "UTF-8"));
                Log.i("" + i, keyValue[0] + "=" + keyValue[1]);
            }

            new AsyncTask<String, String, JSONObject>() {

                @Override
                protected void onPreExecute() {
                    super.onPreExecute();
                }

                @Override
                protected JSONObject doInBackground(String... params) {
                    // TODO Auto-generated method stub
                    String referrerUrl = "MyserverUrl?action=storerefer&" + referrer;
                    Log.i("purl address", referrerUrl);
                    JSONObject json = RestJsonClient.connect(referrerUrl);
                    return json;
                }

                @Override
                protected void onPostExecute(JSONObject result) {
                    // TODO Auto-generated method stub
                    try {
                        if (result == null) {
                            Log.i("json null", "12");
                        } else {
                            String status, error;
                            status = result.getString("status");
                            error = result.getString("error");
                            if (status.equals("success")) {
                                Log.i("referrer", "referrer status success");
                            }
                            if (status.equals("failure")) {
                                Log.i("referrer", "referrer status failure");
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    super.onPostExecute(result);
                }
            }.execute();
        }
    } catch (Exception e) {
    }
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.package.name"
android:versionCode="4"
android:versionName="1.2.1" >

<supports-screens
    android:anyDensity="true"
    android:largeScreens="true"
    android:normalScreens="true"
    android:resizeable="true"
    android:smallScreens="true" />

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />

<uses-feature
    android:name="android.hardware.telephony"
    android:required="false" />
<uses-feature
    android:name="android.hardware.touchscreen"
    android:required="false" />
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="my.package.name.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />

<permission
    android:name="my.package.name.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Black.NoTitleBar" >
    <activity
        android:name="my.package.name.Splash"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:windowSoftInputMode="stateHidden" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <receiver
        android:name="my.package.name.InstallReferrerReceiver"
        android:exported="true" >
        <intent-filter>
            <action android:name="com.android.vending.INSTALL_REFERRER" />
        </intent-filter>
    </receiver>

    <receiver
        android:name="com.google.android.gcm.GCMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="my.package.name" />
        </intent-filter>
    </receiver>

    <service android:name="my.package.name.GCMIntentService" />
</application>

What should I do to get referral string from Google Play ?

解决方案

you can write this simple reciever:

public class DetectInstall extends BroadcastReceiver{

private String referrerId;

@Override
public void onReceive(Context context, Intent intent) {

    if ((null != intent)
            && (intent.getAction().equals("com.android.vending.INSTALL_REFERRER"))) {
        Log.e("Message", "App is getting installed first time..");
        referrerId = intent.getStringExtra("referrer");

    }
}

}

then in manifest add the receiver tag inside the application like this :

<application

    android:hardwareAccelerated="true"
    android:icon="@drawable/ic_bmg"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:theme="@style/AppTheme" >
    <receiver
        android:name=".DetectInstall"
        android:exported="true" >
        <intent-filter>
            <action android:name="com.android.vending.INSTALL_REFERRER" />
        </intent-filter>
    </receiver>

then you will need to send the referrer parameter to the google playstore URL Like this :

https://play.google.com/store/apps/details?id=you.package.name&hl=en&referrer=you will get this first time when you install app

referrer field is required, whatever string u pass in referrer field you will get it in the broadcast reciever

这篇关于Android推介跟踪不适用于Google play的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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