Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: fix parsing non hierarchical uri #2

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading