Install referrer is not tracking on android web market

只谈情不闲聊 提交于 2019-11-27 06:55:24

问题


When installing an app via the Market app on a phone, the app will correctly receive the referrer information passed to it (as described here: http://code.google.com/mobile/analytics/docs/android/#android-market-tracking).

However, when installing the same app with the same referrer via the web-based Market, the referrer information is dropped and isn't received by the app. This makes campaigns targeting your app from the web impossible to track.

Is it possible to track install referrer via android web market?


回答1:


No, it is not possible to track install referrer from the web-based Google Play store. This is a known issue with the latest SDK.

Google Play Campaign Tracking does not currently support web-to-device installs initiated from the web Play Store.




回答2:


Probably a little late here. Fortunately, this works for us to track installs that come from the web store.

receiver class:

public class OwnReceiver extends BroadcastReceiver {

public static final String ACTION_UPDATE_DATA = "ACTION_UPDATE_DATA";
private static final String ACTION_INSTALL_REFERRER = "com.android.vending.INSTALL_REFERRER";
private static final String KEY_REFERRER = "referrer";

public OwnReceiver() {
}

@Override
public void onReceive(Context context, Intent intent) {
    if (intent == null) {
        Log.e("ReferrerReceiver", "Intent is null");
        return;
    }
    if (!ACTION_INSTALL_REFERRER.equals(intent.getAction())) {
        Log.e("ReferrerReceiver", "Wrong action! Expected: " + ACTION_INSTALL_REFERRER + " but was: " + intent.getAction());
        return;
    }
    Bundle extras = intent.getExtras();
    if (intent.getExtras() == null) {
        Log.e("ReferrerReceiver", "No data in intent");
        return;
    }

    MyApplication.setReferrerDate(context.getApplicationContext(), new Date().getTime());
    //Contro.setReferrerData(context.getApplicationContext(), (String) extras.get(KEY_REFERRER));
    MyApplication.setReferrerData(context.getApplicationContext(), (String) extras.get(KEY_REFERRER));
    LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(ACTION_UPDATE_DATA));
}
}

usage in MainActivity:

private final BroadcastReceiver mUpdateReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
       someMethod(); //send received data to your method and use it your way
    }
};

someMethod where you're receiving the data:

 private void someMethod(){
    String referrerDataRaw = MyApplication.getReferrerDataRaw(getApplicationContext());

    if(referrerDataRaw.toLowerCase().contains(matchx.toLowerCase())){        
        Log.i("true",referrerDataRaw);
        Toast.makeText(getBaseContext(),"Install referrer found",Toast.LENGTH_SHORT).show();
        //postBack();
    }
    else {
        Log.i("false","no referrer found");
        Toast.makeText(getBaseContext(),"no referrer found",Toast.LENGTH_SHORT).show();
    }

}

Bonus This one if you're sending postbacks

public void postBack() {
   // String postTest = "https://play.google.com/store/apps/details?id=com.neon.myApp&referrer=utm_source=someOne&utm_medium=cpr&utm_term=testytest";
    String referrerDataRaw = MyApplication.getReferrerDataRaw(getApplicationContext());

   // Toast.makeText(this, "raw : " + postTest, Toast.LENGTH_SHORT).show();
    String[] split  = referrerDataRaw.split("=");
    String end = split[split.length - 1];

    Toast.makeText(this,  AppConstant.lin + end, Toast.LENGTH_SHORT).show();

    StringRequest strReq = new StringRequest(Request.Method.POST,
            AppConstant.lin + end, new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            Toast.makeText(getBaseContext(),"postback sent",Toast.LENGTH_SHORT).show();

        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {

        }
    });

    // Adding request to request queue
    MyApplication.getInstance().addToRequestQueue(strReq, tag_string_req);
}

Got most of the help from this kind soul on github https://github.com/SimonMarquis/Android-InstallReferrer



来源:https://stackoverflow.com/questions/10072467/install-referrer-is-not-tracking-on-android-web-market

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