-
Notifications
You must be signed in to change notification settings - Fork 696
Introduce Intent Confirmation Challenge Analytics Events #12044
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
base: master
Are you sure you want to change the base?
Changes from all commits
377cf60
e1c5e34
b077102
82074a1
7f5864d
88bdac7
d92ae21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.stripe.android.challenge.confirmation | ||
|
|
||
| internal class BridgeException( | ||
| override val message: String?, | ||
| val type: String?, | ||
| val code: String?, | ||
| override val cause: Throwable? = null, | ||
| ) : Throwable() { | ||
| constructor(cause: Throwable?) : this( | ||
| message = cause?.message, | ||
| type = null, | ||
| code = null, | ||
| cause = cause | ||
| ) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package com.stripe.android.challenge.confirmation.analytics | ||
|
|
||
| import com.stripe.android.core.networking.AnalyticsRequestExecutor | ||
| import com.stripe.android.core.networking.AnalyticsRequestFactory | ||
| import com.stripe.android.core.utils.DurationProvider | ||
| import javax.inject.Inject | ||
| import kotlin.time.Duration | ||
| import kotlin.time.DurationUnit | ||
|
|
||
| internal class DefaultIntentConfirmationChallengeAnalyticsEventReporter @Inject constructor( | ||
| private val analyticsRequestExecutor: AnalyticsRequestExecutor, | ||
| private val analyticsRequestFactory: AnalyticsRequestFactory, | ||
| private val durationProvider: DurationProvider, | ||
| ) : IntentConfirmationChallengeAnalyticsEventReporter { | ||
|
|
||
| override fun start() { | ||
| durationProvider.start(DurationProvider.Key.IntentConfirmationChallenge) | ||
| durationProvider.start(DurationProvider.Key.IntentConfirmationChallengeWebViewLoaded) | ||
| fireEvent(IntentConfirmationChallengeAnalyticsEvent.Start()) | ||
| } | ||
|
|
||
| override fun success() { | ||
| val duration = durationProvider.end(DurationProvider.Key.IntentConfirmationChallenge) | ||
| fireEvent(IntentConfirmationChallengeAnalyticsEvent.Success(durationInMs(duration))) | ||
| } | ||
|
|
||
| override fun error( | ||
| errorType: String?, | ||
| errorCode: String?, | ||
| fromBridge: Boolean | ||
| ) { | ||
| val duration = durationProvider.end(DurationProvider.Key.IntentConfirmationChallenge) | ||
| fireEvent( | ||
| event = IntentConfirmationChallengeAnalyticsEvent.Error( | ||
| duration = durationInMs(duration), | ||
| errorType = errorType, | ||
| errorCode = errorCode, | ||
| fromBridge = fromBridge, | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| override fun webViewLoaded() { | ||
| val duration = durationProvider.end(DurationProvider.Key.IntentConfirmationChallengeWebViewLoaded) | ||
| fireEvent(IntentConfirmationChallengeAnalyticsEvent.WebViewLoaded(durationInMs(duration))) | ||
| } | ||
|
|
||
| private fun fireEvent(event: IntentConfirmationChallengeAnalyticsEvent) { | ||
| analyticsRequestExecutor.executeAsync( | ||
| analyticsRequestFactory.createRequest( | ||
| event = event, | ||
| additionalParams = event.params | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| private fun durationInMs(duration: Duration?) = duration?.toDouble(DurationUnit.MILLISECONDS)?.toFloat() ?: 0f | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package com.stripe.android.challenge.confirmation.analytics | ||
|
|
||
| import com.stripe.android.core.networking.AnalyticsEvent | ||
|
|
||
| internal sealed interface IntentConfirmationChallengeAnalyticsEvent : AnalyticsEvent { | ||
| val params: Map<String, Any?> | ||
|
|
||
| class Start : IntentConfirmationChallengeAnalyticsEvent { | ||
| override val params: Map<String, Any?> | ||
| get() = emptyMap() | ||
| override val eventName = "elements.intent_confirmation_challenge.start" | ||
| } | ||
|
|
||
| class Success(val duration: Float) : IntentConfirmationChallengeAnalyticsEvent { | ||
| override val params: Map<String, Any?> | ||
| get() = mapOf(FIELD_DURATION to duration) | ||
| override val eventName = "elements.intent_confirmation_challenge.success" | ||
| } | ||
|
|
||
| class Error( | ||
| val duration: Float, | ||
| val errorType: String?, | ||
| val errorCode: String?, | ||
| val fromBridge: Boolean | ||
| ) : IntentConfirmationChallengeAnalyticsEvent { | ||
| override val params: Map<String, Any?> | ||
| get() = mapOf( | ||
| FIELD_DURATION to duration, | ||
| FIELD_ERROR_TYPE to errorType, | ||
| FIELD_ERROR_CODE to errorCode, | ||
| FIELD_FROM_BRIDGE to fromBridge | ||
| ) | ||
| override val eventName = "elements.intent_confirmation_challenge.error" | ||
| } | ||
|
Comment on lines
+20
to
+34
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to log the error message as well, but there's PII concerns |
||
|
|
||
| class WebViewLoaded(val duration: Float) : IntentConfirmationChallengeAnalyticsEvent { | ||
| override val params: Map<String, Any?> | ||
| get() = mapOf(FIELD_DURATION to duration) | ||
| override val eventName = "elements.intent_confirmation_challenge.web_view_loaded" | ||
| } | ||
|
|
||
| companion object { | ||
| internal const val FIELD_DURATION = "duration" | ||
| internal const val FIELD_ERROR_TYPE = "error_type" | ||
| internal const val FIELD_ERROR_CODE = "error_code" | ||
| internal const val FIELD_FROM_BRIDGE = "from_bridge" | ||
| } | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In EventReporter, we name these functions |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.stripe.android.challenge.confirmation.analytics | ||
|
|
||
| internal interface IntentConfirmationChallengeAnalyticsEventReporter { | ||
| fun start() | ||
|
|
||
| fun success() | ||
|
|
||
| fun error( | ||
| errorType: String?, | ||
| errorCode: String?, | ||
| fromBridge: Boolean | ||
| ) | ||
|
|
||
| fun webViewLoaded() | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just an FYI -- I think that if you use the git mv command (e.g. to move BridgeError to BridgeException) then you'll get a much smaller and nicer diff