Skip to content

Commit e069ec7

Browse files
[INTENG-20913] - Fix initial referrer on re-open (#1247)
Fix initial referrer on re-open
1 parent f1672e2 commit e069ec7

File tree

5 files changed

+51
-17
lines changed

5 files changed

+51
-17
lines changed

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@ private void readAndStripParam(Uri data, Activity activity) {
892892

893893
// Capture the intent URI and extra for analytics in case started by external intents such as google app search
894894
extractExternalUriAndIntentExtras(data, activity);
895+
extractInitialReferrer(activity);
895896

896897
// if branch link is detected we don't need to look for click ID or app link anymore and can terminate early
897898
if (extractBranchLinkFromIntentExtra(activity)) return;
@@ -2264,6 +2265,19 @@ private void extractExternalUriAndIntentExtras(Uri data, Activity activity) {
22642265
}
22652266
}
22662267

2268+
private void extractInitialReferrer(Activity activity){
2269+
BranchLogger.v("extractInitialReferrer " + activity);
2270+
2271+
if(activity != null){
2272+
Uri initialReferrer = ActivityCompat.getReferrer(activity);
2273+
BranchLogger.v("Initial referrer: " + initialReferrer);
2274+
2275+
if(initialReferrer != null) {
2276+
prefHelper_.setInitialReferrer(initialReferrer.toString());
2277+
}
2278+
}
2279+
}
2280+
22672281
@Nullable Activity getCurrentActivity() {
22682282
if (currentActivityReference_ == null) return null;
22692283
return currentActivityReference_.get();
@@ -2415,9 +2429,17 @@ public void init() {
24152429

24162430
Activity activity = branch.getCurrentActivity();
24172431
Intent intent = activity != null ? activity.getIntent() : null;
2432+
Uri initialReferrer = null;
2433+
2434+
if(activity != null) {
2435+
initialReferrer = ActivityCompat.getReferrer(activity);
2436+
}
24182437

2419-
if (activity != null && intent != null && ActivityCompat.getReferrer(activity) != null) {
2420-
PrefHelper.getInstance(activity).setInitialReferrer(ActivityCompat.getReferrer(activity).toString());
2438+
BranchLogger.v("Activity: " + activity);
2439+
BranchLogger.v("Intent: " + intent);
2440+
BranchLogger.v("Initial Referrer: " + initialReferrer);
2441+
if (activity != null && intent != null && initialReferrer!= null) {
2442+
PrefHelper.getInstance(activity).setInitialReferrer(initialReferrer.toString());
24212443
}
24222444

24232445
if (uri != null) {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,7 @@ public int getLATDAttributionWindow(){
11321132
* @param initialReferrer android.intent.extra.REFERRER
11331133
*/
11341134
public void setInitialReferrer(String initialReferrer) {
1135+
BranchLogger.v("setInitialReferrer " + initialReferrer);
11351136
setString(KEY_INITIAL_REFERRER, initialReferrer);
11361137
}
11371138

@@ -1141,7 +1142,9 @@ public void setInitialReferrer(String initialReferrer) {
11411142
* @return {@link String} android.intent.extra.REFERRER
11421143
*/
11431144
public String getInitialReferrer() {
1144-
return getString(KEY_INITIAL_REFERRER);
1145+
String initialReferrer = getString(KEY_INITIAL_REFERRER);
1146+
BranchLogger.v("getInitialReferrer " + initialReferrer);
1147+
return initialReferrer;
11451148
}
11461149

11471150

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ protected void setPost(JSONObject post) throws JSONException {
5454
if (!DeviceInfo.isNullOrEmptyOrBlank(appVersion)) {
5555
post.put(Defines.Jsonkey.AppVersion.getKey(), appVersion);
5656
}
57-
if(!TextUtils.isEmpty(prefHelper_.getInitialReferrer()) && !prefHelper_.getInitialReferrer().equals(PrefHelper.NO_STRING_VALUE)) {
58-
post.put(Defines.Jsonkey.InitialReferrer.getKey(), prefHelper_.getInitialReferrer());
59-
}
6057

6158
updateInstallStateAndTimestamps(post);
6259
updateEnvironment(context_, post);
@@ -191,18 +188,30 @@ public void onPreExecute() {
191188
super.onPreExecute();
192189
JSONObject post = getPost();
193190
try {
194-
if (!prefHelper_.getAppLink().equals(PrefHelper.NO_STRING_VALUE)) {
195-
post.put(Defines.Jsonkey.AndroidAppLinkURL.getKey(), prefHelper_.getAppLink());
191+
String appLink = prefHelper_.getAppLink();
192+
if (!appLink.equals(PrefHelper.NO_STRING_VALUE)) {
193+
post.put(Defines.Jsonkey.AndroidAppLinkURL.getKey(), appLink);
196194
}
197-
if (!prefHelper_.getPushIdentifier().equals(PrefHelper.NO_STRING_VALUE)) {
198-
post.put(Defines.Jsonkey.AndroidPushIdentifier.getKey(), prefHelper_.getPushIdentifier());
195+
196+
String pushIdentifier = prefHelper_.getPushIdentifier();
197+
if (!pushIdentifier.equals(PrefHelper.NO_STRING_VALUE)) {
198+
post.put(Defines.Jsonkey.AndroidPushIdentifier.getKey(), pushIdentifier);
199199
}
200+
200201
// External URI or Extras if exist
201-
if (!prefHelper_.getExternalIntentUri().equals(PrefHelper.NO_STRING_VALUE)) {
202-
post.put(Defines.Jsonkey.External_Intent_URI.getKey(), prefHelper_.getExternalIntentUri());
202+
String externalIntentUri = prefHelper_.getExternalIntentUri();
203+
if (!externalIntentUri.equals(PrefHelper.NO_STRING_VALUE)) {
204+
post.put(Defines.Jsonkey.External_Intent_URI.getKey(), externalIntentUri);
203205
}
204-
if (!prefHelper_.getExternalIntentExtra().equals(PrefHelper.NO_STRING_VALUE)) {
205-
post.put(Defines.Jsonkey.External_Intent_Extra.getKey(), prefHelper_.getExternalIntentExtra());
206+
207+
String externalIntentExtra = prefHelper_.getExternalIntentExtra();
208+
if (!externalIntentExtra.equals(PrefHelper.NO_STRING_VALUE)) {
209+
post.put(Defines.Jsonkey.External_Intent_Extra.getKey(), externalIntentExtra);
210+
}
211+
212+
String initialReferrer = prefHelper_.getInitialReferrer();
213+
if(!TextUtils.isEmpty(initialReferrer) && !initialReferrer.equals(PrefHelper.NO_STRING_VALUE)) {
214+
post.put(Defines.Jsonkey.InitialReferrer.getKey(), initialReferrer);
206215
}
207216

208217
} catch (JSONException e) {

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import org.gradle.api.tasks.testing.logging.*
22

33
plugins {
4-
id("com.android.library") version "8.3.2" apply false
5-
id("com.android.application") version "8.3.2" apply false
4+
id("com.android.library") version "8.7.3" apply false
5+
id("com.android.application") version "8.7.3" apply false
66
id("org.jetbrains.kotlin.android") version "1.6.21" apply false
77
}
88

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#Wed Nov 06 12:51:09 PST 2024
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
55
networkTimeout=10000
66
zipStoreBase=GRADLE_USER_HOME
77
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)