Skip to content

Commit

Permalink
Add analytics for vertical mode. (#9403)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaynewstrom-stripe authored Oct 4, 2024
1 parent eeccda0 commit a6a1bf7
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,11 @@ internal fun List<CardBrand>.toAnalyticsValue(): String? {
internal fun PaymentSheet.Configuration.getExternalPaymentMethodsAnalyticsValue(): List<String>? {
return this.externalPaymentMethods.takeIf { it.isNotEmpty() }?.take(PaymentSheetEvent.MAX_EXTERNAL_PAYMENT_METHODS)
}

internal fun PaymentSheet.PaymentMethodLayout.toAnalyticsValue(): String {
return when (this) {
PaymentSheet.PaymentMethodLayout.Horizontal -> "horizontal"
PaymentSheet.PaymentMethodLayout.Vertical -> "vertical"
PaymentSheet.PaymentMethodLayout.Automatic -> "automatic"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ internal sealed class PaymentSheetEvent : AnalyticsEvent {
),
FIELD_PREFERRED_NETWORKS to configuration.preferredNetworks.toAnalyticsValue(),
FIELD_EXTERNAL_PAYMENT_METHODS to configuration.getExternalPaymentMethodsAnalyticsValue(),
FIELD_PAYMENT_METHOD_LAYOUT to configuration.paymentMethodLayout.toAnalyticsValue(),
)
return mapOf(
FIELD_MOBILE_PAYMENT_ELEMENT_CONFIGURATION to configurationMap,
Expand Down Expand Up @@ -495,6 +496,7 @@ internal sealed class PaymentSheetEvent : AnalyticsEvent {
const val FIELD_SELECTED_CARD_BRAND = "selected_card_brand"
const val FIELD_LINK_CONTEXT = "link_context"
const val FIELD_EXTERNAL_PAYMENT_METHODS = "external_payment_methods"
const val FIELD_PAYMENT_METHOD_LAYOUT = "payment_method_layout"
const val FIELD_COMPOSE = "compose"
const val FIELD_INTENT_TYPE = "intent_type"
const val FIELD_LINK_MODE = "link_mode"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class PaymentSheetEventTest {
),
"preferred_networks" to null,
"external_payment_methods" to null,
"payment_method_layout" to "horizontal",
)

assertThat(event.params).run {
Expand Down Expand Up @@ -138,6 +139,70 @@ class PaymentSheetEventTest {
),
"preferred_networks" to null,
"external_payment_methods" to listOf("external_paypal", "external_fawry"),
"payment_method_layout" to "horizontal",
)

assertThat(event.params).run {
containsEntry("link_enabled", false)
containsEntry("google_pay_enabled", false)
containsEntry("is_decoupled", false)
containsEntry("mpe_config", expectedConfig)
}
}

@Test
fun `Init event with vertical mode should return expected params`() {
val event = PaymentSheetEvent.Init(
mode = EventReporter.Mode.Complete,
configuration = PaymentSheetFixtures.CONFIG_CUSTOMER
.copy(paymentMethodLayout = PaymentSheet.PaymentMethodLayout.Vertical),
isDeferred = false,
linkEnabled = false,
googlePaySupported = false,
)

assertThat(
event.eventName
).isEqualTo(
"mc_complete_init_customer"
)

val expectedConfig = mapOf(
"customer" to true,
"customer_access_provider" to "legacy",
"googlepay" to false,
"primary_button_color" to false,
"default_billing_details" to false,
"allows_delayed_payment_methods" to false,
"appearance" to mapOf(
"colorsLight" to false,
"colorsDark" to false,
"corner_radius" to false,
"border_width" to false,
"font" to false,
"size_scale_factor" to false,
"primary_button" to mapOf(
"colorsLight" to false,
"colorsDark" to false,
"corner_radius" to false,
"border_width" to false,
"font" to false,
),
"usage" to false,
),
"payment_method_order" to listOf<String>(),
"allows_payment_methods_requiring_shipping_address" to false,
"allows_removal_of_last_saved_payment_method" to true,
"billing_details_collection_configuration" to mapOf(
"attach_defaults" to false,
"name" to "Automatic",
"email" to "Automatic",
"phone" to "Automatic",
"address" to "Automatic",
),
"preferred_networks" to null,
"external_payment_methods" to null,
"payment_method_layout" to "vertical",
)

assertThat(event.params).run {
Expand Down Expand Up @@ -199,6 +264,7 @@ class PaymentSheetEventTest {
),
"preferred_networks" to null,
"external_payment_methods" to null,
"payment_method_layout" to "horizontal",
)

assertThat(event.params).run {
Expand Down Expand Up @@ -262,6 +328,7 @@ class PaymentSheetEventTest {
),
"preferred_networks" to "cartes_bancaires, visa",
"external_payment_methods" to null,
"payment_method_layout" to "horizontal",
)

assertThat(event.params).run {
Expand Down Expand Up @@ -1231,6 +1298,7 @@ class PaymentSheetEventTest {
"billing_details_collection_configuration" to expectedBillingDetailsCollection,
"preferred_networks" to null,
"external_payment_methods" to null,
"payment_method_layout" to "horizontal",
)
assertThat(
PaymentSheetEvent.Init(
Expand Down Expand Up @@ -1290,6 +1358,7 @@ class PaymentSheetEventTest {
"billing_details_collection_configuration" to expectedBillingDetailsCollection,
"preferred_networks" to null,
"external_payment_methods" to null,
"payment_method_layout" to "horizontal",
)
assertThat(
PaymentSheetEvent.Init(
Expand Down

0 comments on commit a6a1bf7

Please sign in to comment.