Testing Google Play Install Referrer Library
Asked Answered
G

6

87

I'm looking to migrate from listening to the Play Store's INSTALL_REFERRER intent, to using the new Google Play Install Referrer Library.

I am struggling to find a way to test this new library without first having to add my app to the Play Store. When listening for the INSTALL_REFERRER intent via a BroadcastReceiver, I could test by manually sending a broadcast via the Activity Manager to mimic the behavior. That is to say, I could test by following these steps from Google.

Does there also exist a way I can test this new library without having to first put my app on the Play Store?

Glume answered 28/2, 2018 at 23:0 Comment(4)
Plus 1 for this. I also need a way to test this.Anorak
Have you resolved your issue? do you have some working code for this? from what place have you start tracking your first installation? Have you added a broadcast receiver for listening to Intent.ACTION_PACKAGE_FIRST_LAUNCH or just wrote code in mainActivity?Toddle
@NirajGupta You can try to use my solution below.Toddle
Found this answer for a similar question very helpful: https://mcmap.net/q/243421/-how-to-test-google-play-referrer-api-before-publishing-in-google-play-storeMucous
B
64

There's one old hack to test this.

Steps:

  1. Start Google Play on the device using campaign link, for example, https://play.google.com/store/apps/details?id=com.test.test_project&referrer=utm_source%3Dtest_source%26utm_medium%3Dtest_medium%26utm_term%3Dtest-term%26utm_content%3Dtest_content%26utm_campaign%3Dtest_name (You can use google play generator: https://developers.google.com/analytics/devguides/collection/android/v3/campaigns#google-play-url-builder)

  2. DON'T TAP ON INSTALL BUTTON

  3. Install your test build using adb. adb install -r app-debug.apk

Google Play will be returning your test campaign now.

Banshee answered 21/2, 2020 at 16:11 Comment(10)
Yes it is working , But be careful utm_source will give you (not%20set) if your link didn't redirect you to google play app directly .Sedgewick
Once you insall via adb you should see the Install button change to an "Open" button. You have to open the app via the button (not using adb am) to get the UTM payload. If you don't see the button text change it is because the application id of the installed app is not the same as the one in play store. This is likely if you release a 'prod' flavor of your app but are working with a 'debug' flavor, temporarily change your debug app's application id and the above should work!Hardworking
Yes, this work but why install from adb?Permanence
Build + install from AS UI creates an APK with android:testOnly flag, which cannot be tested in that regard. only using gradle's assembleDebug task then install manually with adb worked (for me at least).Felicle
@ShlomiKatriel Toda Achi!Permatron
Be careful which email you are signed into on play store and on test device. If you are logged into your developer email (email on app listing), you will get (not set) for utm source and medium. So make sure you are signed into a different email on play store and on the device. The email you use has to be included in your list of testers if you are testing using Alpha or Beta channels.Recoup
instead of step 3, we can simply install from AS by pressing the green run button too. not sure why it didn't worked for @ShlomiKatriel, can't verify, but AS dolphin runs :app:assembleDebug and generates referral data for me when pressing the green run buttonCila
I couldn't use this way to test when I needed to update the app (so the previous version of the app exists). That is, we pass the referrer to Google Play Store (to make the user update the app), user updates the app from the store, and then opens the updated app and receives the refererrer on the start of the updated app.Mcclary
I'm not able to get the "Open" option from Google play store. It is always saying Update even when I've a more updated build version. I'm not sure what's wrong :(Alb
It won't let me edit, so here is the updated google play url builder: ga-dev-tools.google/ga4/campaign-url-builder/playIzanami
V
7

This is the summary of my test:

  1. old broadcast way can test.But it's deprecated and not support for now
  2. U can test install referrer lib set up by use adb,and you will get utm_source=google-play&utm_medium=organic just like download form Google Play directly. But we can't get more info, it's can only test your library settings is correct
  3. https://mcmap.net/q/238109/-testing-google-play-install-referrer-library by @Quickern.To be honest, it works follow these tips
  4. Use Beta test provided by Google Play: https://mcmap.net/q/243421/-how-to-test-google-play-referrer-api-before-publishing-in-google-play-store. Without a doubt, it works
  5. Use emulator:https://mcmap.net/q/238109/-testing-google-play-install-referrer-library @Marilia. I didn't test this, because emulator with Google Play Store is just like a real device.And the answer said the condition is upload app to Google Play store,so I think it's just like article 4
Vesica answered 25/8, 2020 at 8:11 Comment(0)
P
3

Step 1

Testing Url
https://play.google.com/store/apps/details?id=com.test.test_project&referrer=utm_source%3Dtest_source%26utm_medium%3Dtest_medium%26utm_term%3Dtest-term%26utm_content%3Dtest_content%26utm_campaign%3Dtest_name

Step 2 Click on the above link. Open Play store (Don't Install from play Store)

Step 3 Install from Android studio. You get the result. Now if you check another Link you need to follow the above step the same manner bcz,

Note: Caution: The install referrer information will be available for 90 days and won't change unless the application is reinstalled. To avoid unnecessary API calls in your app, you should invoke the API only once during the first execution after install.

(From Here)

Note: My App right now Alpha Version(In Play Store)

Permanence answered 30/6, 2021 at 12:17 Comment(0)
T
2

After reading the required steps in https://developers.google.com/analytics/solutions/testing-play-campaigns, I found it possible to test the app install referrer library before releasing it to the Play Store, using the ADB tools.

Please note - the following test is using the deprecated broadcast receiver, not with the new Play Install Referrer API. (Thanks to Peter Keefe who noted it).

Ensure the application is not running and run this shell code in your Terminal / CMD (while the device connected with adb) for triggering the installation intent:

 echo 'am broadcast \
-a com.android.vending.INSTALL_REFERRER \
-n "your.package.name/path.to.receiver" \
--es "referrer" \
  "utm_source=test_source&utm_medium=test_medium&utm_term=test_term&utm_content=test_content&utm_campaign=test_name"; \
exit' | ./adb shell

Replace the package name and path to the receiver:

your.package.name/path.to.receiver

Also, don't forget to replace the utm url params in order to track different install source:

utm_source=test_source&utm_medium=test_medium&utm_term=test_term&utm_content=test_content&utm_campaign=test_name

Tjirebon answered 3/12, 2019 at 9:1 Comment(3)
This tests using the deprecated broadcast receiver, NOT the new Play Install Referrer API.Psilocybin
Can you help with testing the library way ?Ite
The only way to test it should be using the Beta release feature in the Play Store console. Launch beta testing to your device, and use the beta link to inject the referral parameters. I used firebase analytics to log the referral data as a custom event, so you can check if the data received correctly using the Firebase Analytics Debug dashboard.Tjirebon
K
2

I was able to test the Play Install Referrer Library using the emulator. Uninstalling the app and running it again would start a connection and give me the expected responseCode in onInstallReferrerSetupFinished.

Kurdistan answered 15/1, 2020 at 1:59 Comment(7)
But all the emulators won't have play store app right? Then how can we test them?Respondence
To test the case when the Play Store is disabled, you can disable the Google Play Store in the settings. Go to Settings > Tap Apps & notifications. Choose Google Play Store (or first tap See all apps or App info to find it). Tap Disable option. If the Google Play Store is disabled I receive InstallReferrerResponse.FEATURE_NOT_SUPPORTED as responseCode.Kurdistan
Thanks. I did accordingly and I am able to see the response codes.Respondence
btw did you try to mock the procedure of your app installing from an add and then after opening your app from play store, are you able to monitor the installReferrerUrl params like utm_source or utm_medium?Respondence
I didn't try installing from an ad, but installing from the play store gives me those parameters in the referrerUrl, like for example: utm_source=google-play&utm_medium=organicKurdistan
Install from play store means you uploaded to or updated your app on the play store?Respondence
Yes, organic source installs or building the app to the emulator should return those parameters and values I mentioned.Kurdistan
T
-5

Maby some will need this. I created test app and here is source code for only one needed activity. It's about how to add Play Install Referrer Library: https://developer.android.com/google/play/installreferrer/library

Also here is good description: https://android-developers.googleblog.com/2017/11/google-play-referrer-api-track-and.html

package com.cat.red.rsamazingapp;

import android.os.RemoteException;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import com.android.installreferrer.api.InstallReferrerClient;
import com.android.installreferrer.api.InstallReferrerStateListener;
import com.android.installreferrer.api.ReferrerDetails;

import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;

public class MainActivity extends AppCompatActivity implements InstallReferrerStateListener {

    private static final String TAG = "RSD";
    InstallReferrerClient mReferrerClient;
    TextView txtBody;
    StringBuilder stringBuilder;

    private int attemps = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        txtBody = (TextView) this.findViewById(R.id.txt_body);
        stringBuilder = new StringBuilder();
        stringBuilder.append("\nonCreate");

        mReferrerClient = InstallReferrerClient.newBuilder(this).build();
        stringBuilder.append("\n1. onCreate.isReady == " + mReferrerClient.isReady());
        mReferrerClient.startConnection(this);
        stringBuilder.append("\nstartConnection");
        stringBuilder.append("\n2. onCreate.isReady == " + mReferrerClient.isReady());
    }

    @Override
    public void onInstallReferrerSetupFinished(int responseCode) {
        stringBuilder.append("\nonInstallReferrerSetupFinished");

        switch (responseCode) {
            case InstallReferrerClient.InstallReferrerResponse.OK:
                // Connection established
                stringBuilder.append("\nonInstallReferrerSetupFinished. InstallReferrer conneceted. Success");
                stringBuilder.append("\nisReady == " + mReferrerClient.isReady());

                try {
                    ReferrerDetails installReferrerDetails = mReferrerClient.getInstallReferrer();
                    if (installReferrerDetails == null) {
                        stringBuilder.append("\ninstallReferrerDetails == NULL");
                    }

                    if (installReferrerDetails != null) {
                        stringBuilder.append("\ngetInstallReferrer = " + installReferrerDetails.getInstallReferrer());
                        stringBuilder.append("\ngetInstallBeginTimestampSeconds = " + installReferrerDetails.getInstallBeginTimestampSeconds());
                        stringBuilder.append("\ngetReferrerClickTimestampSeconds = " + installReferrerDetails.getReferrerClickTimestampSeconds());
                    }
                } catch (RemoteException e) {
                    stringBuilder.append("\nonInstallReferrerSetupFinished. exception: " + e.getMessage());
                    txtBody.setText(stringBuilder.toString());
                    e.printStackTrace();
                }
                break;
            case InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
                stringBuilder.append("\nonInstallReferrerSetupFinished. Install Referrer API not supported by the installed Play Store app.");
                stringBuilder.append("\nisReady == " + mReferrerClient.isReady());
                break;
            case InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE:
                // Connection could not be established
                stringBuilder.append("\nonInstallReferrerSetupFinished. Could not initiate connection to the Install Referrer service.");
                stringBuilder.append("\nisReady == " + mReferrerClient.isReady());
                break;
            case InstallReferrerClient.InstallReferrerResponse.SERVICE_DISCONNECTED:
                stringBuilder.append("\nonInstallReferrerSetupFinished. Play Store service is not connected now - potentially transient state");
                stringBuilder.append("\nisReady == " + mReferrerClient.isReady());
                break;
            case InstallReferrerClient.InstallReferrerResponse.DEVELOPER_ERROR:
                stringBuilder.append("\nonInstallReferrerSetupFinished. General errors caused by incorrect usage.");
                stringBuilder.append("\nisReady == " + mReferrerClient.isReady());
                break;
            default:
                stringBuilder.append("\nonInstallReferrerSetupFinished. responseCode not found. code = " + responseCode);
                stringBuilder.append("\nisReady == " + mReferrerClient.isReady());
        }

        stringBuilder.append("\nisReady == " + mReferrerClient.isReady());
        mReferrerClient.endConnection();
        stringBuilder.append("\nendConnection");
        stringBuilder.append("\nisReady == " + mReferrerClient.isReady());

        txtBody.setText(stringBuilder.toString());
    }

    @Override
    public void onInstallReferrerServiceDisconnected() {
        // Try to restart the connection on the next request to
        // Google Play by calling the startConnection() method.
        stringBuilder.append("\nonInstallReferrerServiceDisconnected. attemptCount = " + attemps);
        stringBuilder.append("\nisReady == " + mReferrerClient.isReady());

        if (attemps < 3) {
            attemps++;
            stringBuilder.append("\nonInstallReferrerServiceDisconnected. RE-startConnection");
            mReferrerClient.startConnection(this);
        } else {
            stringBuilder.append("\nonInstallReferrerServiceDisconnected. endConnection");
            stringBuilder.append("\nisReady == " + mReferrerClient.isReady());
            mReferrerClient.endConnection();
            stringBuilder.append("\nendConnection");
            stringBuilder.append("\nisReady == " + mReferrerClient.isReady());
        }

        txtBody.setText(stringBuilder.toString());
    }

    @Override
    protected void onResume() {
        super.onResume();
        stringBuilder.append("\nonResume. isReady == "+ mReferrerClient.isReady());
    }

    public static String format(GregorianCalendar calendar){
        SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        fmt.setCalendar(calendar);
        String dateFormatted = fmt.format(calendar.getTime());
        return dateFormatted;
    }
}
Toddle answered 10/8, 2018 at 10:57 Comment(2)
Above is just a "example" code, but didn't show how to test the APP before uploading to the play store.Threecolor
@YingboMiao True, however if you have the possibility to upload to play store, do you know if you can test it for all tracks (internal, alpha, beta, production) or just some?Battologize

© 2022 - 2024 — McMap. All rights reserved.