Skip to content

Commit 6b49a8f

Browse files
adborbasclaude
andcommitted
Simplify analytics by removing factory methods for error and step events
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b15aa70 commit 6b49a8f

File tree

5 files changed

+10
-130
lines changed

5 files changed

+10
-130
lines changed
Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import Foundation
2-
31
extension WooAnalyticsEvent {
42
enum PushNotificationsSetup {
53
private enum Keys: String {
64
case buttonLabel = "button_label"
7-
case step
8-
case errorType = "error_type"
95
}
106

117
enum IntroductionButtonLabel: String {
@@ -14,18 +10,6 @@ extension WooAnalyticsEvent {
1410
case updatePlugin = "update_plugin"
1511
}
1612

17-
enum IntroductionErrorType: String {
18-
case noPermission = "no_permission"
19-
case noMissingRequirements = "no_missing_requirements"
20-
case generic
21-
}
22-
23-
enum FlowStep: String {
24-
case connectWPCom = "connect_wpcom"
25-
case pluginCompatibility = "plugin_compatibility"
26-
case enablePushNotifications = "enable_push_notifications"
27-
}
28-
2913
enum FlowButtonLabel: String {
3014
case done
3115
case goToMyStore = "go_to_my_store"
@@ -38,26 +22,10 @@ extension WooAnalyticsEvent {
3822
properties: [Keys.buttonLabel.rawValue: buttonLabel.rawValue])
3923
}
4024

41-
static func introductionError(errorType: IntroductionErrorType, error: Error? = nil) -> WooAnalyticsEvent {
42-
WooAnalyticsEvent(statName: .pushNotificationsSetupIntroductionError,
43-
properties: [Keys.errorType.rawValue: errorType.rawValue],
44-
error: error)
45-
}
46-
47-
static func flowSuccess(step: FlowStep) -> WooAnalyticsEvent {
48-
WooAnalyticsEvent(statName: .pushNotificationsSetupFlowSuccess,
49-
properties: [Keys.step.rawValue: step.rawValue])
50-
}
51-
5225
static func flowButtonTap(buttonLabel: FlowButtonLabel) -> WooAnalyticsEvent {
5326
WooAnalyticsEvent(statName: .pushNotificationsSetupFlowButtonTap,
5427
properties: [Keys.buttonLabel.rawValue: buttonLabel.rawValue])
5528
}
5629

57-
static func flowError(step: FlowStep, error: Error? = nil) -> WooAnalyticsEvent {
58-
WooAnalyticsEvent(statName: .pushNotificationsSetupFlowError,
59-
properties: [Keys.step.rawValue: step.rawValue],
60-
error: error)
61-
}
6230
}
6331
}

WooCommerce/Classes/Authentication/WPComLogin/WPComConnectionSetup/WPComConnectionSetupHandlerProtocol.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ enum SetupStep: Int, CaseIterable {
66
case connect = 1
77
case enablePush = 2
88

9-
var analyticsFlowStep: WooAnalyticsEvent.PushNotificationsSetup.FlowStep {
9+
var analyticsFlowStep: String {
1010
switch self {
11-
case .checkPlugin: return .pluginCompatibility
12-
case .connect: return .connectWPCom
13-
case .enablePush: return .enablePushNotifications
11+
case .checkPlugin: return "plugin_compatibility"
12+
case .connect: return "connect_wpcom"
13+
case .enablePush: return "enable_push_notifications"
1414
}
1515
}
1616
}

WooCommerce/Classes/Authentication/WPComLogin/WPComConnectionSetup/WPComConnectionSetupViewModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ extension WPComConnectionSetupViewModel: WPComConnectionSetupHandlerDelegate {
189189

190190
switch status {
191191
case .success:
192-
analytics.track(event: .PushNotificationsSetup.flowSuccess(step: step.analyticsFlowStep))
192+
analytics.track(.pushNotificationsSetupFlowSuccess, withProperties: ["step": step.analyticsFlowStep])
193193
case .failure(let error):
194-
analytics.track(event: .PushNotificationsSetup.flowError(step: step.analyticsFlowStep, error: error))
194+
analytics.track(.pushNotificationsSetupFlowError, properties: ["step": step.analyticsFlowStep], error: error)
195195
let checkPluginError: CheckPluginError? = step == .checkPlugin ? checkPluginError(from: error) : nil
196196
setupState = .failed(step: step, checkPluginError: checkPluginError)
197197
case .notStarted, .running:

WooCommerce/Classes/ViewRelated/Dashboard/WPComPushNotificationsBenefits/WPComPushNotificationsBenefitsViewModel.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ final class WPComPushNotificationsBenefitsViewModel {
9191
DDLogError("⛔️ Failed to fetch Jetpack connection data: \(error)")
9292
if case NetworkError.unacceptableStatusCode(403, _) = error {
9393
self.error = .noPermission
94-
analytics.track(event: .PushNotificationsSetup.introductionError(errorType: .noPermission))
94+
analytics.track(.pushNotificationsSetupIntroductionError, withProperties: ["error_type": "no_permission"])
9595
} else {
9696
self.error = .generic(underlyingError: error)
97-
analytics.track(event: .PushNotificationsSetup.introductionError(errorType: .generic, error: error))
97+
analytics.track(.pushNotificationsSetupIntroductionError, properties: ["error_type": "generic"], error: error)
9898
}
9999
}
100100
isCheckingPlugin = false
@@ -134,12 +134,12 @@ private extension WPComPushNotificationsBenefitsViewModel {
134134
variant = .pluginUpdate(currentVersion: currentVersion)
135135
} else {
136136
error = .noMissingRequirements
137-
analytics.track(event: .PushNotificationsSetup.introductionError(errorType: .noMissingRequirements))
137+
analytics.track(.pushNotificationsSetupIntroductionError, withProperties: ["error_type": "no_missing_requirements"])
138138
}
139139
} catch {
140140
DDLogError("⛔️ Plugin version check failed: \(error)")
141141
self.error = .generic(underlyingError: error)
142-
analytics.track(event: .PushNotificationsSetup.introductionError(errorType: .generic, error: error))
142+
analytics.track(.pushNotificationsSetupIntroductionError, properties: ["error_type": "generic"], error: error)
143143
}
144144
}
145145
}

WooCommerce/WooCommerceTests/Analytics/WooAnalyticsEvent+PushNotificationsSetupTests.swift

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,6 @@ struct WooAnalyticsEvent_PushNotificationsSetupTests {
2424
}
2525
}
2626

27-
// MARK: - flowSuccess
28-
29-
@Test func test_flowSuccess_when_given_each_step_then_produces_correct_event() {
30-
// Given
31-
let cases: [(WooAnalyticsEvent.PushNotificationsSetup.FlowStep, String)] = [
32-
(.connectWPCom, "connect_wpcom"),
33-
(.pluginCompatibility, "plugin_compatibility"),
34-
(.enablePushNotifications, "enable_push_notifications")
35-
]
36-
37-
for (step, expected) in cases {
38-
// When
39-
let event = WooAnalyticsEvent.PushNotificationsSetup.flowSuccess(step: step)
40-
41-
// Then
42-
#expect(event.statName == .pushNotificationsSetupFlowSuccess)
43-
#expect(event.properties["step"] as? String == expected)
44-
}
45-
}
46-
4727
// MARK: - flowButtonTap
4828

4929
@Test func test_flowButtonTap_when_given_each_label_then_produces_correct_event() {
@@ -64,72 +44,4 @@ struct WooAnalyticsEvent_PushNotificationsSetupTests {
6444
#expect(event.properties["button_label"] as? String == expected)
6545
}
6646
}
67-
68-
// MARK: - introductionError
69-
70-
@Test func test_introductionError_when_given_each_error_type_then_produces_correct_event() {
71-
// Given
72-
let cases: [(WooAnalyticsEvent.PushNotificationsSetup.IntroductionErrorType, String)] = [
73-
(.noPermission, "no_permission"),
74-
(.noMissingRequirements, "no_missing_requirements"),
75-
(.generic, "generic")
76-
]
77-
78-
for (errorType, expected) in cases {
79-
// When
80-
let event = WooAnalyticsEvent.PushNotificationsSetup.introductionError(errorType: errorType)
81-
82-
// Then
83-
#expect(event.statName == .pushNotificationsSetupIntroductionError)
84-
#expect(event.properties["error_type"] as? String == expected)
85-
#expect(event.error == nil)
86-
}
87-
}
88-
89-
@Test func test_introductionError_when_error_provided_then_passes_error_in_event() {
90-
// Given
91-
let underlyingError = NSError(domain: "test.domain", code: 99)
92-
93-
// When
94-
let event = WooAnalyticsEvent.PushNotificationsSetup.introductionError(errorType: .generic, error: underlyingError)
95-
96-
// Then
97-
#expect(event.statName == .pushNotificationsSetupIntroductionError)
98-
#expect(event.properties["error_type"] as? String == "generic")
99-
#expect(event.error as? NSError == underlyingError)
100-
}
101-
102-
// MARK: - flowError
103-
104-
@Test func test_flowError_when_no_error_provided_then_produces_correct_event_with_nil_error() {
105-
// Given
106-
let cases: [(WooAnalyticsEvent.PushNotificationsSetup.FlowStep, String)] = [
107-
(.connectWPCom, "connect_wpcom"),
108-
(.pluginCompatibility, "plugin_compatibility"),
109-
(.enablePushNotifications, "enable_push_notifications")
110-
]
111-
112-
for (step, expected) in cases {
113-
// When
114-
let event = WooAnalyticsEvent.PushNotificationsSetup.flowError(step: step)
115-
116-
// Then
117-
#expect(event.statName == .pushNotificationsSetupFlowError)
118-
#expect(event.properties["step"] as? String == expected)
119-
#expect(event.error == nil)
120-
}
121-
}
122-
123-
@Test func test_flowError_when_error_provided_then_passes_error_in_event() {
124-
// Given
125-
let underlyingError = NSError(domain: "test.domain", code: 42)
126-
127-
// When
128-
let event = WooAnalyticsEvent.PushNotificationsSetup.flowError(step: .connectWPCom, error: underlyingError)
129-
130-
// Then
131-
#expect(event.statName == .pushNotificationsSetupFlowError)
132-
#expect(event.properties["step"] as? String == "connect_wpcom")
133-
#expect(event.error as? NSError == underlyingError)
134-
}
13547
}

0 commit comments

Comments
 (0)