2014-07-21 15 views
10

Próbuję wprowadzić śledzenie odsyłające w plikach do pobrania z Google Play. Przed przesłaniem do Google Play, gdy próbowałem przetestować aplikację przy użyciu poniższego skryptu, działa poprawnie i otrzymuję ciąg polecający.Śledzenie skierowań na Androida nie działa z Google Play.

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" 

Po uruchomieniu tego kodu, mam dekodowania ciąg skierowania i mój serwer zaczyna aktualizacja według napisu skierowania. Ale kiedy wdrożyłem tę aplikację do Google Play, nie otrzymuję żadnego ciągu polecającego z Google Play. Korzystam z Google Analytics V2 do śledzenia analitycznego i śledzenia poleceń.

Poniżej znajduje się mój niestandardowy program 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> 

Co należy zrobić, aby otrzymać skierowanie ciąg z Google Play?

Odpowiedz

5

można napisać prosty odbiornik:

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"); 

    } 
} 

}

następnie w oczywisty dodać tag odbiornika wewnątrz aplikacji takich jak to:

<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> 

następnie trzeba będzie wysłać parametr odsyłacza do adresu URL Google Playstore:

https://play.google.com/store/apps/details?id=you.package.name&hl=en&referrer=you otrzymasz po raz pierwszy, gdy zainstalujesz aplikację, wymagane jest pole strony odsyłającej, niezależnie od tego, jaki ciąg zostanie przekazany w polu strony odsyłającej, otrzymasz je w odbiorniku transmisji.

Powiązane problemy