How Android app install tracking works?

北城以北 提交于 2019-11-30 14:09:42

It's quite simple actually. You click on the link with a referral (Google calls them Campaing Attribution) and this link is passed to the Google Play Store app. Then, when you install the app, the Play Store also forwards this data (campaign name, source, &c) to the app itself.

The app just needs to have a particular BroadcastReceiver (with an intent-filter for the com.android.vending.INSTALL_REFERRER action) declared in its Manifest for this to work.

It's well explained in the Google Play Campaign Attribution section of the Google Analytics documentation.

Here is an example how you can implement a custom BroadcastReceiver with INSTALL_REFERRER.

AndroidManifest.xml

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

ManyInstallTrackersReceiver.java

import com.google.android.gms.tagmanager.InstallReferrerReceiver;

public class CustomInstallTrackersReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        try {
            // Implementing Google Referrer tracker
            InstallReferrerReceiver googleReferrerTracking = new InstallReferrerReceiver();
            googleReferrerTracking.onReceive(context, intent);

            // Do something with referrer data to do your own tracker.
            Log.d("CustomInstallTrackers", "Referrer: "+intent.getStringExtra("referrer"));
        } catch(Exception e){
            e.printStackTrace();
        }
    }
}

You can test it with the following commands

$ adb shell
$ am broadcast -a com.android.vending.INSTALL_REFERRER -n com.your.package/com.your.package.CustomInstallTrackersReceiver --es "referrer" "hello%3Dworld%26utm_source%3Dshell"

From 20 November 2017, Its very simple using Google Play Referrer API

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