Have you ever wondered if Android market sends you information at the moment of app install? Wouldn’t be nice to create custom links to your android application, including bits of information about the referrer, and send it directly to the app for processing at install? This could be a simple and accurate solution for mobile app install tracking but I’m sure you can find this useful in many ways…
With Android, you actually get this information as a broadcasted intent by android market at install time – even before opening your app.
I recently had to deal with Android app tracking. There are numerous ad networks you can join which offer mobile app tracking but depending on the method used, download and install tracking is not always easy, or not 100% accurate, not to speak about determining the referer which has led to a conversion(install).
I’ll talk more about mobile app tracking in other posts. For now, let’s focus on the solution for the above problem.
Remember, we are talking only about Android devices. Official Android documentation describes this subject more or less as Google Analytics use this method.
I will assume you have some knowledge about Android development, especially broadcast intents and broadcast receivers. Here are the steps for getting the referer:
- As you may know, url scheme for opening Android Market app and viewing, for example the app my.package.appname is as follows:
market://details?id=my.package.appname
- You can append, among others, a referrer parameter to this link, having any url encoded string as a value. For example, for the value “this is the referrer”:
market://details?id=my.package.appname&referrer=this%20is%20the%20referrer
- When this app is installed from Android market, the second sends a broadcasted intent with the action “com.android.vending.INSTALL_REFERRER“
- In order to get this intent we will build a class which extends BroadcastReceiver.
public class ReferrerCatcher extends BroadcastReceiver {
private static String referrer = "";
@Override
public void onReceive(Context context, Intent intent) {
//TODO...
}
//...
}
- In the onReceive method, you can get the referrer param by extracting the information from the received intent:
@Override
public void onReceive(Context context, Intent intent) {
referrer = "";
Bundle extras = intent.getExtras();
if(extras != null){
referrer = extras.getString("referrer");
}
Log.w("REFERRER","Referer is: "+referrer);
}
- The last thing you want to do is register this BroadcastReceiver in your manifest file with the specified intent filter. This should go between application tags!!!
<receiver android:name="my.package.ReferrerCatcher"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER"></action>
</intent-filter>
</receiver>
A few notes about this:
- As broadcast receivers work on the main thread don’t do lengthy processing here. As a matter of fact, the rule says no longer than 5 seconds of processing here, otherwise a force close dialog will appear.
- You can create a background thread in the onReceive method for processing lengthy tasks like sending referrer to a server.
- If you use more broadcast receivers for INSTALL_REFERRER action(like Google Analytics) make sure they don’t block each other. Take a look at this article where I give a solution about this.

It’s really a cool and helpful piece of info. I am happy that you shared this useful info with us. Please keep us informed like this. Thanks for sharing.
Hi,
Thank You for the tutorial.
I receive the broadcast soon after install.But at that moment the app is in stop state. So I dont receive the intent in my broadcast receiver. Let me know if you know of any workaround other that reading logs and reading browser history.
This is applicable in android 2.2
Regards,
Aasha
The market app is the one responsible for sending that broadcast intent to your app. The thing worked when installed from the market, so market app was required.
This is how it worked at least at the moment I wrote this post.
With the new market updates, I’m not sure about it, but it appears to send the broadcast message not necessarily at the moment of install, but rather later, when app is open. Not sure about it, but others including me, using this code, experienced some delays in receiving the intent, but you should try and read official forums. Maybe there’s more details on this one.
Hi,
I have already gone through most of the forums. They talk about devices with android 3.0 and above.
I tested on 3.0 and above and it comes little late not at install time as you mentioned.
But when I tried on 2.2 device its still coming at install state. Please let me know if you have some info about devices with android 2.2 or 2.3. Note that the market app installed in these devices is the updated market app.
–Aasha
This excellent website certainly has all of the info I wanted about this subject and didn’t know who to ask.