From d4c7a21037fe812551a3892f4ad2401c5d0420a2 Mon Sep 17 00:00:00 2001 From: Stephanie <127455800+stechiu@users.noreply.github.com> Date: Fri, 20 Dec 2024 12:39:36 -0800 Subject: [PATCH] Shopper Insights - Update `sendSelected` Events (#1486) * Added BTButtonType enum and `sendSelectedEvent()` * Updated unit tests * Addressed PR comments * Fixed failing unit test * Removed unnecessary unit tests * add parameters to docstring for presented event --------- Co-authored-by: Jax DesMarais-Leder --- CHANGELOG.md | 1 + .../ShopperInsightsViewController.swift | 4 ++-- .../BTShopperInsightsAnalytics.swift | 8 +++----- .../BTShopperInsightsClient.swift | 19 +++++++++---------- .../BTShopperInsightsAnalytics_Tests.swift | 4 +--- .../BTShopperInsightsClient_Tests.swift | 14 ++++++++------ .../BraintreeTestShared/MockAPIClient.swift | 2 +- 7 files changed, 25 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92c1cda7a..52c0d6e5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * `experimentType` * `pageType` * `buttonOrder` + * Replace `sendPayPalSelectedEvent()` and `sendPayPalSelectedEvent()` with `sendSelectedEvent(for:)` ## 6.25.0 (2024-12-11) * BraintreePayPal diff --git a/Demo/Application/Features/ShopperInsightsViewController.swift b/Demo/Application/Features/ShopperInsightsViewController.swift index 47c8ace2b..2e9778fbb 100644 --- a/Demo/Application/Features/ShopperInsightsViewController.swift +++ b/Demo/Application/Features/ShopperInsightsViewController.swift @@ -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 @@ -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 diff --git a/Sources/BraintreeShopperInsights/BTShopperInsightsAnalytics.swift b/Sources/BraintreeShopperInsights/BTShopperInsightsAnalytics.swift index e00f0fbfd..4ef6d8f58 100644 --- a/Sources/BraintreeShopperInsights/BTShopperInsightsAnalytics.swift +++ b/Sources/BraintreeShopperInsights/BTShopperInsightsAnalytics.swift @@ -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" diff --git a/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift b/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift index 2dc4de8d0..23564fe1e 100644 --- a/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift +++ b/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift @@ -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. diff --git a/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsAnalytics_Tests.swift b/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsAnalytics_Tests.swift index 54578a829..713762c7c 100644 --- a/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsAnalytics_Tests.swift +++ b/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsAnalytics_Tests.swift @@ -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") diff --git a/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift b/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift index 8440ac76f..27ac9c74f 100644 --- a/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift +++ b/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift @@ -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 { @@ -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) + 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, @@ -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") } diff --git a/UnitTests/BraintreeTestShared/MockAPIClient.swift b/UnitTests/BraintreeTestShared/MockAPIClient.swift index ba9b05d81..3fe91dd29 100644 --- a/UnitTests/BraintreeTestShared/MockAPIClient.swift +++ b/UnitTests/BraintreeTestShared/MockAPIClient.swift @@ -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