Skip to content

Commit 2d00a6d

Browse files
authored
fix: Refactor InstallReferrerClient to use reflection (#592)
1 parent 26e4cf0 commit 2d00a6d

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

android-core/src/main/java/com/mparticle/InstallReferrerHelper.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,30 @@
1515
import com.mparticle.internal.Logger;
1616
import com.mparticle.internal.MPUtility;
1717

18+
/**
19+
* Helper class to fetch install referrer via reflection.
20+
* <p>
21+
* To test the install referrer functionality:
22+
* 1. Set test application `applicationId` to a real app's Play Store package name, e.g. "com.medium.reader".
23+
* <p>
24+
* 2. Ensure the app is fully uninstalled from the test device:
25+
* `adb uninstall com.medium.reader`
26+
* <p>
27+
* 3. Broadcast the test referrer to the Play Store. This will open the Play Store app:
28+
* `adb shell "am start -a android.intent.action.VIEW -d 'https://play.google.com/store/apps/details?id=com.medium.reader&referrer=utm_source%3Dgoogle%26utm_medium%3Dcpc%26utm_term%3Drunning%252Bshoes%26utm_content%3Dcontent%26utm_campaign%3Dpromo'"`
29+
* <p>
30+
* 4. Install the debug version of your test app.
31+
* <p>
32+
* 5. Launch the app and check the logs for the referrer:
33+
* `adb logcat -d | grep 'Install Referrer received'`
34+
* <p>
35+
* 6. Verify the referrer is logged in the test app's logs by checking for the utm_* parameters passed in during step 3.
36+
* e.g. `Install Referrer received: utm_source=google&utm_medium=cpc&utm_term=running%2Bshoes&utm_content=content&utm_campaign=promo`
37+
*
38+
* @see <a href="https://developer.android.com/reference/com/android/installreferrer/api/InstallReferrerClient">InstallReferrerClient</a>
39+
* @see <a href="https://medium.com/@madicdjordje/how-to-test-the-play-store-install-referrer-api-78a63d59945b">How to Test the Play Store Install Referrer API</a>
40+
* @noinspection JavadocLinkAsPlainText
41+
*/
1842
public class InstallReferrerHelper {
1943

2044
@Nullable

android-core/src/main/java/com/mparticle/internal/MPUtility.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,9 @@ public static Boolean isFirebaseAvailablePreV21() {
593593

594594
public static boolean isInstallRefApiAvailable() {
595595
try {
596+
Class.forName("com.android.installreferrer.api.InstallReferrerClient");
596597
Class.forName("com.android.installreferrer.api.InstallReferrerStateListener");
598+
Class.forName("com.android.installreferrer.api.ReferrerDetails");
597599
return true;
598600
} catch (Exception ignored) {
599601
}

0 commit comments

Comments
 (0)