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

Analytics - Track redirect error events #1882

Merged
merged 4 commits into from
Nov 19, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ 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
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
Expand Down Expand Up @@ -139,6 +141,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)
}
}
Expand All @@ -157,6 +165,12 @@ constructor(
}
}
} catch (ex: CheckoutException) {
val event = GenericEvents.error(
component = action?.paymentMethodType.orEmpty(),
event = ErrorEvent.REDIRECT_PARSE_FAILED
)
analyticsManager?.trackEvent(event)

emitError(ex)
}
}
Expand Down Expand Up @@ -187,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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ 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
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
Expand Down Expand Up @@ -199,6 +201,60 @@ 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
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
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
Expand Down