diff --git a/CHANGELOG.md b/CHANGELOG.md index e44e46371b..562cb49d1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * BraintreePayPal * Add `shopperSessionId` to `PayPalCheckoutRequest` and `PayPalVaultRequest` * Replace `sendPayPalPresentedEvent()` and `sendVenmoPresentedEvent()` with `sendPresentedEvent()` + * Replace `sendPayPalSelectedEvent()` and `sendVenmoSelectedEvent()` with `sendSelectedEvent()` ## 5.3.0 (2024-12-11) diff --git a/Demo/src/main/java/com/braintreepayments/demo/ShopperInsightsFragment.kt b/Demo/src/main/java/com/braintreepayments/demo/ShopperInsightsFragment.kt index 9faefbde02..d6a666f376 100644 --- a/Demo/src/main/java/com/braintreepayments/demo/ShopperInsightsFragment.kt +++ b/Demo/src/main/java/com/braintreepayments/demo/ShopperInsightsFragment.kt @@ -236,7 +236,9 @@ class ShopperInsightsFragment : BaseFragment() { } private fun launchPayPalVault() { - shopperInsightsClient.sendPayPalSelectedEvent() + shopperInsightsClient.sendSelectedEvent( + ButtonType.PAYPAL + ) payPalClient.createPaymentAuthRequest( requireContext(), @@ -274,7 +276,9 @@ class ShopperInsightsFragment : BaseFragment() { } private fun launchVenmo() { - shopperInsightsClient.sendVenmoSelectedEvent() + shopperInsightsClient.sendSelectedEvent( + ButtonType.VENMO + ) val venmoRequest = VenmoRequest(VenmoPaymentMethodUsage.SINGLE_USE) venmoRequest.profileId = null diff --git a/ShopperInsights/src/main/java/com/braintreepayments/api/shopperinsights/ShopperInsightsAnalytics.kt b/ShopperInsights/src/main/java/com/braintreepayments/api/shopperinsights/ShopperInsightsAnalytics.kt index c7a3cc60ce..2da495e97c 100644 --- a/ShopperInsights/src/main/java/com/braintreepayments/api/shopperinsights/ShopperInsightsAnalytics.kt +++ b/ShopperInsights/src/main/java/com/braintreepayments/api/shopperinsights/ShopperInsightsAnalytics.kt @@ -1,8 +1,7 @@ package com.braintreepayments.api.shopperinsights internal object ShopperInsightsAnalytics { - const val PAYPAL_SELECTED = "shopper-insights:paypal-selected" - const val VENMO_SELECTED = "shopper-insights:venmo-selected" + const val BUTTON_SELECTED = "shopper-insights:button-selected" const val BUTTON_PRESENTED = "shopper-insights:button-presented" const val GET_RECOMMENDED_PAYMENTS_FAILED = "shopper-insights:get-recommended-payments:failed" diff --git a/ShopperInsights/src/main/java/com/braintreepayments/api/shopperinsights/ShopperInsightsClient.kt b/ShopperInsights/src/main/java/com/braintreepayments/api/shopperinsights/ShopperInsightsClient.kt index 3eb6d503ae..12090c3375 100644 --- a/ShopperInsights/src/main/java/com/braintreepayments/api/shopperinsights/ShopperInsightsClient.kt +++ b/ShopperInsights/src/main/java/com/braintreepayments/api/shopperinsights/ShopperInsightsClient.kt @@ -10,11 +10,10 @@ import com.braintreepayments.api.core.ExperimentalBetaApi import com.braintreepayments.api.core.MerchantRepository import com.braintreepayments.api.core.TokenizationKey import com.braintreepayments.api.shopperinsights.ShopperInsightsAnalytics.BUTTON_PRESENTED +import com.braintreepayments.api.shopperinsights.ShopperInsightsAnalytics.BUTTON_SELECTED import com.braintreepayments.api.shopperinsights.ShopperInsightsAnalytics.GET_RECOMMENDED_PAYMENTS_FAILED import com.braintreepayments.api.shopperinsights.ShopperInsightsAnalytics.GET_RECOMMENDED_PAYMENTS_STARTED import com.braintreepayments.api.shopperinsights.ShopperInsightsAnalytics.GET_RECOMMENDED_PAYMENTS_SUCCEEDED -import com.braintreepayments.api.shopperinsights.ShopperInsightsAnalytics.PAYPAL_SELECTED -import com.braintreepayments.api.shopperinsights.ShopperInsightsAnalytics.VENMO_SELECTED /** * Use [ShopperInsightsClient] to optimize your checkout experience @@ -166,7 +165,7 @@ class ShopperInsightsClient internal constructor( } /** - * Call this method when the PayPal button has been successfully displayed to the buyer. + * Call this method when the PayPal, Venmo or Other button has been successfully displayed to the buyer. * This method sends analytics to help improve the Shopper Insights feature experience. * @param buttonType Type of button presented - PayPal, Venmo, or Other. * @param presentmentDetails Detailed information, including button order, experiment type, @@ -189,19 +188,19 @@ class ShopperInsightsClient internal constructor( } /** - * Call this method when the PayPal button has been selected/tapped by the buyer. + * Call this method when the PayPal, Venmo or Other button has been selected/tapped by the buyer. * This method sends analytics to help improve the Shopper Insights feature experience. + * @param buttonType Type of button presented - PayPal, Venmo, or Other. */ - fun sendPayPalSelectedEvent() { - braintreeClient.sendAnalyticsEvent(PAYPAL_SELECTED, analyticsParams) - } + fun sendSelectedEvent( + buttonType: ButtonType, + ) { + val params = AnalyticsEventParams( + shopperSessionId = shopperSessionId, + buttonType = buttonType.getStringRepresentation(), + ) - /** - * Call this method when the Venmo button has been selected/tapped by the buyer. - * This method sends analytics to help improve the Shopper Insights feature experience. - */ - fun sendVenmoSelectedEvent() { - braintreeClient.sendAnalyticsEvent(VENMO_SELECTED, analyticsParams) + braintreeClient.sendAnalyticsEvent(BUTTON_SELECTED, params) } /** diff --git a/ShopperInsights/src/test/java/com/braintreepayments/api/shopperinsights/ShopperInsightsClientUnitTest.kt b/ShopperInsights/src/test/java/com/braintreepayments/api/shopperinsights/ShopperInsightsClientUnitTest.kt index 1b2fd53839..146dd23a9b 100644 --- a/ShopperInsights/src/test/java/com/braintreepayments/api/shopperinsights/ShopperInsightsClientUnitTest.kt +++ b/ShopperInsights/src/test/java/com/braintreepayments/api/shopperinsights/ShopperInsightsClientUnitTest.kt @@ -438,7 +438,6 @@ class ShopperInsightsClientUnitTest { @Test fun `test paypal button presented analytics event`() { - // A Test type, with a button in the first position displayed in the mini cart. val presentmentDetails = PresentmentDetails( ExperimentType.TEST, @@ -467,7 +466,6 @@ class ShopperInsightsClientUnitTest { @Test fun `test venmo button presented analytics event`() { - // A Control type, with a button in the second position displayed on the homepage. val presentmentDetails = PresentmentDetails( ExperimentType.CONTROL, @@ -490,22 +488,35 @@ class ShopperInsightsClientUnitTest { PageType.HOMEPAGE ) ) + verify { braintreeClient.sendAnalyticsEvent("shopper-insights:button-presented", params) } } @Test fun `test paypal selected analytics event`() { - sut.sendPayPalSelectedEvent() - verify { braintreeClient.sendAnalyticsEvent("shopper-insights:paypal-selected", - AnalyticsEventParams(shopperSessionId = shopperSessionId)) } + val params = AnalyticsEventParams( + shopperSessionId = shopperSessionId, + buttonType = ButtonType.PAYPAL.getStringRepresentation() + ) + sut.sendSelectedEvent( + ButtonType.PAYPAL + ) + verify { braintreeClient.sendAnalyticsEvent("shopper-insights:button-selected", + params) } } @Test fun `test venmo selected analytics event`() { - sut.sendVenmoSelectedEvent() - verify { braintreeClient.sendAnalyticsEvent("shopper-insights:venmo-selected", - AnalyticsEventParams(shopperSessionId = shopperSessionId)) } + val params = AnalyticsEventParams( + shopperSessionId = shopperSessionId, + buttonType = ButtonType.VENMO.getStringRepresentation(), + ) + sut.sendSelectedEvent( + ButtonType.VENMO, + ) + verify { braintreeClient.sendAnalyticsEvent("shopper-insights:button-selected", + params) } } @Test