Skip to content

Commit

Permalink
Adds attestation analytics events.
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosmuvi-stripe committed Jan 2, 2025
1 parent 5a1f7e4 commit 4e2309d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import com.stripe.android.financialconnections.FinancialConnectionsSheetViewEffe
import com.stripe.android.financialconnections.FinancialConnectionsSheetViewEffect.OpenNativeAuthFlow
import com.stripe.android.financialconnections.FinancialConnectionsSheetViewModel.Companion.QUERY_PARAM_PAYMENT_METHOD
import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsEvent
import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsEvent.AttestationInitFailed
import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsEvent.AttestationInitSucceeded
import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsTracker
import com.stripe.android.financialconnections.analytics.FinancialConnectionsEvent.ErrorCode
import com.stripe.android.financialconnections.analytics.FinancialConnectionsEvent.Metadata
Expand Down Expand Up @@ -129,17 +131,16 @@ internal class FinancialConnectionsSheetViewModel @Inject constructor(
}

private suspend fun prepareStandardRequestManager(): Boolean {
val result = integrityRequestManager.prepare()
result.exceptionOrNull()?.let {
analyticsTracker.track(
FinancialConnectionsAnalyticsEvent.Error(
extraMessage = "Failed to warm up the IntegrityStandardRequestManager",
pane = Pane.CONSENT,
exception = it
)
)
}
return result.isSuccess
return integrityRequestManager.prepare().fold(
onSuccess = {
analyticsTracker.track(AttestationInitSucceeded())
true
},
onFailure = {
analyticsTracker.track(AttestationInitFailed(reason = it.message ?: "Unknown error"))
false
}
)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,32 @@ internal sealed class FinancialConnectionsAnalyticsEvent(
).filterNotNullValues()
)

class AttestationInitSucceeded() : FinancialConnectionsAnalyticsEvent(
name = "attestation.init_succeeded"
)

class AttestationInitFailed(
reason: String
) : FinancialConnectionsAnalyticsEvent(
name = "attestation.init_failed",
mapOf(
"reason" to reason
)
)

class AttestationRequestSucceeded() : FinancialConnectionsAnalyticsEvent(
name = "attestation.request_token_succeeded"
)

class AttestationRequestFailed(
reason: String
) : FinancialConnectionsAnalyticsEvent(
name = "attestation.request_token_failed",
mapOf(
"reason" to reason
)
)

internal val Pane.analyticsValue
get() = when (this) {
// We want to log partner_auth regardless of the pane being shown full-screen or as a drawer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import android.app.Application
import com.stripe.android.financialconnections.FinancialConnectionsSheet
import com.stripe.android.financialconnections.repository.FinancialConnectionsConsumerSessionRepository
import com.stripe.android.model.ConsumerSessionLookup
import com.stripe.attestation.IntegrityRequestManager
import javax.inject.Inject

internal class LookupAccount @Inject constructor(
private val application: Application,
private val integrityRequestManager: IntegrityRequestManager,
private val requestIntegrityToken: RequestIntegrityToken,
private val consumerSessionRepository: FinancialConnectionsConsumerSessionRepository,
val configuration: FinancialConnectionsSheet.Configuration,
) {
Expand All @@ -19,10 +18,11 @@ internal class LookupAccount @Inject constructor(
verifiedFlow: Boolean
): ConsumerSessionLookup {
return if (verifiedFlow) {
val token = requestIntegrityToken()
requireNotNull(
consumerSessionRepository.mobileLookupConsumerSession(
email = email.lowercase().trim(),
verificationToken = integrityRequestManager.requestToken().getOrThrow(),
verificationToken = token,
appId = application.packageName
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.stripe.android.financialconnections.domain

import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsEvent.AttestationRequestFailed
import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsEvent.AttestationRequestSucceeded
import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsTracker
import com.stripe.attestation.IntegrityRequestManager

internal class RequestIntegrityToken(
private val integrityRequestManager: IntegrityRequestManager,
private val analyticsTracker: FinancialConnectionsAnalyticsTracker
) {
suspend operator fun invoke(): String = integrityRequestManager.requestToken()
.onSuccess {
analyticsTracker.track(
AttestationRequestSucceeded()
)
}
.onFailure {
analyticsTracker.track(
AttestationRequestFailed(it.message ?: "Unknown error")
)
}
.getOrThrow()
}

0 comments on commit 4e2309d

Please sign in to comment.