diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d4b59b..32fead9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ----- @@ -17,4 +22,4 @@ 1.0 ----- - * Dispatcher release. \ No newline at end of file + * Dispatcher release. diff --git a/mixpanel-dispatcher/src/main/java/com/batch/android/dispatcher/mixpanel/MixpanelDispatcher.java b/mixpanel-dispatcher/src/main/java/com/batch/android/dispatcher/mixpanel/MixpanelDispatcher.java index 55889d7..117da54 100644 --- a/mixpanel-dispatcher/src/main/java/com/batch/android/dispatcher/mixpanel/MixpanelDispatcher.java +++ b/mixpanel-dispatcher/src/main/java/com/batch/android/dispatcher/mixpanel/MixpanelDispatcher.java @@ -126,17 +126,22 @@ private static Map 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 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 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); @@ -152,24 +157,29 @@ private static Map 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 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 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);