How to track Google Play Store installs in your Android app?

Detect if user installs your app via your campaign link

Mehmet Delikaya
3 min readDec 1, 2019
Photo by Bryan Hanson on Unsplash

Developing mobile apps is not always creating data structures, logics or presenting UI all the time. It is sometimes more important to retrieve meaningful analytic data to determine your user segments, funnels and their activities. If you have come across with a marketing problem and you want to see how your users come to your app via your campaign links or not, this article may be useful for you, so I will mention about how to determine it in your Android app.

When this method is required?

You or your colleagues may want to perform some ad campaigns and create different download links regarding to each campaign. If your campaign download links contain utm data like utm_source, utm_campaign, utm_content, utm_medium or utm_term and if you want to know that if your user downloaded your app via these links, you can match your user with the utm data retrieved from download link with this method.

How to implement?

It is very easy :) Only couple of codes. Firstly, open your AndroidManifest.xml file and put the below snippet inside the application tag and below the activity tag as follows;

<application
...
<activity
...
</activity>
<receiver
android:name=".CampaignReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER"/>
</intent-filter>
</receiver>
</application>

CampaignReceiver is the name that I give, you can rename it as well.

Secondly, create a BroadcastReceiver

public class CampaignReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if(extras!=null) {
String referrerString = extras.getString("referrer");
}
}
}

This CampaignReceiver will be called when your app is downloaded from Google Play Store via INSTALL_REFERRER and then you can get the referrerString inside the onReceive method from the Intent extras.

How to test?

You may have questions about testing this because I mentioned about campaigns, download links, google play store installs and etc.

Just hit your command line tool with the following lines

adb shell
am broadcast -a com.android.vending.INSTALL_REFERRER -n <your package name>/.<your broadcastreceiver name> --es "referrer" "utm_source=test_source&utm_medium=test_medium&utm_term=test_term&utm_content=test_content&utm_campaign=test_name"

What is the result?

Let me show you the result with an example with the broadcast receiver I created.

I added a log line into onReceive() method of our broadcast receiver to see the referrer string.

public class CampaignReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if(extras!=null) {
String referrerString = extras.getString("referrer");
Log.d("Referrer", referrerString);
}
}
}

Just build your app into your target device and then type the following lines in your command line tool

adb shell
am broadcast -a com.android.vending.INSTALL_REFERRER -n installtracking.com.installtrackingexampleapp/.CampaignReceiver --es "referrer" "utm_source=test_source&utm_medium=test_medium&utm_term=test_term&utm_content=test_content&utm_campaign=test_name"

This will print out the following

Broadcasting: Intent { act=com.android.vending.INSTALL_REFERRER flg=0x400000 cmp=installtracking.com.installtrackingexampleapp/.CampaignReceiver (has extras) }
Broadcast completed: result=0

It says CampaignReceiver has extras, we can see those extras on logcat by filtering Referrer and it will be shown like below

D/Referrer: utm_source=test_source&utm_medium=test_medium&utm_term=test_term&utm_content=test_content&utm_campaign=test_name

That’s it you are able to see the utm data on your logcat. You can parse the values and use them on your demand.

For the real life scenario,

If a user downloads your app via a link like https://play.google.com/store/apps/details?id=com.example.app&referrer=utm_source%3Dgoogle%26utm_medium%3Dcpc%26utm_term%3Drunning%252Bshoes%26utm_content%3DdisplayAd1%26utm_campaign%3Dshoe%252Bcampaign , you can get the utm values and match those values with your user when authenticated, and also send them to your analytics platform to see how your campaign goes.

If a user organically downloads your app by searching on Google Play Store, you will get utm_source as google-play andutm_medium as organic

If you have a Google Play Store account for your app, release your app by internal test and add your email to internal test users list. Generate a Google Play Store download link with utm values and then download the internal test apk via that link. You will be able to collect the utm values. The closest test might be this before you release your prod apk. If you get utm_source=(not%20set) and utm_medium=(not%20set), I would suggest you that you should try this with a fresh google play tester account.

To see the full implementation of this example with the utm parsing and storing, visit my github project repository https://github.com/mehmetdelikaya/InstallTrackingExampleApp

This method deprecated on March 1, 2020. You can check the new method on my next story here.

--

--