Skip to content

Commit c3d4b96

Browse files
Merge pull request #1008 from BranchMetrics/gdeluna-branch/SDK-1496
Add app store source in request
2 parents a8300a3 + 8f0ee29 commit c3d4b96

File tree

9 files changed

+76
-28
lines changed

9 files changed

+76
-28
lines changed

Branch-SDK/src/androidTest/java/io/branch/referral/PrefHelperTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,12 @@ public void testSetNoConnectionRetryMax(){
196196

197197
Assert.assertEquals(max, prefHelper.getNoConnectionRetryMax());
198198
}
199+
200+
@Test
201+
public void testAppStoreSource(){
202+
prefHelper.setAppStoreSource(Defines.Jsonkey.Google_Play_Store.getKey());
203+
204+
String result = prefHelper.getAppStoreSource();
205+
Assert.assertEquals(Defines.Jsonkey.Google_Play_Store.getKey(), result);
206+
}
199207
}

Branch-SDK/src/androidTest/java/io/branch/referral/StoreReferrerTests.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ public void testReturnLatestInstallReferrer_AllValidReferrers(){
4444

4545
String result = StoreReferrerUtils.getLatestValidReferrerStore();
4646

47-
Assert.assertEquals(Defines.Jsonkey.HUAWEI_APP_GALLERY.getKey(), result);
47+
Assert.assertEquals(Defines.Jsonkey.Huawei_App_Gallery.getKey(), result);
48+
49+
StoreReferrerUtils.writeLatestInstallReferrer(context, result);
50+
Assert.assertEquals(Defines.Jsonkey.Huawei_App_Gallery.getKey(), prefHelper.getAppStoreSource());
4851
}
4952

5053
@Test
@@ -68,6 +71,9 @@ public void testReturnLatestInstallReferrer_NoReferrer(){
6871
String result = StoreReferrerUtils.getLatestValidReferrerStore();
6972

7073
Assert.assertEquals("", result);
74+
75+
StoreReferrerUtils.writeLatestInstallReferrer(context, result);
76+
Assert.assertEquals(PrefHelper.NO_STRING_VALUE, prefHelper.getAppStoreSource());
7177
}
7278

7379
@Test
@@ -90,7 +96,10 @@ public void testReturnLatestInstallReferrer_AllSameTimestamp_OneNotNullReferrerS
9096

9197
String result = StoreReferrerUtils.getLatestValidReferrerStore();
9298

93-
Assert.assertEquals(Defines.Jsonkey.GOOGLE_PLAY_STORE.getKey(), result);
99+
Assert.assertEquals(Defines.Jsonkey.Google_Play_Store.getKey(), result);
100+
101+
StoreReferrerUtils.writeLatestInstallReferrer(context, result);
102+
Assert.assertEquals(Defines.Jsonkey.Google_Play_Store.getKey(), prefHelper.getAppStoreSource());
94103
}
95104

96105
@Test
@@ -115,5 +124,6 @@ public void testWriteLatestInstallReferrer(){
115124

116125
StoreReferrerUtils.writeLatestInstallReferrer(context, result);
117126
Assert.assertEquals(StoreReferrerGooglePlayStore.rawReferrer, PrefHelper.getInstance(context).getAppStoreReferrer());
127+
Assert.assertEquals(Defines.Jsonkey.Google_Play_Store.getKey(), prefHelper.getAppStoreSource());
118128
}
119129
}

Branch-SDK/src/main/java/io/branch/referral/AppStoreReferrer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ public abstract class AppStoreReferrer {
1515
/* Link identifier on installing app from play store. */
1616
private static String installID_ = PrefHelper.NO_STRING_VALUE;
1717

18-
protected static void processReferrerInfo(Context context, String rawReferrerString, long referrerClickTS, long installClickTS) {
18+
protected static void processReferrerInfo(Context context, String rawReferrerString, long referrerClickTS, long installClickTS, String store) {
1919
PrefHelper prefHelper = PrefHelper.getInstance(context);
20+
if(!TextUtils.isEmpty(store)){
21+
prefHelper.setAppStoreSource(store);
22+
}
2023
if (referrerClickTS > 0) {
2124
prefHelper.setLong(PrefHelper.KEY_REFERRER_CLICK_TS, referrerClickTS);
2225
}

Branch-SDK/src/main/java/io/branch/referral/Defines.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,11 @@ public enum Jsonkey {
218218
QRCodeBranchKey("branch_key"),
219219
QRCodeResponseString("QRCodeString"),
220220

221-
GOOGLE_PLAY_STORE("google_play_store"),
222-
HUAWEI_APP_GALLERY("huawei_app_gallery"),
223-
SAMSUNG_GALAXY_STORE("samsung_galaxy_store"),
224-
XIAOMI_GET_APPS("xiaomi_get_apps");
221+
App_Store("app_store"),
222+
Google_Play_Store("PlayStore"),
223+
Huawei_App_Gallery("AppGallery"),
224+
Samsung_Galaxy_Store("GalaxyStore"),
225+
Xiaomi_Get_Apps("GetApps");
225226

226227
private final String key;
227228

Branch-SDK/src/main/java/io/branch/referral/DeviceInfo.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ void updateRequestWithV2Params(ServerRequest serverRequest, PrefHelper prefHelpe
181181
if (!isNullOrEmptyOrBlank(devId)) {
182182
userDataObj.put(Defines.Jsonkey.DeveloperIdentity.getKey(), devId);
183183
}
184+
185+
String appStore = prefHelper.getAppStoreSource();
186+
if(!NO_STRING_VALUE.equals(appStore)) {
187+
userDataObj.put(Defines.Jsonkey.App_Store.getKey(), appStore);
188+
}
184189
}
185190

186191
userDataObj.put(Defines.Jsonkey.AppVersion.getKey(), getAppVersion());

Branch-SDK/src/main/java/io/branch/referral/PrefHelper.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public class PrefHelper {
7676
private static final String KEY_LINK_CLICK_IDENTIFIER = "bnc_link_click_identifier";
7777
private static final String KEY_GOOGLE_SEARCH_INSTALL_IDENTIFIER = "bnc_google_search_install_identifier";
7878
private static final String KEY_GOOGLE_PLAY_INSTALL_REFERRER_EXTRA = "bnc_google_play_install_referrer_extras";
79+
private static final String KEY_APP_STORE_SOURCE = "bnc_app_store_source";
7980
private static final String KEY_GCLID_JSON_OBJECT = "bnc_gclid_json_object";
8081
private static final String KEY_GCLID_VALUE = "bnc_gclid_value";
8182
private static final String KEY_GCLID_EXPIRATION_DATE = "bnc_gclid_expiration_date";
@@ -695,6 +696,16 @@ public String getAppStoreReferrer() {
695696
return getString(KEY_GOOGLE_PLAY_INSTALL_REFERRER_EXTRA);
696697
}
697698

699+
public void setAppStoreSource(String store){
700+
if(!TextUtils.isEmpty(store)) {
701+
setString(KEY_APP_STORE_SOURCE, store);
702+
}
703+
}
704+
705+
public String getAppStoreSource(){
706+
return getString(KEY_APP_STORE_SOURCE);
707+
}
708+
698709
/**
699710
* Sets the referrer Google Click ID with an expiration date computed by time set + expiration window
700711
* @param referrerGclid

Branch-SDK/src/main/java/io/branch/referral/ServerRequestInitSession.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,15 @@ void updateLinkReferrerParams() {
168168
} catch (JSONException ignore) {
169169
}
170170
}
171+
172+
String appStore = prefHelper_.getAppStoreSource();
173+
if(!PrefHelper.NO_STRING_VALUE.equals(appStore)) {
174+
try {
175+
getPost().put(Defines.Jsonkey.App_Store.getKey(), appStore);
176+
} catch (JSONException ignore) {
177+
}
178+
}
179+
171180
// Check for Conversion from instant app to full app
172181
if (prefHelper_.isFullAppConversion()) {
173182
try {
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package io.branch.referral;
22

3-
import static io.branch.referral.Defines.Jsonkey.GOOGLE_PLAY_STORE;
4-
import static io.branch.referral.Defines.Jsonkey.HUAWEI_APP_GALLERY;
5-
import static io.branch.referral.Defines.Jsonkey.SAMSUNG_GALAXY_STORE;
6-
import static io.branch.referral.Defines.Jsonkey.XIAOMI_GET_APPS;
3+
import static io.branch.referral.Defines.Jsonkey.Google_Play_Store;
4+
import static io.branch.referral.Defines.Jsonkey.Huawei_App_Gallery;
5+
import static io.branch.referral.Defines.Jsonkey.Samsung_Galaxy_Store;
6+
import static io.branch.referral.Defines.Jsonkey.Xiaomi_Get_Apps;
77

88
import android.content.Context;
99
import android.text.TextUtils;
@@ -19,62 +19,62 @@ public class StoreReferrerUtils {
1919
*/
2020
public static String getLatestValidReferrerStore(){
2121
String result = "";
22-
Long latestTimeStamp = Long.MIN_VALUE;
22+
Long latestTimeStamp = 0L;
2323

2424
if(StoreReferrerGooglePlayStore.installBeginTimestamp > latestTimeStamp){
2525
latestTimeStamp = StoreReferrerGooglePlayStore.installBeginTimestamp;
26-
result = GOOGLE_PLAY_STORE.getKey();
26+
result = Google_Play_Store.getKey();
2727
}
2828

2929
if(StoreReferrerHuaweiAppGallery.installBeginTimestamp > latestTimeStamp){
3030
latestTimeStamp = StoreReferrerHuaweiAppGallery.installBeginTimestamp;
31-
result = HUAWEI_APP_GALLERY.getKey();
31+
result = Huawei_App_Gallery.getKey();
3232
}
3333

3434
if(StoreReferrerSamsungGalaxyStore.installBeginTimestamp > latestTimeStamp){
3535
latestTimeStamp = StoreReferrerSamsungGalaxyStore.installBeginTimestamp;
36-
result = SAMSUNG_GALAXY_STORE.getKey();
36+
result = Samsung_Galaxy_Store.getKey();
3737
}
3838

3939
if(StoreReferrerXiaomiGetApps.installBeginTimestamp > latestTimeStamp){
40-
result = XIAOMI_GET_APPS.getKey();
40+
result = Xiaomi_Get_Apps.getKey();
4141
}
4242

4343
// iterate through non-null strings for cases like Google Play returning
4444
// "utm_source=google-play&utm_medium=organic" for organic installs
4545
if(result.isEmpty()){
4646
if(!TextUtils.isEmpty(StoreReferrerGooglePlayStore.rawReferrer)){
47-
result = GOOGLE_PLAY_STORE.getKey();
47+
result = Google_Play_Store.getKey();
4848
}
4949

5050
if(!TextUtils.isEmpty(StoreReferrerHuaweiAppGallery.rawReferrer)){
51-
result = HUAWEI_APP_GALLERY.getKey();
51+
result = Huawei_App_Gallery.getKey();
5252
}
5353

5454
if(!TextUtils.isEmpty(StoreReferrerSamsungGalaxyStore.rawReferrer)){
55-
result = SAMSUNG_GALAXY_STORE.getKey();
55+
result = Samsung_Galaxy_Store.getKey();
5656
}
5757

5858
if(!TextUtils.isEmpty(StoreReferrerXiaomiGetApps.rawReferrer)){
59-
result = XIAOMI_GET_APPS.getKey();
59+
result = Xiaomi_Get_Apps.getKey();
6060
}
6161
}
6262

6363
return result;
6464
}
6565

6666
public static void writeLatestInstallReferrer(Context context_, String store) {
67-
if(store.equals(Defines.Jsonkey.GOOGLE_PLAY_STORE.getKey())){
68-
AppStoreReferrer.processReferrerInfo(context_, StoreReferrerGooglePlayStore.rawReferrer, StoreReferrerGooglePlayStore.clickTimestamp, StoreReferrerGooglePlayStore.installBeginTimestamp);
67+
if(store.equals(Defines.Jsonkey.Google_Play_Store.getKey())){
68+
AppStoreReferrer.processReferrerInfo(context_, StoreReferrerGooglePlayStore.rawReferrer, StoreReferrerGooglePlayStore.clickTimestamp, StoreReferrerGooglePlayStore.installBeginTimestamp, store);
6969
}
70-
if(store.equals(Defines.Jsonkey.HUAWEI_APP_GALLERY.getKey())){
71-
AppStoreReferrer.processReferrerInfo(context_, StoreReferrerHuaweiAppGallery.rawReferrer, StoreReferrerHuaweiAppGallery.clickTimestamp, StoreReferrerHuaweiAppGallery.installBeginTimestamp);
70+
if(store.equals(Defines.Jsonkey.Huawei_App_Gallery.getKey())){
71+
AppStoreReferrer.processReferrerInfo(context_, StoreReferrerHuaweiAppGallery.rawReferrer, StoreReferrerHuaweiAppGallery.clickTimestamp, StoreReferrerHuaweiAppGallery.installBeginTimestamp, store);
7272
}
73-
if(store.equals(Defines.Jsonkey.SAMSUNG_GALAXY_STORE.getKey())){
74-
AppStoreReferrer.processReferrerInfo(context_, StoreReferrerSamsungGalaxyStore.rawReferrer, StoreReferrerSamsungGalaxyStore.clickTimestamp, StoreReferrerSamsungGalaxyStore.installBeginTimestamp);
73+
if(store.equals(Defines.Jsonkey.Samsung_Galaxy_Store.getKey())){
74+
AppStoreReferrer.processReferrerInfo(context_, StoreReferrerSamsungGalaxyStore.rawReferrer, StoreReferrerSamsungGalaxyStore.clickTimestamp, StoreReferrerSamsungGalaxyStore.installBeginTimestamp, store);
7575
}
76-
if(store.equals(Defines.Jsonkey.XIAOMI_GET_APPS.getKey())){
77-
AppStoreReferrer.processReferrerInfo(context_, StoreReferrerXiaomiGetApps.rawReferrer, StoreReferrerXiaomiGetApps.clickTimestamp, StoreReferrerXiaomiGetApps.installBeginTimestamp);
76+
if(store.equals(Defines.Jsonkey.Xiaomi_Get_Apps.getKey())){
77+
AppStoreReferrer.processReferrerInfo(context_, StoreReferrerXiaomiGetApps.rawReferrer, StoreReferrerXiaomiGetApps.clickTimestamp, StoreReferrerXiaomiGetApps.installBeginTimestamp, store);
7878
}
7979
}
8080
}

Branch-SDK/src/main/java/io/branch/referral/TrackingController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ private void onTrackingDisabled(Context context) {
5757
prefHelper.setAppLink(PrefHelper.NO_STRING_VALUE);
5858
prefHelper.setInstallReferrerParams(PrefHelper.NO_STRING_VALUE);
5959
prefHelper.setAppStoreReferrer(PrefHelper.NO_STRING_VALUE);
60+
prefHelper.setAppStoreSource(PrefHelper.NO_STRING_VALUE);
6061
prefHelper.setGoogleSearchInstallIdentifier(PrefHelper.NO_STRING_VALUE);
6162
prefHelper.setInitialReferrer(PrefHelper.NO_STRING_VALUE);
6263
prefHelper.setExternalIntentUri(PrefHelper.NO_STRING_VALUE);

0 commit comments

Comments
 (0)