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 - Update sendSelected Events #1486

Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* `experimentType`
* `pageType`
* `buttonOrder`
* Replace `sendPayPalSelectedEvent()` and `sendPayPalSelectedEvent()` with `sendSelectedEvent(for:)`

## 6.25.0 (2024-12-11)
* BraintreePayPal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class ShopperInsightsViewController: PaymentButtonBaseViewController {

@objc func payPalVaultButtonTapped(_ button: UIButton) {
progressBlock("Tapped PayPal Vault")
shopperInsightsClient.sendPayPalSelectedEvent()
shopperInsightsClient.sendSelectedEvent(for: .payPal)

button.setTitle("Processing...", for: .disabled)
button.isEnabled = false
Expand All @@ -157,7 +157,7 @@ class ShopperInsightsViewController: PaymentButtonBaseViewController {

@objc func venmoButtonTapped(_ button: UIButton) {
progressBlock("Tapped Venmo")
shopperInsightsClient.sendVenmoSelectedEvent()
shopperInsightsClient.sendSelectedEvent(for: .venmo)

button.setTitle("Processing...", for: .disabled)
button.isEnabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import Foundation
enum BTShopperInsightsAnalytics {

// MARK: - Merchant Triggered Events

static let payPalSelected = "shopper-insights:paypal-selected"
static let venmoSelected = "shopper-insights:venmo-selected"


static let buttonPresented = "shopper-insights:button-presented"

static let buttonSelected = "shopper-insights:button-selected"

// MARK: - SDK Triggered Events

static let recommendedPaymentsStarted = "shopper-insights:get-recommended-payments:started"
Expand Down
19 changes: 9 additions & 10 deletions Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,16 @@ public class BTShopperInsightsClient {
shopperSessionID: shopperSessionID
)
}

/// Call this method when the PayPal button has been selected/tapped by the buyer.
/// This method sends analytics to help improve the Shopper Insights feature experience
public func sendPayPalSelectedEvent() {
apiClient.sendAnalyticsEvent(BTShopperInsightsAnalytics.payPalSelected, shopperSessionID: shopperSessionID)
}

/// 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
public func sendVenmoSelectedEvent() {
apiClient.sendAnalyticsEvent(BTShopperInsightsAnalytics.venmoSelected, shopperSessionID: shopperSessionID)
/// Call this method when a button has been selected/tapped by the buyer.
/// This method sends analytics to help improve the Shopper Insights feature experience.
/// - Parameter buttonType: Type of button presented - PayPal, Venmo, or Other
public func sendSelectedEvent(for buttonType: BTButtonType) {
apiClient.sendAnalyticsEvent(
BTShopperInsightsAnalytics.buttonSelected,
buttonType: buttonType.rawValue,
shopperSessionID: shopperSessionID
)
}

/// Indicates whether the PayPal App is installed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ final class BTShopperInsightsAnalytics_Tests: XCTestCase {

func test_recommendedPaymentAnalyticEvents_sendExpectedEventNames() {
XCTAssertEqual(BTShopperInsightsAnalytics.buttonPresented, "shopper-insights:button-presented")
XCTAssertEqual(BTShopperInsightsAnalytics.payPalSelected, "shopper-insights:paypal-selected")
XCTAssertEqual(BTShopperInsightsAnalytics.buttonPresented, "shopper-insights:button-presented")
XCTAssertEqual(BTShopperInsightsAnalytics.venmoSelected, "shopper-insights:venmo-selected")
XCTAssertEqual(BTShopperInsightsAnalytics.buttonSelected, "shopper-insights:button-selected")
XCTAssertEqual(BTShopperInsightsAnalytics.recommendedPaymentsStarted, "shopper-insights:get-recommended-payments:started")
XCTAssertEqual(BTShopperInsightsAnalytics.recommendedPaymentsSucceeded, "shopper-insights:get-recommended-payments:succeeded")
XCTAssertEqual(BTShopperInsightsAnalytics.recommendedPaymentsFailed, "shopper-insights:get-recommended-payments:failed")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class BTShopperInsightsClient_Tests: XCTestCase {
}

func testGetRecommendedPaymentMethods_withTokenizationKey_returnsError() async {
var apiClient = BTAPIClient(authorization: "sandbox_merchant_1234567890abc")!
let apiClient = BTAPIClient(authorization: "sandbox_merchant_1234567890abc")!
let shopperInsightsClient = BTShopperInsightsClient(apiClient: apiClient)

do {
Expand Down Expand Up @@ -243,11 +243,12 @@ class BTShopperInsightsClient_Tests: XCTestCase {
}

func testSendPayPalSelectedEvent_sendsAnalytic() {
sut.sendPayPalSelectedEvent()
XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:paypal-selected")
sut.sendSelectedEvent(for: .payPal)
stechiu marked this conversation as resolved.
Show resolved Hide resolved
XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:button-selected")
XCTAssertEqual(mockAPIClient.postedShopperSessionID, "fake-shopper-session-id")
XCTAssertEqual(mockAPIClient.postedButtonType, "PayPal")
}

func testSendVenmoPresentedEvent_sendsAnalytic() {
let presentmentDetails = BTPresentmentDetails(
buttonOrder: .first,
Expand Down Expand Up @@ -285,8 +286,9 @@ class BTShopperInsightsClient_Tests: XCTestCase {
}

func testSendVenmoSelectedEvent_sendsAnalytic() {
sut.sendVenmoSelectedEvent()
XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:venmo-selected")
sut.sendSelectedEvent(for: .venmo)
XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:button-selected")
XCTAssertEqual(mockAPIClient.postedButtonType, "Venmo")
XCTAssertEqual(mockAPIClient.postedShopperSessionID, "fake-shopper-session-id")
}

Expand Down
2 changes: 1 addition & 1 deletion UnitTests/BraintreeTestShared/MockAPIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class MockAPIClient: BTAPIClient {
public var lastGETParameters = [:] as [String: Any]?
public var lastGETAPIClientHTTPType: BTAPIClientHTTPService?

public var postedAnalyticsEvents : [String] = []
public var postedAnalyticsEvents: [String] = []
public var postedAppSwitchURL: [String: String?] = [:]
public var postedButtonOrder: String? = nil
public var postedButtonType: String? = nil
Expand Down