Get referrer after installing app from Android Market

82,058

Solution 1

I would try to help who, like me, fails to make install_referrer work and who don't find ANY useful information about these features.

Notes:

  1. The intent com.android.vending.INSTALL_REFERRER will be caught during the install process, not when the application starts for the first time.
  2. The referrer ...extras.getString("referrer").. is fixed but the contents can be any string value that respect the http get syntax ...referrer=thatsthevalue&thisisnot=xxx

The above code is okay, just some explanations to complete the info:

  1. Android Manifest. The <receiver> tags must be inside the <application> tags.
  2. The correct url to link the market is not the results of the famous google forms in sdk

but this one

http://market.android.com/details?id=your.application.package.name&referrer=my_referrer_finally_works_fine

Obviously, you need to follow the link from the mobile device and the only way for a complete test is to publish a test application in the market.

And a final and personal note.

I don't understand why those info are omitted completely and i hope that Google will act for detailing it.

Solution 2

This might be a little late, but you CAN test the install referrer without using Google Play, just use ADB :)

Run this from adb.exe

adb shell

am broadcast -a com.android.vending.INSTALL_REFERRER -n your.package/path.to.your.BroadcastReceiver --es "referrer" "test_referrer=test"

If you have logging setup in your BroadcastReceiver, you will see it popup in LogCat.

Hope this helps!

Solution 3

I think these answers must have been written pre-Android 3.1 - because things have changed in one import way.

The system now marks app as dormant when they are installed - they won't receive INSTALL_REFERRER or any other broadcast until the user explicitly activates the app by running it (or placing widget).

Solution 4

Okay so I found the reason why the Intent wasn't being launched. Apparently you MUST use the same parameter names as outlined here: http://code.google.com/mobile/analytics/docs/android/#referrals

You cant use your own parameter names as I was doing :S

Solution 5

Please notice that this is not the first start intent but only a android market related intent which is sent my the google android market. If you install the app through a different resource than the android market it will not fire.

Use the link which you can build there: http://code.google.com/mobile/analytics/docs/android/#android-market-tracking get the referrer from the intent and take it apart to get the different parameters

referrer = intent.getStringExtra("referrer");
Map<String, String> params = Toolbox.getQueryMap(referrer);

P.S. You don't need to read to read the deviceid/IMEI to do this, as some apps do. You shouldn't want to spy out your users.

Share:
82,058
Jake
Author by

Jake

Updated on July 05, 2022

Comments

  • Jake
    Jake almost 2 years

    I am trying to register a Broadcast Receiver that catches "com.android.vending.INSTALL_REFERRER" intents launched by Android after an app is installed from the Market.

    I am following the details here: http://code.google.com/mobile/analytics/docs/android/#referrals

    However, I cannot use Google Analytics so I have created my own solution. I have added the following to my manifest file:

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

    and created a basic BroadcastReceiver class:

    public class Receiver extends BroadcastReceiver {
    
        @Override
        public void onReceive(Context context, Intent intent) {
    
            Bundle extras = intent.getExtras();
            String referrerString = extras.getString("referrer");
    
            Log.w("TEST", "Referrer is: " + referrerString);
        }
    }
    

    However, when the app is installed the receiver doesn't seem to catch the Intent (if the Intent is even broadcast?) and I get no logging output.

    Am I going wrong somewhere or is the Market no longer launching these Intents when an app is installed?

  • emmby
    emmby over 12 years
    To test, see this answer: stackoverflow.com/questions/5890914/…
  • Barry Fruitman
    Barry Fruitman over 12 years
    INSTALL_REFERRER works as documented and there is nothing wrong with URLs generated by the "famous google forms" because they are designed be received by the GA SDK. Your code works only if you plan on posting to GA manually or integrating with another analytics platform. See the link above if you want to catch the referrer and still use the GA SDK.
  • Khan
    Khan about 12 years
    can u help me in my question stackoverflow.com/questions/10431018/…
  • Giorgos Kylafas
    Giorgos Kylafas almost 12 years
    the <receiver> tag must be inside the <application> tag. This is not explained in analytics SDK dev guide, nor does the compilation fail if you do it otherwise. So, thank you Tobia!
  • Tom
    Tom almost 12 years
    See my comment below - I believe your Note #1 is no longer true from Android >= 3.1.
  • eveliotc
    eveliotc over 11 years
  • rycfung
    rycfung over 11 years
    Any documentation to support this? I'm still failing to see any broadcast being sent before/after I launch my installed app despite opening the Play Store with the referrer param
  • rycfung
    rycfung over 11 years
    I believe the INSTALL_REFERRER doesn't work for the http protocol. At least, not anymore if it did before. Refer to this documentation, and note point #2 under known issues: developers.google.com/analytics/devguides/collection/android‌​/v2/…
  • rycfung
    rycfung over 11 years
    Can you indicate which version of android you were able to achieve this? Does this behaviour still hold for 2.3.3 & ICS (4.0)?
  • androidyue
    androidyue over 10 years
    Tom, I think it works and have tested in 4.x. Since Android 3.1 Launch controls on stopped applications has been introduced. http://developer.android.com/about/versions/android-3.1.html Note that the system adds FLAG_EXCLUDE_STOPPED_PACKAGES to all broadcast intents.However A background service or application can override this behavior by adding the FLAG_INCLUDE_STOPPED_PACKAGES flag to broadcast intents that should be allowed to activate stopped applications. Hope this could be helpful.
  • Zac Sweers
    Zac Sweers over 9 years
    @rycfung I think that only means it won't work when you click "install" from the web, not if you open the play store app from a web link
  • Pratik Dasa
    Pratik Dasa about 9 years
    @Jake Can you please tell me which parameters? Actually I have same issue like you
  • Alok Vaish
    Alok Vaish about 8 years
    on OS X key value pair of -e option need not be enclosed with double codes. So above command will be: adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n your.package/path.to.your.BroadcastReceiver --es referrer test_referrer=test
  • MikeL
    MikeL over 7 years
    You can test your app even before uploading it to the market. You can send from the shell: am broadcast -a com.android.vending.INSTALL_REFERRER -n com.yourapp.custom.referrer.receiver/.ReferrerReceiver --es "referrer" "your_referrer_data"