Google CampaignTrackingReceiver working partially

173 Views Asked by At

I have implemented custom CampaignTrackingReceiver in my application the code for the same is mentioned below:

 public class ReferrerCatcher extends WakefulBroadcastReceiver {

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

    try {
        //starting ReferralIntentService to further act on UTM source
        ComponentName comp = new ComponentName(context.getPackageName(), ReferralIntentService.class.getName());
        startWakefulService(context, (intent.setComponent(comp)));

        new CampaignTrackingReceiver().onReceive(context, intent);
    } catch (Exception e) {
    }
}
}

and i save the UTM_SOURCE in the ReferralIntentService as mentioned below:

public class ReferralIntentService extends IntentService {
private String referrer;
private Context context;

public ReferralIntentService() {
    super("ReferralIntentService");
}

@Override
protected void onHandleIntent(Intent intent) {
    try {
        Bundle extras = intent.getExtras();
        this.context = this;
        if (extras != null) {
            referrer = extras.getString("referrer");

            if (referrer.contains("%26")) {
                String array[] = referrer.split("%26");
                SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
                SharedPreferences.Editor editor = sharedPreferences.edit();
                editor.putString(Constants.UTM_SOURCE, array[0].split("%3D")[1]);
                editor.commit();

            } else {
                String array[] = referrer.split("&");
                SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
                SharedPreferences.Editor editor = sharedPreferences.edit();
                editor.putString(Constants.UTM_SOURCE, array[0].split("=")[1]);
                editor.commit();

            }

            // Release the wake lock provided by the WakefulBroadcastReceiver.
            ReferrerCatcher.completeWakefulIntent(intent);

        }
    } catch (Exception e) {


        Crashlytics.logException(e);
    }

}

My manifest with both of these looks like this:

     <receiver
        android:name=".broadcastreciever.ReferrerCatcher"
        android:enabled="true">
        <intent-filter android:priority="2147483647">
            <action android:name="com.android.vending.INSTALL_REFERRER" />
        </intent-filter>
    </receiver>

   <service
        android:name=".services.ReferralIntentService"
        android:exported="false" />

I have tested the same using following ADB command and is working as desired:

     adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n "package_name/receiver" --es referrer "tracking_id=123456789"

Now the strange thing is that in realtime its working only for around 20% of the users and in all other cases it does not hit at all.

The only source of download of my app is google play.

Kindly help to understand the gap and provide a solution if someone has faced the same problem.

Thanks for your time and help.

0

There are 0 best solutions below