From 1b6bb47562123ef98f295501d616fac988f63443 Mon Sep 17 00:00:00 2001 From: Nipun Singh <88689850+nsingh-branch@users.noreply.github.com> Date: Wed, 13 Mar 2024 11:11:47 -0700 Subject: [PATCH] Add new field is_meta_ct field to v1/installs for Meta Install Referrer (#1174) * Patch to include is click-through field * updated log and moved code * Update ChangeLog.md * Added more verbose logs * Update ChangeLog.md * Update ChangeLog.md --- .../java/io/branch/coroutines/InstallReferrers.kt | 11 +++++------ .../java/io/branch/referral/AppStoreReferrer.java | 7 ++++++- .../src/main/java/io/branch/referral/Defines.java | 3 ++- .../src/main/java/io/branch/referral/PrefHelper.java | 10 ++++++++++ .../io/branch/referral/ServerRequestInitSession.java | 8 +++++++- .../main/java/io/branch/referral/SystemObserver.java | 2 +- ChangeLog.md | 3 +++ gradle.properties | 4 ++-- 8 files changed, 36 insertions(+), 12 deletions(-) diff --git a/Branch-SDK/src/main/java/io/branch/coroutines/InstallReferrers.kt b/Branch-SDK/src/main/java/io/branch/coroutines/InstallReferrers.kt index ce8d8a58e..3adc57284 100644 --- a/Branch-SDK/src/main/java/io/branch/coroutines/InstallReferrers.kt +++ b/Branch-SDK/src/main/java/io/branch/coroutines/InstallReferrers.kt @@ -308,7 +308,7 @@ private fun queryProvider(context: Context, provider: String): InstallReferrerRe return null } - BranchLogger.i("getMetaInstallReferrerDetails - Got Meta Install Referrer from provider $provider: $installReferrerString") + BranchLogger.i("getMetaInstallReferrerDetails - Got Meta Install Referrer as ${if (isClickThrough) "click-through" else "view-through"} from provider $provider: $installReferrerString") try { val json = JSONObject(utmContentValue) @@ -345,6 +345,9 @@ suspend fun fetchLatestInstallReferrer(context: Context): InstallReferrerResult? val allReferrers: List = listOf(googleReferrer.await(), huaweiReferrer.await(), samsungReferrer.await(), xiaomiReferrer.await(), metaReferrer.await()) val latestReferrer = getLatestValidReferrerStore(allReferrers) + BranchLogger.v("All Install Referrers: $allReferrers") + BranchLogger.v("Latest Install Referrer: $latestReferrer") + latestReferrer } } @@ -360,11 +363,7 @@ fun getLatestValidReferrerStore(allReferrers: List): Ins } if (allReferrers.filterNotNull().any { it.appStore == Jsonkey.Meta_Install_Referrer.key }) { - val latestReferrer = handleMetaInstallReferrer(allReferrers, result!!) - if (latestReferrer?.appStore == Jsonkey.Meta_Install_Referrer.key) { - latestReferrer?.appStore = Jsonkey.Google_Play_Store.key - } - return latestReferrer + return handleMetaInstallReferrer(allReferrers, result!!) } return result diff --git a/Branch-SDK/src/main/java/io/branch/referral/AppStoreReferrer.java b/Branch-SDK/src/main/java/io/branch/referral/AppStoreReferrer.java index 8636f8f12..10b18b2bb 100644 --- a/Branch-SDK/src/main/java/io/branch/referral/AppStoreReferrer.java +++ b/Branch-SDK/src/main/java/io/branch/referral/AppStoreReferrer.java @@ -15,10 +15,15 @@ public class AppStoreReferrer { /* Link identifier on installing app from play store. */ private static String installID_ = PrefHelper.NO_STRING_VALUE; - public static void processReferrerInfo(Context context, String rawReferrerString, long referrerClickTS, long installClickTS, String store) { + public static void processReferrerInfo(Context context, String rawReferrerString, long referrerClickTS, long installClickTS, String store, Boolean isClickThrough) { PrefHelper prefHelper = PrefHelper.getInstance(context); if(!TextUtils.isEmpty(store)){ prefHelper.setAppStoreSource(store); + + //Set the click through flag for Meta Install Referrers + if (store.equals(Defines.Jsonkey.Meta_Install_Referrer.getKey())) { + prefHelper.setIsMetaClickThrough(isClickThrough); + } } if (referrerClickTS > 0) { prefHelper.setLong(PrefHelper.KEY_REFERRER_CLICK_TS, referrerClickTS); diff --git a/Branch-SDK/src/main/java/io/branch/referral/Defines.java b/Branch-SDK/src/main/java/io/branch/referral/Defines.java index 42149d717..835e8692e 100644 --- a/Branch-SDK/src/main/java/io/branch/referral/Defines.java +++ b/Branch-SDK/src/main/java/io/branch/referral/Defines.java @@ -222,7 +222,8 @@ public enum Jsonkey { DMA_EEA("dma_eea"), DMA_Ad_Personalization("dma_ad_personalization"), - DMA_Ad_User_Data("dma_ad_user_data"); + DMA_Ad_User_Data("dma_ad_user_data"), + Is_Meta_Click_Through("is_meta_ct"); private final String key; diff --git a/Branch-SDK/src/main/java/io/branch/referral/PrefHelper.java b/Branch-SDK/src/main/java/io/branch/referral/PrefHelper.java index 8a1941e97..737c50a64 100644 --- a/Branch-SDK/src/main/java/io/branch/referral/PrefHelper.java +++ b/Branch-SDK/src/main/java/io/branch/referral/PrefHelper.java @@ -127,6 +127,8 @@ public class PrefHelper { static final String KEY_REFERRING_URL_QUERY_PARAMETERS = "bnc_referringUrlQueryParameters"; static final String KEY_ANON_ID = "bnc_anon_id"; + static final String KEY_IS_META_CLICKTHROUGH = "bnc_is_meta_clickthrough"; + /** * Internal static variable of own type {@link PrefHelper}. This variable holds the single * instance used when the class is instantiated via the Singleton pattern. @@ -709,6 +711,14 @@ public String getAppStoreSource(){ return getString(KEY_APP_STORE_SOURCE); } + public void setIsMetaClickThrough(boolean isMetaClickThrough) { + setBool(KEY_IS_META_CLICKTHROUGH, isMetaClickThrough); + } + + public boolean getIsMetaClickThrough() { + return getBool(KEY_IS_META_CLICKTHROUGH); + } + /** * Sets the referring URL query parameters. * @param referringUrlQueryParameters diff --git a/Branch-SDK/src/main/java/io/branch/referral/ServerRequestInitSession.java b/Branch-SDK/src/main/java/io/branch/referral/ServerRequestInitSession.java index c16b8430f..f661a9ded 100644 --- a/Branch-SDK/src/main/java/io/branch/referral/ServerRequestInitSession.java +++ b/Branch-SDK/src/main/java/io/branch/referral/ServerRequestInitSession.java @@ -130,7 +130,13 @@ void updateLinkReferrerParams() { String appStore = prefHelper_.getAppStoreSource(); if(!PrefHelper.NO_STRING_VALUE.equals(appStore)) { try { - getPost().put(Defines.Jsonkey.App_Store.getKey(), appStore); + //Handle Meta Install Referrer by setting store as Google Play Store and adding is_meta_click_through + if (appStore.equals(Defines.Jsonkey.Meta_Install_Referrer.getKey())) { + getPost().put(Defines.Jsonkey.App_Store.getKey(), Defines.Jsonkey.Google_Play_Store.getKey()); + getPost().put(Defines.Jsonkey.Is_Meta_Click_Through.getKey(), prefHelper_.getIsMetaClickThrough()); + } else { + getPost().put(Defines.Jsonkey.App_Store.getKey(), appStore); + } } catch (JSONException e) { BranchLogger.w("Caught JSONException " + e.getMessage()); } diff --git a/Branch-SDK/src/main/java/io/branch/referral/SystemObserver.java b/Branch-SDK/src/main/java/io/branch/referral/SystemObserver.java index c43a56c5c..a3cfa6494 100644 --- a/Branch-SDK/src/main/java/io/branch/referral/SystemObserver.java +++ b/Branch-SDK/src/main/java/io/branch/referral/SystemObserver.java @@ -602,7 +602,7 @@ public CoroutineContext getContext() { public void resumeWith(@NonNull Object o) { if (o != null) { InstallReferrerResult latestReferrer = (InstallReferrerResult) o; - AppStoreReferrer.processReferrerInfo(context_, latestReferrer.getLatestRawReferrer(), latestReferrer.getLatestClickTimestamp(), latestReferrer.getLatestInstallTimestamp(), latestReferrer.getAppStore()); + AppStoreReferrer.processReferrerInfo(context_, latestReferrer.getLatestRawReferrer(), latestReferrer.getLatestClickTimestamp(), latestReferrer.getLatestInstallTimestamp(), latestReferrer.getAppStore(), latestReferrer.isClickThrough()); } } }); diff --git a/ChangeLog.md b/ChangeLog.md index a5deb4d8a..db6ca5bd3 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,4 +1,7 @@ # Branch Android SDK change log +- v5.10.1 + * _*Master Release*_ - Mar 13, 2024 + - Track Meta Install Referrer view-through installs - v5.10.0 * _*Master Release*_ - Mar 8, 2024 - Introduced Meta Install Referrer tracking diff --git a/gradle.properties b/gradle.properties index 5fdd42523..4c891a263 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ -VERSION_NAME=5.10.0 -VERSION_CODE=051200 +VERSION_NAME=5.10.1 +VERSION_CODE=051201 GROUP=io.branch.sdk.android POM_DESCRIPTION=Use the Branch SDK (branch.io) to create and power the links that point back to your apps for all of these things and more. Branch makes it incredibly simple to create powerful deep links that can pass data across app install and open while handling all edge cases (using on desktop vs. mobile vs. already having the app installed, etc). Best of all, it is really simple to start using the links for your own app: only 2 lines of code to register the deep link router and one more line of code to create the links with custom data.