From 88f697269ef97d4000db320265544a57624e7741 Mon Sep 17 00:00:00 2001 From: Ararat Mnatsakanyan Date: Thu, 7 Nov 2024 15:26:30 +0100 Subject: [PATCH 1/4] Add target to error events COAND-1006 --- .../components/core/internal/analytics/GenericEvents.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components-core/src/main/java/com/adyen/checkout/components/core/internal/analytics/GenericEvents.kt b/components-core/src/main/java/com/adyen/checkout/components/core/internal/analytics/GenericEvents.kt index 226dd931db..d6d3c4d561 100644 --- a/components-core/src/main/java/com/adyen/checkout/components/core/internal/analytics/GenericEvents.kt +++ b/components-core/src/main/java/com/adyen/checkout/components/core/internal/analytics/GenericEvents.kt @@ -128,9 +128,11 @@ object GenericEvents { fun error( component: String, event: ErrorEvent, + target: String? = null, ) = AnalyticsEvent.Error( component = component, errorType = event.errorType, code = event.errorCode, + target = target, ) } From 7b9fe18ee536fb7c605ef5e902b0eb67dfff13b5 Mon Sep 17 00:00:00 2001 From: Ararat Mnatsakanyan Date: Thu, 7 Nov 2024 15:26:49 +0100 Subject: [PATCH 2/4] Track redirect failed event COAND-1006 --- .../internal/ui/DefaultRedirectDelegate.kt | 7 +++++++ .../internal/ui/DefaultRedirectDelegateTest.kt | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/redirect/src/main/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegate.kt b/redirect/src/main/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegate.kt index de0baabdc1..c5f3ef6314 100644 --- a/redirect/src/main/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegate.kt +++ b/redirect/src/main/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegate.kt @@ -23,6 +23,7 @@ import com.adyen.checkout.components.core.internal.PaymentDataRepository import com.adyen.checkout.components.core.internal.SavedStateHandleContainer import com.adyen.checkout.components.core.internal.SavedStateHandleProperty import com.adyen.checkout.components.core.internal.analytics.AnalyticsManager +import com.adyen.checkout.components.core.internal.analytics.ErrorEvent import com.adyen.checkout.components.core.internal.analytics.GenericEvents import com.adyen.checkout.components.core.internal.ui.model.GenericComponentParams import com.adyen.checkout.components.core.internal.util.bufferedChannel @@ -139,6 +140,12 @@ constructor( // PaymentComponentState for actions. redirectHandler.launchUriRedirect(activity, url) } catch (ex: CheckoutException) { + val event = GenericEvents.error( + component = action?.paymentMethodType.orEmpty(), + event = ErrorEvent.REDIRECT_FAILED + ) + analyticsManager?.trackEvent(event) + emitError(ex) } } diff --git a/redirect/src/test/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegateTest.kt b/redirect/src/test/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegateTest.kt index 0cb1c80fa4..4a085015e5 100644 --- a/redirect/src/test/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegateTest.kt +++ b/redirect/src/test/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegateTest.kt @@ -17,6 +17,7 @@ import com.adyen.checkout.components.core.action.ActionTypes import com.adyen.checkout.components.core.action.RedirectAction import com.adyen.checkout.components.core.internal.ActionObserverRepository import com.adyen.checkout.components.core.internal.PaymentDataRepository +import com.adyen.checkout.components.core.internal.analytics.ErrorEvent import com.adyen.checkout.components.core.internal.analytics.GenericEvents import com.adyen.checkout.components.core.internal.analytics.TestAnalyticsManager import com.adyen.checkout.components.core.internal.ui.model.CommonComponentParamsMapper @@ -199,6 +200,23 @@ internal class DefaultRedirectDelegateTest( ) analyticsManager.assertLastEventEquals(expectedEvent) } + + @Test + fun `when handleAction called and redirect fails, then an event is tracked`() = runTest { + val action = RedirectAction( + paymentMethodType = TEST_PAYMENT_METHOD_TYPE, + type = TEST_ACTION_TYPE, + ) + redirectHandler.exception = ComponentException("Failed to launch redirect.") + + delegate.handleAction(action, Activity()) + + val expectedEvent = GenericEvents.error( + component = TEST_PAYMENT_METHOD_TYPE, + event = ErrorEvent.REDIRECT_FAILED, + ) + analyticsManager.assertLastEventEquals(expectedEvent) + } } @Test From 0b7532c0b338ebf4c0fc53ac0de24ee19ab54a3d Mon Sep 17 00:00:00 2001 From: Ararat Mnatsakanyan Date: Thu, 7 Nov 2024 15:27:01 +0100 Subject: [PATCH 3/4] Track redirect parse failed event COAND-1006 --- .../internal/ui/DefaultRedirectDelegate.kt | 6 ++++++ .../ui/DefaultRedirectDelegateTest.kt | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/redirect/src/main/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegate.kt b/redirect/src/main/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegate.kt index c5f3ef6314..227fc4cb85 100644 --- a/redirect/src/main/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegate.kt +++ b/redirect/src/main/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegate.kt @@ -164,6 +164,12 @@ constructor( } } } catch (ex: CheckoutException) { + val event = GenericEvents.error( + component = action?.paymentMethodType.orEmpty(), + event = ErrorEvent.REDIRECT_PARSE_FAILED + ) + analyticsManager?.trackEvent(event) + emitError(ex) } } diff --git a/redirect/src/test/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegateTest.kt b/redirect/src/test/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegateTest.kt index 4a085015e5..8643e3c165 100644 --- a/redirect/src/test/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegateTest.kt +++ b/redirect/src/test/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegateTest.kt @@ -217,6 +217,25 @@ internal class DefaultRedirectDelegateTest( ) analyticsManager.assertLastEventEquals(expectedEvent) } + + @Test + fun `when handleIntent called and parsing redirect result fails, then an event is tracked`() = runTest { + val action = RedirectAction( + paymentMethodType = TEST_PAYMENT_METHOD_TYPE, + type = TEST_ACTION_TYPE, + ) + + delegate.handleAction(action, Activity()) + redirectHandler.exception = ComponentException("Failed to parse redirect result.") + + delegate.handleIntent(Intent()) + + val expectedEvent = GenericEvents.error( + component = TEST_PAYMENT_METHOD_TYPE, + event = ErrorEvent.REDIRECT_PARSE_FAILED, + ) + analyticsManager.assertLastEventEquals(expectedEvent) + } } @Test From 692e0586df0a15c9176f52d04aa9a586d7af9851 Mon Sep 17 00:00:00 2001 From: Ararat Mnatsakanyan Date: Thu, 7 Nov 2024 15:27:18 +0100 Subject: [PATCH 4/4] Track redirect cancelled event COAND-1006 --- .../internal/ui/DefaultRedirectDelegate.kt | 9 +++++++++ .../ui/DefaultRedirectDelegateTest.kt | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/redirect/src/main/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegate.kt b/redirect/src/main/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegate.kt index 227fc4cb85..061b4b2ef0 100644 --- a/redirect/src/main/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegate.kt +++ b/redirect/src/main/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegate.kt @@ -28,6 +28,7 @@ import com.adyen.checkout.components.core.internal.analytics.GenericEvents import com.adyen.checkout.components.core.internal.ui.model.GenericComponentParams import com.adyen.checkout.components.core.internal.util.bufferedChannel import com.adyen.checkout.core.AdyenLogLevel +import com.adyen.checkout.core.exception.CancellationException import com.adyen.checkout.core.exception.CheckoutException import com.adyen.checkout.core.exception.ComponentException import com.adyen.checkout.core.exception.HttpException @@ -200,6 +201,14 @@ constructor( } override fun onError(e: CheckoutException) { + if (e is CancellationException) { + val event = GenericEvents.error( + component = action?.paymentMethodType.orEmpty(), + event = ErrorEvent.REDIRECT_CANCELLED + ) + analyticsManager?.trackEvent(event) + } + emitError(e) } diff --git a/redirect/src/test/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegateTest.kt b/redirect/src/test/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegateTest.kt index 8643e3c165..d57fa4bede 100644 --- a/redirect/src/test/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegateTest.kt +++ b/redirect/src/test/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegateTest.kt @@ -23,6 +23,7 @@ import com.adyen.checkout.components.core.internal.analytics.TestAnalyticsManage import com.adyen.checkout.components.core.internal.ui.model.CommonComponentParamsMapper import com.adyen.checkout.components.core.internal.ui.model.GenericComponentParamsMapper import com.adyen.checkout.core.Environment +import com.adyen.checkout.core.exception.CancellationException import com.adyen.checkout.core.exception.ComponentException import com.adyen.checkout.core.exception.HttpException import com.adyen.checkout.core.exception.ModelSerializationException @@ -236,6 +237,24 @@ internal class DefaultRedirectDelegateTest( ) analyticsManager.assertLastEventEquals(expectedEvent) } + + @Test + fun `when redirect is cancelled with CancellationException, then an event is tracked`() = runTest { + val action = RedirectAction( + paymentMethodType = TEST_PAYMENT_METHOD_TYPE, + type = TEST_ACTION_TYPE, + ) + delegate.handleAction(action, Activity()) + + val exception = CancellationException("Redirect flow cancelled.") + delegate.onError(exception) + + val expectedEvent = GenericEvents.error( + component = TEST_PAYMENT_METHOD_TYPE, + event = ErrorEvent.REDIRECT_CANCELLED, + ) + analyticsManager.assertLastEventEquals(expectedEvent) + } } @Test