Skip to content

Commit

Permalink
core: fix parsing non hierarchical uri
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasMengelatte committed Dec 4, 2024
1 parent a01af1b commit 009582a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 28 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
UPCOMING
-----

* Fixed an issue where Batch would crash when a non-hierarchical URI was parsed in a deeplink.

2.0.0
-----

Expand All @@ -17,4 +22,4 @@
1.0
-----

* Dispatcher release.
* Dispatcher release.
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,22 @@ private static Map<String, Object> getInAppParams(Batch.EventDispatcher.Payload

String deeplink = payload.getDeeplink();
if (deeplink != null) {
deeplink = deeplink.trim();
Uri uri = Uri.parse(deeplink);

String fragment = uri.getFragment();
if (fragment != null && !fragment.isEmpty()) {
Map<String, String> fragments = getFragmentMap(fragment);
// Copy from fragment part of the deeplink
copyValueFromMap(fragments, UTM_CONTENT, mixpanelParams, CONTENT);
try {
deeplink = deeplink.trim();
Uri uri = Uri.parse(deeplink);
if (uri.isHierarchical()) {
String fragment = uri.getFragment();
if (fragment != null && !fragment.isEmpty()) {
Map<String, String> fragments = getFragmentMap(fragment);
// Copy from fragment part of the deeplink
copyValueFromMap(fragments, UTM_CONTENT, mixpanelParams, CONTENT);
}
// Copy from query parameters of the deeplink
copyValueFromQuery(uri, UTM_CONTENT, mixpanelParams, CONTENT);
}
} catch (Exception e) {
Log.e("BatchMixpanelDispatcher", "Something went wrong parsing deeplink: " + e.getLocalizedMessage());
}
// Copy from query parameters of the deeplink
copyValueFromQuery(uri, UTM_CONTENT, mixpanelParams, CONTENT);
}
// Load from custom payload
copyValueFromPayload(payload, UTM_CAMPAIGN, mixpanelParams, CAMPAIGN);
Expand All @@ -152,24 +157,29 @@ private static Map<String, Object> getNotificationParams(Batch.EventDispatcher.P

String deeplink = payload.getDeeplink();
if (deeplink != null) {
deeplink = deeplink.trim();
Uri uri = Uri.parse(deeplink);

String fragment = uri.getFragment();
if (fragment != null && !fragment.isEmpty()) {
Map<String, String> fragments = getFragmentMap(fragment);
// Copy from fragment part of the deeplink
copyValueFromMap(fragments, UTM_CAMPAIGN, mixpanelParams, CAMPAIGN);
copyValueFromMap(fragments, UTM_MEDIUM, mixpanelParams, MEDIUM);
copyValueFromMap(fragments, UTM_SOURCE, mixpanelParams, SOURCE);
copyValueFromMap(fragments, UTM_CONTENT, mixpanelParams, CONTENT);
}
try {
deeplink = deeplink.trim();
Uri uri = Uri.parse(deeplink);
if(uri.isHierarchical()) {
String fragment = uri.getFragment();
if (fragment != null && !fragment.isEmpty()) {
Map<String, String> fragments = getFragmentMap(fragment);
// Copy from fragment part of the deeplink
copyValueFromMap(fragments, UTM_CAMPAIGN, mixpanelParams, CAMPAIGN);
copyValueFromMap(fragments, UTM_MEDIUM, mixpanelParams, MEDIUM);
copyValueFromMap(fragments, UTM_SOURCE, mixpanelParams, SOURCE);
copyValueFromMap(fragments, UTM_CONTENT, mixpanelParams, CONTENT);
}

// Copy from query parameters of the deeplink
copyValueFromQuery(uri, UTM_CAMPAIGN, mixpanelParams, CAMPAIGN);
copyValueFromQuery(uri, UTM_MEDIUM, mixpanelParams, MEDIUM);
copyValueFromQuery(uri, UTM_SOURCE, mixpanelParams, SOURCE);
copyValueFromQuery(uri, UTM_CONTENT, mixpanelParams, CONTENT);
// Copy from query parameters of the deeplink
copyValueFromQuery(uri, UTM_CAMPAIGN, mixpanelParams, CAMPAIGN);
copyValueFromQuery(uri, UTM_MEDIUM, mixpanelParams, MEDIUM);
copyValueFromQuery(uri, UTM_SOURCE, mixpanelParams, SOURCE);
copyValueFromQuery(uri, UTM_CONTENT, mixpanelParams, CONTENT);
}
} catch (Exception e) {
Log.e("BatchMixpanelDispatcher", "Something went wrong parsing deeplink: " + e.getLocalizedMessage());
}
}
// Load from custom payload
copyValueFromPayload(payload, UTM_CAMPAIGN, mixpanelParams, CAMPAIGN);
Expand Down

0 comments on commit 009582a

Please sign in to comment.