Skip to content

Commit

Permalink
Merge pull request #1882 from Adyen/feature/analytics_track_redirect_…
Browse files Browse the repository at this point in the history
…error_events

Analytics - Track redirect error events
  • Loading branch information
araratthehero authored Nov 19, 2024
2 parents a0123c6 + 692e058 commit 091f501
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
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

0 comments on commit 091f501

Please sign in to comment.