Skip to content
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

Shopper insights rp2 feature selected event button #1247

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ class ShopperInsightsFragment : BaseFragment() {
}

private fun launchPayPalVault() {
shopperInsightsClient.sendPayPalSelectedEvent()
shopperInsightsClient.sendSelectedEvent(
ButtonType.PAYPAL
)

payPalClient.createPaymentAuthRequest(
requireContext(),
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
Loading