Skip to content

Commit

Permalink
Add new field is_meta_ct field to v1/installs for Meta Install Referr…
Browse files Browse the repository at this point in the history
…er (#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
  • Loading branch information
nsingh-branch authored Mar 13, 2024
1 parent 53e1788 commit 1b6bb47
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -345,6 +345,9 @@ suspend fun fetchLatestInstallReferrer(context: Context): InstallReferrerResult?
val allReferrers: List<InstallReferrerResult?> = 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
}
}
Expand All @@ -360,11 +363,7 @@ fun getLatestValidReferrerStore(allReferrers: List<InstallReferrerResult?>): 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion Branch-SDK/src/main/java/io/branch/referral/Defines.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 10 additions & 0 deletions Branch-SDK/src/main/java/io/branch/referral/PrefHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
});
Expand Down
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 1b6bb47

Please sign in to comment.