Skip to content

Commit

Permalink
ShopperInsights - Merchant Analytics (#1162)
Browse files Browse the repository at this point in the history
  • Loading branch information
scannillo authored Dec 19, 2023
1 parent 1eec880 commit e0379d3
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Braintree.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
57D94372296CCA2F0079EAB1 /* String+NonceValidation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57D94371296CCA2F0079EAB1 /* String+NonceValidation.swift */; };
800E78C429E0DD5300D1B0FC /* FPTIBatchData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 800E78C329E0DD5300D1B0FC /* FPTIBatchData.swift */; };
800FC544257FDC5100DEE132 /* BTApplePayCardNonce_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 800FC543257FDC5100DEE132 /* BTApplePayCardNonce_Tests.swift */; };
8037BFB02B2CCC130017072C /* BTShopperInsightsAnalytics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8037BFAF2B2CCC130017072C /* BTShopperInsightsAnalytics.swift */; };
804698372B27C5390090878E /* BTShopperInsightsClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8064F38E2B1E492F0059C4CB /* BTShopperInsightsClient.swift */; };
804698382B27C53B0090878E /* BTShopperInsightsRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8064F3962B1E63800059C4CB /* BTShopperInsightsRequest.swift */; };
804698392B27C53E0090878E /* BTShopperInsightsResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8064F3902B1E49E10059C4CB /* BTShopperInsightsResult.swift */; };
Expand Down Expand Up @@ -730,6 +731,7 @@
800E23DC22206A8300C5D22E /* BTThreeDSecureAuthenticateJWT_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTThreeDSecureAuthenticateJWT_Tests.swift; sourceTree = "<group>"; };
800E78C329E0DD5300D1B0FC /* FPTIBatchData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FPTIBatchData.swift; sourceTree = "<group>"; };
800FC543257FDC5100DEE132 /* BTApplePayCardNonce_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTApplePayCardNonce_Tests.swift; sourceTree = "<group>"; };
8037BFAF2B2CCC130017072C /* BTShopperInsightsAnalytics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTShopperInsightsAnalytics.swift; sourceTree = "<group>"; };
804698302B27C5340090878E /* BraintreeShopperInsights.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = BraintreeShopperInsights.framework; sourceTree = BUILT_PRODUCTS_DIR; };
8046983E2B27C5530090878E /* BraintreeShopperInsightsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = BraintreeShopperInsightsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
804698482B27C71C0090878E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1296,6 +1298,7 @@
804698292B27C4D70090878E /* BraintreeShopperInsights */ = {
isa = PBXGroup;
children = (
8037BFAF2B2CCC130017072C /* BTShopperInsightsAnalytics.swift */,
8064F38E2B1E492F0059C4CB /* BTShopperInsightsClient.swift */,
8064F3962B1E63800059C4CB /* BTShopperInsightsRequest.swift */,
8064F3902B1E49E10059C4CB /* BTShopperInsightsResult.swift */,
Expand Down Expand Up @@ -2928,6 +2931,7 @@
files = (
804698382B27C53B0090878E /* BTShopperInsightsRequest.swift in Sources */,
804698372B27C5390090878E /* BTShopperInsightsClient.swift in Sources */,
8037BFB02B2CCC130017072C /* BTShopperInsightsAnalytics.swift in Sources */,
804698392B27C53E0090878E /* BTShopperInsightsResult.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
10 changes: 10 additions & 0 deletions Braintree.xcodeproj/xcshareddata/xcschemes/UnitTests.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@
ReferencedContainer = "container:Braintree.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8046983D2B27C5530090878E"
BuildableName = "BraintreeShopperInsightsTests.xctest"
BlueprintName = "BraintreeShopperInsightsTests"
ReferencedContainer = "container:Braintree.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
11 changes: 11 additions & 0 deletions Sources/BraintreeShopperInsights/BTShopperInsightsAnalytics.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Foundation

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"
}
24 changes: 24 additions & 0 deletions Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,28 @@ public class BTShopperInsightsClient {
// TODO: - Make API call to PaymentReadyAPI. DTBTSDK-3176
return BTShopperInsightsResult()
}

/// Call this method when the PayPal button has been successfully displayed to the buyer.
/// This method sends analytics to help improve the Shopper Insights feature experience.
public func sendPayPalPresentedEvent() {
apiClient.sendAnalyticsEvent(BTShopperInsightsAnalytics.paypalPresented)
}

/// 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
public func sendVenmoPresentedEvent() {
apiClient.sendAnalyticsEvent(BTShopperInsightsAnalytics.venmoPresented)
}

/// 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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,26 @@ class BTShopperInsightsClient_Tests: XCTestCase {
XCTAssertNotNil(result!.isPayPalRecommended)
XCTAssertNotNil(result!.isVenmoRecommended)
}

// MARK: - Analytics

func testSendPayPalPresentedEvent_sendsAnalytic() {
sut.sendPayPalPresentedEvent()
XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:paypal-presented")
}

func testSendPayPalSelectedEvent_sendsAnalytic() {
sut.sendPayPalSelectedEvent()
XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:paypal-selected")
}

func testSendVenmoPresentedEvent_sendsAnalytic() {
sut.sendVenmoPresentedEvent()
XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:venmo-presented")
}

func testSendVenmoSelectedEvent_sendsAnalytic() {
sut.sendVenmoSelectedEvent()
XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:venmo-selected")
}
}

0 comments on commit e0379d3

Please sign in to comment.