[Update] The information in this post might be outdated. It worked at the moment of writing, but I don’t have the time to do a new research on the subject. I leave this post as is, it might work, or it might guide others to research the subject. Probably this feature still exists in some way.
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.
If has installed in before, are you other ways to listen?
hi,
is this information updated?
and, do you happen to know how to do the same thing with iOS?
this is not updated indeed..I’ll put a notice about this, a lot has changed since this has been written. You should search web for newer solutions
the same is with iOS…I’m too lazy to update this as I’m not focused on android/iOS at the moment.
I would like to thank you for the efforts you’ve put in writing this website.
I really hope to check out the same high-grade blog posts by you in
the future as well. In truth, your creative writing abilities
has encouraged me to get my own, personal website now 😉
Is the broadcast intent sent for all other apps also?, can other apps receive it too?
Is the braodcast intent sent to other apps as well?
i think broadcast intents are received by all apps listening it
not sure about it because I haven’t checked android docs lately
I’m sure you’ll find more info there
Then how are the apps like the one which give money if you download an ad from their app and track if they are installed work ??
excellent explanation to Listen for install referrer broadcast message – get referrer on install..Android Training
I have been exploring for a bit for any high quality articles or
blog posts in this kind of area . Exploring in Yahoo I ultimately stumbled upon this site.
Studying this info So i am glad to show that I’ve a very good uncanny feeling I found out just what I
needed. I so much certainly will make sure to don?t forget this
website and provides it a look on a relentless basis.