1

I want to track UTM attributes to track the sources that are bringing users to my app and store them in database but after spending more than two days I have not found anything useful on google.

  • i think this solved in this link https://stackoverflow.com/questions/47855460/conversion-tracking-with-firebase-analytics-and-utm-on-android . i hope that. – Nour Eldien Mohamed Jan 16 '20 at 10:44
  • There's a library, once answered this [here](https://stackoverflow.com/questions/57733287/how-to-test-install-referrer-with-googles-installreferrer-library/57862237). – Martin Zeitler Jan 16 '20 at 11:25

1 Answers1

3

You need to register a broadcast receiver which will automatically trigger on your app first open, you can use the below example to achieve this,

public class InstallTrackersReceiver extends BroadcastReceiver {
    private static final String KEY_REFERRER = "referrer";

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i("Install Referrer", "onReceive");
        if (intent != null && !intent.getStringExtra(KEY_REFERRER).equalsIgnoreCase("")) {
            Log.i("Referrer", intent.getStringExtra(KEY_REFERRER));
        } else {
            Log.e("Install Referrer", "not found");
        }
    }
}

In your manifest, register your receiver like below,

        <receiver
            android:name="InstallTrackersReceiver"
            android:enabled="true"
            android:exported="true"
            android:permission="android.permission.INSTALL_PACKAGES">
            <intent-filter>
                <action android:name="com.android.vending.INSTALL_REFERRER" />
            </intent-filter>
        </receiver>

Updated

You can use the following adb command to test install referrer,

adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n <your.package>/.<path.up.until.your.InstallTrackersReceiver> --es "referrer" "utm_source=test_source\&utm_medium=test_medium\&utm_term=test_term\&utm_content=test_content\&utm_campaign=test_name"
Arsal Imam
  • 2,882
  • 2
  • 24
  • 35