From 4b4579d1b35cbf4da39d862313c6a6dd0a3e70d9 Mon Sep 17 00:00:00 2001 From: stechiu Date: Fri, 13 Dec 2024 16:16:08 -0800 Subject: [PATCH 1/7] Added BTButtonType enum and `sendSelectedEvent()` --- Braintree.xcodeproj/project.pbxproj | 4 ++++ CHANGELOG.md | 1 + .../ShopperInsightsViewController.swift | 4 ++-- .../Analytics/FPTIBatchData.swift | 2 ++ Sources/BraintreeCore/BTAPIClient.swift | 2 ++ .../BTButtonType.swift | 10 ++++++++++ .../BTShopperInsightsClient.swift | 18 ++++++------------ 7 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 Sources/BraintreeShopperInsights/BTButtonType.swift diff --git a/Braintree.xcodeproj/project.pbxproj b/Braintree.xcodeproj/project.pbxproj index 38a990360..ed219fdc4 100644 --- a/Braintree.xcodeproj/project.pbxproj +++ b/Braintree.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 04B001122D0D02CF00C0060D /* BTButtonType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04B001112D0D02CB00C0060D /* BTButtonType.swift */; }; 0917F6E42A27BDC700ACED2E /* BTVenmoLineItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 096C6B2529CCDCEB00912863 /* BTVenmoLineItem.swift */; }; 09357DCB2A2FBEC10096D449 /* BTVenmoLineItem_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09357DCA2A2FBEC10096D449 /* BTVenmoLineItem_Tests.swift */; }; 1FEB89E614CB6BF0B9858EE4 /* Pods_Tests_IntegrationTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 85BD589D380436A0C9D1DEC1 /* Pods_Tests_IntegrationTests.framework */; }; @@ -729,6 +730,7 @@ 035A59D91EA5DE97002960C8 /* BTLocalPaymentClient_UnitTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BTLocalPaymentClient_UnitTests.swift; sourceTree = ""; }; 039A8BD91F9E993500D607E7 /* BTAmericanExpressRewardsBalance_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTAmericanExpressRewardsBalance_Tests.swift; sourceTree = ""; }; 03F921C1200EBB200076CD80 /* BTThreeDSecurePostalAddress_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTThreeDSecurePostalAddress_Tests.swift; sourceTree = ""; }; + 04B001112D0D02CB00C0060D /* BTButtonType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTButtonType.swift; sourceTree = ""; }; 09357DCA2A2FBEC10096D449 /* BTVenmoLineItem_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTVenmoLineItem_Tests.swift; sourceTree = ""; }; 096C6B2529CCDCEB00912863 /* BTVenmoLineItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTVenmoLineItem.swift; sourceTree = ""; }; 162174E1192D9220008DC35D /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -1494,6 +1496,7 @@ 804698292B27C4D70090878E /* BraintreeShopperInsights */ = { isa = PBXGroup; children = ( + 04B001112D0D02CB00C0060D /* BTButtonType.swift */, 62EA90482B63071800DD79BC /* BTEligiblePaymentMethods.swift */, 800ED7822B4F5B66007D8A30 /* BTEligiblePaymentsRequest.swift */, 8037BFAF2B2CCC130017072C /* BTShopperInsightsAnalytics.swift */, @@ -3365,6 +3368,7 @@ buildActionMask = 2147483647; files = ( 804698382B27C53B0090878E /* BTShopperInsightsRequest.swift in Sources */, + 04B001122D0D02CF00C0060D /* BTButtonType.swift in Sources */, 624B27F72B6AE0C2000AC08A /* BTShopperInsightsError.swift in Sources */, 804698372B27C5390090878E /* BTShopperInsightsClient.swift in Sources */, 800ED7832B4F5B66007D8A30 /* BTEligiblePaymentsRequest.swift in Sources */, diff --git a/CHANGELOG.md b/CHANGELOG.md index a0b46587c..9cd5e4489 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * BraintreeShopperInsights (BETA) * Add `shopperSessionID` to `BTShopperInsightsClient` initializer * Add `isPayPalAppInstalled()` and/or `isVenmoAppInstalled()` + * Replace `sendPayPalSelectedEvent()` and `sendPayPalSelectedEvent()` with `sendSelectedEvent(for buttonType: BTButtonType)` ## 6.24.0 (2024-10-15) * BraintreePayPal diff --git a/Demo/Application/Features/ShopperInsightsViewController.swift b/Demo/Application/Features/ShopperInsightsViewController.swift index 820f914ae..12c5d1795 100644 --- a/Demo/Application/Features/ShopperInsightsViewController.swift +++ b/Demo/Application/Features/ShopperInsightsViewController.swift @@ -115,7 +115,7 @@ class ShopperInsightsViewController: PaymentButtonBaseViewController { let paymentMethods = ["Apple Pay", "Card", "PayPal"] shopperInsightsClient.sendPayPalPresentedEvent(paymentMethodsDisplayed: paymentMethods, experiment: sampleExperiment) progressBlock("Tapped PayPal Vault") - shopperInsightsClient.sendPayPalSelectedEvent() + shopperInsightsClient.sendSelectedEvent(for: .payPal) button.setTitle("Processing...", for: .disabled) button.isEnabled = false @@ -133,7 +133,7 @@ class ShopperInsightsViewController: PaymentButtonBaseViewController { @objc func venmoButtonTapped(_ button: UIButton) { shopperInsightsClient.sendVenmoPresentedEvent() progressBlock("Tapped Venmo") - shopperInsightsClient.sendVenmoSelectedEvent() + shopperInsightsClient.sendSelectedEvent(for: .venmo) button.setTitle("Processing...", for: .disabled) button.isEnabled = false diff --git a/Sources/BraintreeCore/Analytics/FPTIBatchData.swift b/Sources/BraintreeCore/Analytics/FPTIBatchData.swift index f986717b6..6b86d65dd 100644 --- a/Sources/BraintreeCore/Analytics/FPTIBatchData.swift +++ b/Sources/BraintreeCore/Analytics/FPTIBatchData.swift @@ -30,6 +30,8 @@ struct FPTIBatchData: Codable { struct Event: Codable { let appSwitchURL: String? + /// The button type to be displayed or presented + let buttonType: String? /// UTC millisecond timestamp when a networking task started establishing a TCP connection. See [Apple's docs](https://developer.apple.com/documentation/foundation/urlsessiontasktransactionmetrics#3162615). /// `nil` if a persistent connection is used. let connectionStartTime: Int? diff --git a/Sources/BraintreeCore/BTAPIClient.swift b/Sources/BraintreeCore/BTAPIClient.swift index 1d3b04f4d..e05e752b3 100644 --- a/Sources/BraintreeCore/BTAPIClient.swift +++ b/Sources/BraintreeCore/BTAPIClient.swift @@ -303,6 +303,7 @@ import Foundation @_documentation(visibility: private) public func sendAnalyticsEvent( _ eventName: String, + buttonType: String? = nil, correlationID: String? = nil, errorDescription: String? = nil, merchantExperiment: String? = nil, @@ -316,6 +317,7 @@ import Foundation analyticsService.sendAnalyticsEvent( FPTIBatchData.Event( appSwitchURL: appSwitchURL, + buttonType: buttonType, correlationID: correlationID, errorDescription: errorDescription, eventName: eventName, diff --git a/Sources/BraintreeShopperInsights/BTButtonType.swift b/Sources/BraintreeShopperInsights/BTButtonType.swift new file mode 100644 index 000000000..4776f8737 --- /dev/null +++ b/Sources/BraintreeShopperInsights/BTButtonType.swift @@ -0,0 +1,10 @@ +import Foundation + +/// The button type to be displayed or presented +/// Warning: This module is in beta. It's public API may change or be removed in future releases. + +public enum BTButtonType: String { + case payPal = "Paypal" + case venmo = "Venmo" + case other = "Other" +} diff --git a/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift b/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift index f2b81849e..89ae56c02 100644 --- a/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift +++ b/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift @@ -105,13 +105,7 @@ public class BTShopperInsightsClient { paymentMethodsDisplayed: paymentMethodsDisplayedString ) } - - /// 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) - } - + /// Call this method when the Venmo button has been successfully displayed to the buyer. /// This method sends analytics to help improve the Shopper Insights feature experience. /// - Parameters: @@ -125,11 +119,11 @@ public class BTShopperInsightsClient { paymentMethodsDisplayed: paymentMethodsDisplayedString ) } - - /// 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) + + /// 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. + public func sendSelectedEvent(for buttonType: BTButtonType) { + apiClient.sendAnalyticsEvent(buttonType.rawValue) } /// Indicates whether the PayPal App is installed. From 8ea62ea10903b2fe96ac8daaf332c2bd2bf7b137 Mon Sep 17 00:00:00 2001 From: stechiu Date: Fri, 13 Dec 2024 16:39:34 -0800 Subject: [PATCH 2/7] Updated unit tests --- Sources/BraintreeCore/Analytics/FPTIBatchData.swift | 3 +++ .../BTShopperInsightsClient_Tests.swift | 8 ++++---- UnitTests/BraintreeTestShared/MockAPIClient.swift | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Sources/BraintreeCore/Analytics/FPTIBatchData.swift b/Sources/BraintreeCore/Analytics/FPTIBatchData.swift index 6b86d65dd..d3c43984c 100644 --- a/Sources/BraintreeCore/Analytics/FPTIBatchData.swift +++ b/Sources/BraintreeCore/Analytics/FPTIBatchData.swift @@ -65,6 +65,7 @@ struct FPTIBatchData: Codable { init( appSwitchURL: URL? = nil, + buttonType: String? = nil, connectionStartTime: Int? = nil, correlationID: String? = nil, endpoint: String? = nil, @@ -81,6 +82,7 @@ struct FPTIBatchData: Codable { startTime: Int? = nil ) { self.appSwitchURL = appSwitchURL?.absoluteString + self.buttonType = buttonType self.connectionStartTime = connectionStartTime self.correlationID = correlationID self.endpoint = endpoint @@ -99,6 +101,7 @@ struct FPTIBatchData: Codable { enum CodingKeys: String, CodingKey { case appSwitchURL = "url" + case buttonType = "button_type" case connectionStartTime = "connect_start_time" case correlationID = "correlation_id" case errorDescription = "error_desc" diff --git a/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift b/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift index 47806902f..14e2fcbd2 100644 --- a/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift +++ b/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift @@ -214,8 +214,8 @@ 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, "PayPal") } func testSendVenmoPresentedEvent_sendsAnalytic() { @@ -224,8 +224,8 @@ 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, "Venmo") } func testShopperInsightsClient_withSessionID_setSessionIDInMetadata() { diff --git a/UnitTests/BraintreeTestShared/MockAPIClient.swift b/UnitTests/BraintreeTestShared/MockAPIClient.swift index 77ff070ec..3699bc552 100644 --- a/UnitTests/BraintreeTestShared/MockAPIClient.swift +++ b/UnitTests/BraintreeTestShared/MockAPIClient.swift @@ -93,6 +93,7 @@ public class MockAPIClient: BTAPIClient { public override func sendAnalyticsEvent( _ name: String, + buttonType: String? = nil, correlationID: String? = nil, errorDescription: String? = nil, merchantExperiment experiment: String? = nil, From 7f41732ff45d90e567746f709a1fa812583ff348 Mon Sep 17 00:00:00 2001 From: stechiu Date: Mon, 16 Dec 2024 09:55:13 -0800 Subject: [PATCH 3/7] Addressed PR comments --- CHANGELOG.md | 2 +- Sources/BraintreeShopperInsights/BTButtonType.swift | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cd5e4489..f8fe2ec24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ * BraintreeShopperInsights (BETA) * Add `shopperSessionID` to `BTShopperInsightsClient` initializer * Add `isPayPalAppInstalled()` and/or `isVenmoAppInstalled()` - * Replace `sendPayPalSelectedEvent()` and `sendPayPalSelectedEvent()` with `sendSelectedEvent(for buttonType: BTButtonType)` + * Replace `sendPayPalSelectedEvent()` and `sendPayPalSelectedEvent()` with `sendSelectedEvent(for:)` ## 6.24.0 (2024-10-15) * BraintreePayPal diff --git a/Sources/BraintreeShopperInsights/BTButtonType.swift b/Sources/BraintreeShopperInsights/BTButtonType.swift index 4776f8737..80216a1c5 100644 --- a/Sources/BraintreeShopperInsights/BTButtonType.swift +++ b/Sources/BraintreeShopperInsights/BTButtonType.swift @@ -1,10 +1,9 @@ import Foundation /// The button type to be displayed or presented -/// Warning: This module is in beta. It's public API may change or be removed in future releases. - +/// - Warning: This module is in beta. It's public API may change or be removed in future releases. public enum BTButtonType: String { - case payPal = "Paypal" + case payPal = "PayPal" case venmo = "Venmo" case other = "Other" } From 9e1a125e1b75af38f2877cb04c941c9f7de3401c Mon Sep 17 00:00:00 2001 From: stechiu Date: Mon, 16 Dec 2024 16:10:01 -0800 Subject: [PATCH 4/7] Fixed unit tests --- .../BTShopperInsightsAnalytics.swift | 6 +++--- .../BTShopperInsightsClient.swift | 14 +------------- .../BTShopperInsightsAnalytics_Tests.swift | 3 +-- .../BTShopperInsightsClient_Tests.swift | 13 ++++--------- 4 files changed, 9 insertions(+), 27 deletions(-) diff --git a/Sources/BraintreeShopperInsights/BTShopperInsightsAnalytics.swift b/Sources/BraintreeShopperInsights/BTShopperInsightsAnalytics.swift index fefbcd5fa..80e513525 100644 --- a/Sources/BraintreeShopperInsights/BTShopperInsightsAnalytics.swift +++ b/Sources/BraintreeShopperInsights/BTShopperInsightsAnalytics.swift @@ -5,10 +5,10 @@ enum BTShopperInsightsAnalytics { // MARK: - Merchant Triggered Events static let payPalPresented = "shopper-insights:paypal-presented" - static let payPalSelected = "shopper-insights:paypal-selected" static let venmoPresented = "shopper-insights:venmo-presented" - static let venmoSelected = "shopper-insights:venmo-selected" - + + 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 ef3a33563..df256b7be 100644 --- a/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift +++ b/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift @@ -104,12 +104,6 @@ public class BTShopperInsightsClient { ) } - /// 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 successfully displayed to the buyer. /// This method sends analytics to help improve the Shopper Insights feature experience. /// - Parameters: @@ -128,13 +122,7 @@ public class BTShopperInsightsClient { /// 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. public func sendSelectedEvent(for buttonType: BTButtonType) { - apiClient.sendAnalyticsEvent(buttonType.rawValue) - } - - /// 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) + apiClient.sendAnalyticsEvent(BTShopperInsightsAnalytics.buttonSelected, shopperSessionID: shopperSessionID) } /// Indicates whether the PayPal App is installed. diff --git a/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsAnalytics_Tests.swift b/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsAnalytics_Tests.swift index 991a240b4..cdd4c01ee 100644 --- a/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsAnalytics_Tests.swift +++ b/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsAnalytics_Tests.swift @@ -5,9 +5,8 @@ final class BTShopperInsightsAnalytics_Tests: XCTestCase { func test_recommendedPaymentAnalyticEvents_sendExpectedEventNames() { XCTAssertEqual(BTShopperInsightsAnalytics.payPalPresented, "shopper-insights:paypal-presented") - XCTAssertEqual(BTShopperInsightsAnalytics.payPalSelected, "shopper-insights:paypal-selected") + XCTAssertEqual(BTShopperInsightsAnalytics.buttonSelected, "shopper-insights:button-selected") XCTAssertEqual(BTShopperInsightsAnalytics.venmoPresented, "shopper-insights:venmo-presented") - XCTAssertEqual(BTShopperInsightsAnalytics.venmoSelected, "shopper-insights:venmo-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 4348159de..96dbb22a2 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 { @@ -222,10 +222,7 @@ class BTShopperInsightsClient_Tests: XCTestCase { func testSendPayPalSelectedEvent_sendsAnalytic() { sut.sendSelectedEvent(for: .payPal) - XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "PayPal") - - sut.sendPayPalSelectedEvent() - XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:paypal-selected") + XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:button-selected") XCTAssertEqual(mockAPIClient.postedShopperSessionID, "fake-shopper-session-id") } @@ -237,15 +234,13 @@ class BTShopperInsightsClient_Tests: XCTestCase { func testSendVenmoSelectedEvent_sendsAnalytic() { sut.sendSelectedEvent(for: .venmo) - XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "Venmo") + XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:button-selected") } func testShopperInsightsClient_withSessionID_setSessionIDInMetadata() { sut = BTShopperInsightsClient(apiClient: mockAPIClient, shopperSessionID: "123456") XCTAssertEqual(mockAPIClient.metadata.sessionID, "123456") - - sut.sendVenmoSelectedEvent() - XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:venmo-selected") + XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:button-selected") XCTAssertEqual(mockAPIClient.postedShopperSessionID, "fake-shopper-session-id") } From 4fa49cff59877a83ba78efa00900436e0331fd6a Mon Sep 17 00:00:00 2001 From: stechiu Date: Tue, 17 Dec 2024 12:17:20 -0800 Subject: [PATCH 5/7] Fixed failing unit test --- .../BTShopperInsightsClient.swift | 6 +++++- .../BTPayPalClient_Tests.swift | 18 ------------------ .../BTShopperInsightsClient_Tests.swift | 4 +++- .../BraintreeTestShared/MockAPIClient.swift | 4 +++- 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift b/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift index df256b7be..72d760fd6 100644 --- a/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift +++ b/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift @@ -122,7 +122,11 @@ public class BTShopperInsightsClient { /// 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. public func sendSelectedEvent(for buttonType: BTButtonType) { - apiClient.sendAnalyticsEvent(BTShopperInsightsAnalytics.buttonSelected, shopperSessionID: shopperSessionID) + apiClient.sendAnalyticsEvent( + BTShopperInsightsAnalytics.buttonSelected, + buttonType: buttonType.rawValue, + shopperSessionID: shopperSessionID + ) } /// Indicates whether the PayPal App is installed. diff --git a/UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift b/UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift index 7d112d2d3..14527dbb6 100644 --- a/UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift +++ b/UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift @@ -982,24 +982,6 @@ class BTPayPalClient_Tests: XCTestCase { XCTAssertNil(lastPostParameters["merchant_app_return_url"] as? String) } - func testInvokedOpenURLSuccessfully_whenSuccess_sendsAppSwitchSucceededWithAppSwitchURL() { - let eventName = BTPayPalAnalytics.appSwitchSucceeded - let fakeURL = URL(string: "some-url")! - payPalClient.invokedOpenURLSuccessfully(true, url: fakeURL) { _, _ in } - - XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.last!, eventName) - XCTAssertEqual(mockAPIClient.postedAppSwitchURL[eventName], fakeURL.absoluteString) - } - - func testInvokedOpenURLSuccessfully_whenFailure_sendsAppSwitchFailedWithAppSwitchURL() { - let eventName = BTPayPalAnalytics.appSwitchFailed - let fakeURL = URL(string: "some-url")! - payPalClient.invokedOpenURLSuccessfully(false, url: fakeURL) { _, _ in } - - XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first!, eventName) - XCTAssertEqual(mockAPIClient.postedAppSwitchURL[eventName], fakeURL.absoluteString) - } - // MARK: - Analytics func testAPIClientMetadata_hasIntegrationSetToCustom() { diff --git a/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift b/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift index 96dbb22a2..413598691 100644 --- a/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift +++ b/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift @@ -224,8 +224,9 @@ class BTShopperInsightsClient_Tests: XCTestCase { 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() { sut.sendVenmoPresentedEvent() XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:venmo-presented") @@ -235,6 +236,7 @@ class BTShopperInsightsClient_Tests: XCTestCase { func testSendVenmoSelectedEvent_sendsAnalytic() { sut.sendSelectedEvent(for: .venmo) XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:button-selected") + XCTAssertEqual(mockAPIClient.postedButtonType, "Venmo") } func testShopperInsightsClient_withSessionID_setSessionIDInMetadata() { diff --git a/UnitTests/BraintreeTestShared/MockAPIClient.swift b/UnitTests/BraintreeTestShared/MockAPIClient.swift index b88dd1e46..80665cebf 100644 --- a/UnitTests/BraintreeTestShared/MockAPIClient.swift +++ b/UnitTests/BraintreeTestShared/MockAPIClient.swift @@ -11,7 +11,8 @@ public class MockAPIClient: BTAPIClient { public var lastGETParameters = [:] as [String: Any]? public var lastGETAPIClientHTTPType: BTAPIClientHTTPService? - public var postedAnalyticsEvents : [String] = [] + public var postedButtonType: String? = nil + public var postedAnalyticsEvents: [String] = [] public var postedPayPalContextID: String? = nil public var postedLinkType: LinkType? = nil public var postedIsVaultRequest = false @@ -106,6 +107,7 @@ public class MockAPIClient: BTAPIClient { appSwitchURL: URL? = nil, shopperSessionID: String? = nil ) { + postedButtonType = buttonType postedPayPalContextID = payPalContextID postedLinkType = linkType postedIsVaultRequest = isVaultRequest ?? false From ae466970708fc555dbf2130c283d55667f0daa7f Mon Sep 17 00:00:00 2001 From: stechiu Date: Tue, 17 Dec 2024 12:43:04 -0800 Subject: [PATCH 6/7] Removed unnecessary unit tests --- .../BTShopperInsightsClient_Tests.swift | 6 ------ 1 file changed, 6 deletions(-) diff --git a/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift b/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift index 413598691..bdaaa11d1 100644 --- a/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift +++ b/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift @@ -237,12 +237,6 @@ class BTShopperInsightsClient_Tests: XCTestCase { sut.sendSelectedEvent(for: .venmo) XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:button-selected") XCTAssertEqual(mockAPIClient.postedButtonType, "Venmo") - } - - func testShopperInsightsClient_withSessionID_setSessionIDInMetadata() { - sut = BTShopperInsightsClient(apiClient: mockAPIClient, shopperSessionID: "123456") - XCTAssertEqual(mockAPIClient.metadata.sessionID, "123456") - XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:button-selected") XCTAssertEqual(mockAPIClient.postedShopperSessionID, "fake-shopper-session-id") } From 871d01fda7431488937e6e95d63a1b46e2def481 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Fri, 20 Dec 2024 14:24:16 -0600 Subject: [PATCH 7/7] add parameters to docstring for presented event --- Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift b/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift index d7e446948..23564fe1e 100644 --- a/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift +++ b/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift @@ -109,6 +109,7 @@ public class BTShopperInsightsClient { /// 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,