Skip to content

Commit

Permalink
Added validityWindow check and clear on trackingDisabled
Browse files Browse the repository at this point in the history
  • Loading branch information
nsingh-branch committed Oct 3, 2023
1 parent 847f9c7 commit 1c4ea34
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
7 changes: 5 additions & 2 deletions Branch-SDK/src/main/java/io/branch/referral/PrefHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -704,15 +704,18 @@ public String getAppStoreSource(){
* @param referringUrlQueryParameters
*/
public void setReferringUrlQueryParameters(JSONObject referringUrlQueryParameters) {
setString(KEY_REFERRING_URL_QUERY_PARAMETERS, String.valueOf(referringUrlQueryParameters));
if (referringUrlQueryParameters.length() == 0) {

This comment has been minimized.

Copy link
@gdeluna-branch

gdeluna-branch Oct 3, 2023

Contributor

Is it possible for the result of serialization to be null?

setString(KEY_REFERRING_URL_QUERY_PARAMETERS, NO_STRING_VALUE);
} else {
setString(KEY_REFERRING_URL_QUERY_PARAMETERS, String.valueOf(referringUrlQueryParameters));
}
}

/**
* Returns the referring URL query parameters.
* @return
*/
public JSONObject getReferringURLQueryParameters() {

String string = getString(KEY_REFERRING_URL_QUERY_PARAMETERS);
JSONObject params = new JSONObject();

Expand Down
27 changes: 19 additions & 8 deletions Branch-SDK/src/main/java/io/branch/referral/ReferringUrlUtility.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,27 @@ class ReferringUrlUtility (prefHelper: PrefHelper) {
val gclid = urlQueryParameters[Defines.Jsonkey.Gclid.key]
if (gclid != null) {
if (gclid.value != null && gclid.value != PrefHelper.NO_STRING_VALUE) {
returnParams.put(Defines.Jsonkey.Gclid.key, gclid.value)

//Only v1/open requires is_deeplink_gclid
if (request is ServerRequestRegisterOpen) {
returnParams.put(Defines.Jsonkey.IsDeeplinkGclid.key, gclid.isDeepLink)
// If current time is before the expiry time, proceed
val currentTime = Date().time
val gclidTimestamp = gclid.timestamp?.time
val gclidValidityWindowMillis = 10//gclid.validityWindow * 1000L
if (gclidTimestamp != null) {
if (gclid.validityWindow == 0L || currentTime < gclidTimestamp + gclidValidityWindowMillis) {
returnParams.put(Defines.Jsonkey.Gclid.key, gclid.value)

// Only v1/open requires is_deeplink_gclid
if (request is ServerRequestRegisterOpen) {
returnParams.put(Defines.Jsonkey.IsDeeplinkGclid.key, gclid.isDeepLink)
}

gclid.isDeepLink = false
prefHelper.setReferringUrlQueryParameters(serializeToJson(urlQueryParameters))
} else {
urlQueryParameters.remove(Defines.Jsonkey.Gclid.key)
prefHelper.setReferringUrlQueryParameters(serializeToJson(urlQueryParameters))
}
}

gclid.isDeepLink = false
prefHelper.setReferringUrlQueryParameters(serializeToJson(urlQueryParameters))
}
}
}
Expand Down Expand Up @@ -182,7 +194,6 @@ class ReferringUrlUtility (prefHelper: PrefHelper) {
* 3. If that Gclid does exist, it will be turned into a BranchUrlQueryParameter and saved.
* 4. Lastly, the old gclid is cleared and now the function
*/
@VisibleForTesting
private fun checkForAndMigrateOldGclid() {
val newGclid = urlQueryParameters[Defines.Jsonkey.Gclid.key]
if (newGclid?.value == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import androidx.annotation.NonNull;

import org.json.JSONObject;

/**
* Created by sojanpr on 3/7/18.
* <p>
Expand Down Expand Up @@ -64,6 +66,7 @@ private void onTrackingDisabled(Context context) {
prefHelper.setExternalIntentExtra(PrefHelper.NO_STRING_VALUE);
prefHelper.setSessionParams(PrefHelper.NO_STRING_VALUE);
prefHelper.setAnonID(PrefHelper.NO_STRING_VALUE);
prefHelper.setReferringUrlQueryParameters(new JSONObject());
Branch.getInstance().clearPartnerParameters();
}

Expand Down

0 comments on commit 1c4ea34

Please sign in to comment.