Skip to content

Commit e13bea3

Browse files
committed
Track Cash on Delivery disabled CTA tapped event
1 parent cf833a4 commit e13bea3

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

WooCommerce/Classes/Analytics/WooAnalyticsEvent.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,20 @@ extension WooAnalyticsEvent {
11721172
])
11731173
}
11741174

1175+
/// Tracked when a In-Person Payments onboarding step's CTA is tapped by the user.
1176+
///
1177+
/// - Parameters:
1178+
/// - reason: the reason why the onboarding step was shown (effectively the name of the step.)
1179+
/// - countryCode: the country code of the store.
1180+
///
1181+
static func cardPresentOnboardingCtaTapped(reason: String, countryCode: String) -> WooAnalyticsEvent {
1182+
WooAnalyticsEvent(statName: .cardPresentOnboardingCtaTapped,
1183+
properties: [
1184+
Keys.countryCode: countryCode,
1185+
Keys.reason: reason
1186+
])
1187+
}
1188+
11751189
/// Tracked when the user taps on the "See Receipt" button to view a receipt.
11761190
/// - Parameter countryCode: the country code of the store.
11771191
///

WooCommerce/Classes/Analytics/WooAnalyticsStat.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ public enum WooAnalyticsStat: String {
185185
case cardPresentOnboardingLearnMoreTapped = "card_present_onboarding_learn_more_tapped"
186186
case cardPresentOnboardingNotCompleted = "card_present_onboarding_not_completed"
187187
case cardPresentOnboardingStepSkipped = "card_present_onboarding_step_skipped"
188+
case cardPresentOnboardingCtaTapped = "card_present_onboarding_cta_tapped"
188189

189190
// MARK: Payment Gateways selection
190191
case cardPresentPaymentGatewaySelected = "card_present_payment_gateway_selected"

WooCommerce/Classes/ViewRelated/Dashboard/Settings/In-Person Payments/Onboarding Errors/InPersonPaymentsCashOnDeliveryPaymentGatewayNotSetUpViewModel.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ final class InPersonPaymentsCashOnDeliveryPaymentGatewayNotSetUpViewModel: Obser
6565
}
6666

6767
func enableTapped() {
68+
trackEnableTapped()
69+
6870
guard let siteID = siteID else {
6971
return completion()
7072
}
@@ -108,18 +110,24 @@ final class InPersonPaymentsCashOnDeliveryPaymentGatewayNotSetUpViewModel: Obser
108110

109111
// MARK: - Analytics
110112
private extension InPersonPaymentsCashOnDeliveryPaymentGatewayNotSetUpViewModel {
111-
private typealias Event = WooAnalyticsEvent.InPersonPayments
113+
typealias Event = WooAnalyticsEvent.InPersonPayments
112114

113-
private var reason: String {
115+
var reason: String {
114116
CardPresentPaymentOnboardingState.codPaymentGatewayNotSetUp.reasonForAnalytics ?? ""
115117
}
116118

117-
private func trackSkipTapped() {
119+
func trackSkipTapped() {
118120
let event = Event.cardPresentOnboardingStepSkipped(reason: reason,
119121
remindLater: false,
120122
countryCode: cardPresentPaymentsConfiguration.countryCode)
121123
analytics.track(event: event)
122124
}
125+
126+
func trackEnableTapped() {
127+
let event = Event.cardPresentOnboardingCtaTapped(reason: reason,
128+
countryCode: cardPresentPaymentsConfiguration.countryCode)
129+
analytics.track(event: event)
130+
}
123131
}
124132

125133
private enum Localization {

WooCommerce/WooCommerceTests/ViewRelated/Dashboard/Settings/In-Person Payments/Onboarding Errors/InPersonPaymentsCashOnDeliveryPaymentGatewayNotSetUpViewModelTests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,26 @@ final class InPersonPaymentsCashOnDeliveryPaymentGatewayNotSetUpViewModelTests:
134134
assertEqual(false, eventProperties[AnalyticProperties.remindLaterKey] as? Bool)
135135
assertEqual("US", eventProperties[AnalyticProperties.countryCodeKey] as? String)
136136
}
137+
138+
func test_enable_tapped_logs_cta_tapped_event() throws {
139+
// Given
140+
assertEmpty(analyticsProvider.receivedEvents)
141+
142+
// When
143+
sut.enableTapped()
144+
145+
// Then
146+
assertNotEmpty(analyticsProvider.receivedEvents)
147+
let indexOfEvent = try XCTUnwrap(analyticsProvider.receivedEvents.firstIndex(where: { $0 == AnalyticEvents.ctaTappedEvent }))
148+
let eventProperties = try XCTUnwrap(analyticsProvider.receivedProperties[indexOfEvent])
149+
assertEqual(AnalyticProperties.cashOnDeliveryDisabledReason, eventProperties[AnalyticProperties.reasonKey] as? String)
150+
assertEqual("US", eventProperties[AnalyticProperties.countryCodeKey] as? String)
151+
}
137152
}
138153

139154
private enum AnalyticEvents {
140155
static let skippedEvent = "card_present_onboarding_step_skipped"
156+
static let ctaTappedEvent = "card_present_onboarding_cta_tapped"
141157
}
142158

143159
private enum AnalyticProperties {

0 commit comments

Comments
 (0)