Get referrer after installing app from Android Market
Asked Answered
V

10

73

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?

Vento answered 4/11, 2010 at 1:28 Comment(6)
I answered this same question here #3817530Gardia
It's worth noting that, due to a bug in the newest version of the Android Market app, the referrer string does not currently work. You can star the bug here to help draw Google's attention to it: code.google.com/p/android/issues/detail?id=19247Prater
Does anyone knows if there is a way to receive this broadcast when OTHER apps, beside mine, is being installed?Talkingto
How do you do the opposite? Meaning, how do you use an intent on an APK file, to mark it as the referrer of your choice?Telegu
Can you please tell me which parameters? Actually I have same issue like you.Papaya
this can help. use adb. developers.google.com/analytics/solutions/…Fluctuant
B
57

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.

Burrus answered 14/12, 2010 at 13:16 Comment(5)
To test, see this answer: #5891414Staceestacey
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.Polloch
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!Conchitaconchobar
See my comment below - I believe your Note #1 is no longer true from Android >= 3.1.Gruver
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"Garrard
B
22

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!

Bala answered 9/6, 2015 at 13:18 Comment(1)
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=testAntimasque
G
6

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).

Gruver answered 13/9, 2012 at 15:57 Comment(2)
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 paramGraybill
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.Cogen
V
5

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

Vento answered 4/11, 2010 at 1:43 Comment(3)
can u help me in my question #10431518Gynecocracy
Updated link developers.google.com/analytics/devguides/collection/android/…Krute
@Vento Can you please tell me which parameters? Actually I have same issue like youPapaya
S
2

I agree that Google's documentation isn't the best. However, I've only been able to get the intent to fire by actually uploading the app to the Market Place and then downloading/installing it. The intent does launch immediately after the download/instal - the user does not have to start the app. I'm using this to start a background service as well.

Someday answered 28/3, 2011 at 21:26 Comment(1)
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)?Graybill
B
2

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.

Brazilein answered 15/6, 2011 at 18:53 Comment(0)
L
2
1) Broadcast receiver

public class InstallReferrerReceiver extends BroadcastReceiver {

    String referrer = "";

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction() != null) {
            if (intent.getAction().equals("com.android.vending.INSTALL_REFERRER")) {

                Bundle extras = intent.getExtras();
                if (extras != null)
                {
                    referrer = extras.getString("referrer");

                    Log.e("Receiver Referral", "===>" + referrer);                  
                    PrefUtils.putPrefString(context, PrefUtils.PRF_REFERRER, referrer);

                    /*
                    If you want split username and code use below code...
                    for ex referrer="username12345678890"
                    if(referrer!=null)
                    {
                        String[] referrerParts = referrer.split("(?<=\\D)(?=\\d)");
                        String strName = referrerParts[0];
                        String strCode = referrerParts[1];

                        Log.e("Receiver Referral Code", "===>" + strName);
                        Log.e("Receiver Referral Name", "===>" + strCode);

                        PrefUtils.putPrefString(context, PrefUtils.PRF_REFERRER_CODE, strName);
                        PrefUtils.putPrefString(context, PrefUtils.PRF_REFERRER_NAME, strCode);
                    }*/
                }
            }
        }
    }
}

2) Define a receiver in your app manifest.in which com.android.vending.INSTALL_REFERRER 

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

3) Test your app configuration running this command

adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n package_name/broadcast_receiver_path_with_packagename --es referrer "username1234567890"
Latterly answered 28/9, 2018 at 6:59 Comment(0)
B
1

Actually there could be any links like market://... or http://market... either work fine. Also it doesn't matter what kind of parameters will be in the referrer field. It works fine with any text in there.

The main issue that this event type "com.android.vending.INSTALL_REFERRER" doesn't send by broadcast. This event goes ONLY into the just installed application.

UPD: And there only one way to test it - deploy your App into the Market and then install it on the phone.

Bachelorism answered 3/5, 2011 at 5:52 Comment(2)
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/…Graybill
@Graybill 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 linkSoileau
A
1

Use Google Play Referrer API (from 20 Nov 2017) very easily and securely as i answered here

Aeromedical answered 20/4, 2018 at 10:2 Comment(0)
F
0

com.android.vending.INSTALL_REFERRER is not broadcast anymore since March 2020. See this SO answer for details and alternatives.

Flirtation answered 22/11, 2021 at 14:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.