Skip to content

Commit 64bb048

Browse files
Merge pull request #8218 from woocommerce/issue/8075-tracks
Login: Jetpack setup: Add tracks
2 parents 80661f9 + 07a9b7f commit 64bb048

File tree

7 files changed

+105
-5
lines changed

7 files changed

+105
-5
lines changed

WooCommerce/Classes/Analytics/WooAnalyticsStat.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ public enum WooAnalyticsStat: String {
114114

115115
case loginJetpackSetupAuthorizedUsingDifferentWPCOMAccount = "login_jetpack_setup_authorized_using_different_wpcom_account"
116116

117+
case loginJetpackSetupScreenTryAgainButtonTapped = "login_jetpack_setup_try_again_button_tapped"
118+
case loginJetpackSetupScreenGetSupportTapped = "login_jetpack_setup_get_support_button_tapped"
119+
117120
// MARK: No matched site alert
118121
//
119122
case loginJetpackNoMatchedSiteErrorViewed = "login_jetpack_no_matched_site_error_viewed"

WooCommerce/Classes/Authentication/Jetpack Setup/Native Jetpack Setup/LoginJetpackSetupView.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ final class LoginJetpackSetupHostingController: UIHostingController<LoginJetpack
2222
}
2323

2424
rootView.supportHandler = { [weak self] in
25-
self?.presentSupport()
25+
guard let self else { return }
26+
27+
self.analytics.track(.loginJetpackSetupScreenGetSupportTapped, withProperties: self.viewModel.currentSetupStep?.analyticsDescription)
28+
self.presentSupport()
2629
}
2730

2831
rootView.cancellationHandler = dismissView
@@ -49,7 +52,13 @@ final class LoginJetpackSetupHostingController: UIHostingController<LoginJetpack
4952

5053
@objc
5154
private func dismissView() {
52-
analytics.track(.loginJetpackSetupScreenDismissed)
55+
analytics.track(.loginJetpackSetupScreenDismissed,
56+
withProperties: viewModel.currentSetupStep?.analyticsDescription)
57+
dismiss(animated: true)
58+
}
59+
60+
@objc
61+
private func dismissWebView() {
5362
dismiss(animated: true)
5463
}
5564

@@ -73,7 +82,7 @@ final class LoginJetpackSetupHostingController: UIHostingController<LoginJetpack
7382
webView.navigationItem.leftBarButtonItem = UIBarButtonItem(title: Localization.cancel,
7483
style: .plain,
7584
target: self,
76-
action: #selector(self.dismissView))
85+
action: #selector(self.dismissWebView))
7786
let navigationController = UINavigationController(rootViewController: webView)
7887
self.present(navigationController, animated: true)
7988
}
@@ -203,7 +212,6 @@ struct LoginJetpackSetupView: View {
203212

204213
// Support button
205214
Button {
206-
// TODO: add tracks?
207215
supportHandler()
208216
} label: {
209217
Label {
@@ -240,7 +248,6 @@ struct LoginJetpackSetupView: View {
240248
// Error state buttons: Retry and Cancel
241249
VStack(spacing: Constants.contentVerticalSpacing) {
242250
Button {
243-
// TODO: add tracks
244251
viewModel.retryAllSteps()
245252
} label: {
246253
Text(viewModel.tryAgainButtonTitle)
@@ -267,6 +274,7 @@ struct LoginJetpackSetupView: View {
267274
.fullScreenCover(isPresented: $viewModel.jetpackConnectionInterrupted) {
268275
LoginJetpackSetupInterruptedView(siteURL: viewModel.siteURL, onSupport: supportHandler, onContinue: {
269276
viewModel.jetpackConnectionInterrupted = false
277+
viewModel.didTapContinueConnectionButton()
270278
// delay for the dismissal of the interrupted screen to complete.
271279
DispatchQueue.main.asyncAfter(deadline: .now() + Constants.interruptedConnectionActionHandlerDelayTime) {
272280
webViewPresentationHandler()

WooCommerce/Classes/Authentication/Jetpack Setup/Native Jetpack Setup/LoginJetpackSetupViewModel.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ final class LoginJetpackSetupViewModel: ObservableObject {
134134
}
135135

136136
func retryAllSteps() {
137+
analytics.track(.loginJetpackSetupScreenTryAgainButtonTapped,
138+
withProperties: currentSetupStep?.analyticsDescription)
137139
setupFailed = false
138140
setupError = nil
139141
setupErrorDetail = nil
@@ -142,6 +144,12 @@ final class LoginJetpackSetupViewModel: ObservableObject {
142144
currentConnectionStep = nil
143145
startSetup()
144146
}
147+
148+
// MARK: - LoginJetpackSetupInterruptedView
149+
func didTapContinueConnectionButton() {
150+
analytics.track(.loginJetpackSetupScreenTryAgainButtonTapped,
151+
withProperties: currentSetupStep?.analyticsDescription)
152+
}
145153
}
146154

147155
// MARK: Private helpers

WooCommerce/Classes/ViewRelated/Dashboard/JetpackInstall/JetpackInstallSteps.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,24 @@ extension JetpackInstallStep {
9797
}
9898
}
9999

100+
/// Description dictionary for Analytics
101+
///
102+
var analyticsDescription: [String: String] {
103+
let stepDescription = {
104+
switch self {
105+
case .installation:
106+
return "installation"
107+
case .activation:
108+
return "activation"
109+
case .connection:
110+
return "connection"
111+
case .done:
112+
return "all_done"
113+
}
114+
}()
115+
return ["jetpack_install_step": stepDescription]
116+
}
117+
100118
private enum Localization {
101119
static let installationStep = NSLocalizedString("Installing Jetpack", comment: "Name of installing Jetpack plugin step")
102120
static let activationStep = NSLocalizedString("Activating", comment: "Name of the activation Jetpack plugin step")

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,6 +1871,7 @@
18711871
EE0EE7A828B74EF300F6061E /* CustomHelpCenterContentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE0EE7A728B74EF300F6061E /* CustomHelpCenterContentTests.swift */; };
18721872
EE81B1382865BB0B0032E0D4 /* ProductImagesProductIDUpdaterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE81B1372865BB0B0032E0D4 /* ProductImagesProductIDUpdaterTests.swift */; };
18731873
EE8DCA8028BF964700F23B23 /* MockAuthentication.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE8DCA7F28BF964700F23B23 /* MockAuthentication.swift */; };
1874+
EEAA45FD293073FE0047D125 /* JetpackInstallStepTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEAA45FC293073FE0047D125 /* JetpackInstallStepTests.swift */; };
18741875
EEADF622281A40CB001B40F1 /* ShippingValueLocalizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEADF621281A40CB001B40F1 /* ShippingValueLocalizer.swift */; };
18751876
EEADF624281A421A001B40F1 /* DefaultShippingValueLocalizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEADF623281A421A001B40F1 /* DefaultShippingValueLocalizer.swift */; };
18761877
EEADF626281A65A9001B40F1 /* DefaultShippingValueLocalizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEADF625281A65A9001B40F1 /* DefaultShippingValueLocalizerTests.swift */; };
@@ -3866,6 +3867,7 @@
38663867
EE0EE7A728B74EF300F6061E /* CustomHelpCenterContentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomHelpCenterContentTests.swift; sourceTree = "<group>"; };
38673868
EE81B1372865BB0B0032E0D4 /* ProductImagesProductIDUpdaterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductImagesProductIDUpdaterTests.swift; sourceTree = "<group>"; };
38683869
EE8DCA7F28BF964700F23B23 /* MockAuthentication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockAuthentication.swift; sourceTree = "<group>"; };
3870+
EEAA45FC293073FE0047D125 /* JetpackInstallStepTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JetpackInstallStepTests.swift; sourceTree = "<group>"; };
38693871
EEADF621281A40CB001B40F1 /* ShippingValueLocalizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingValueLocalizer.swift; sourceTree = "<group>"; };
38703872
EEADF623281A421A001B40F1 /* DefaultShippingValueLocalizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultShippingValueLocalizer.swift; sourceTree = "<group>"; };
38713873
EEADF625281A65A9001B40F1 /* DefaultShippingValueLocalizerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultShippingValueLocalizerTests.swift; sourceTree = "<group>"; };
@@ -8630,6 +8632,7 @@
86308632
DEE183EC292BD900008818AB /* LoginJetpackSetupViewModelTests.swift */,
86318633
EEC2D27E292CF60E0072132E /* LoginJetpackSetupHostingControllerTests.swift */,
86328634
EEC2D280292D10520072132E /* SiteCredentialLoginHostingViewControllerTests.swift */,
8635+
EEAA45FC293073FE0047D125 /* JetpackInstallStepTests.swift */,
86338636
);
86348637
path = "Jetpack Setup";
86358638
sourceTree = "<group>";
@@ -11152,6 +11155,7 @@
1115211155
45FBDF2D238BF8BF00127F77 /* AddProductImageCollectionViewCellTests.swift in Sources */,
1115311156
578195FC25AD1D7C004A5C12 /* OrderFulfillmentUseCaseTests.swift in Sources */,
1115411157
094C161227B0604700B25F51 /* ProductVariationFormViewModelTests.swift in Sources */,
11158+
EEAA45FD293073FE0047D125 /* JetpackInstallStepTests.swift in Sources */,
1115511159
CECC759923D6160000486676 /* AggregateDataHelperTests.swift in Sources */,
1115611160
454453C82755171E00464AC5 /* HubMenuCoordinatorTests.swift in Sources */,
1115711161
5767E940256D9A4A00CFA652 /* OrderListViewModelTests.swift in Sources */,
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import XCTest
2+
@testable import WooCommerce
3+
4+
final class JetpackInstallStepTests: XCTestCase {
5+
private let testURL = "https://test.com"
6+
7+
func test_analyticsDescription_has_correct_key() throws {
8+
// Given
9+
let sut = try XCTUnwrap(JetpackInstallStep.allCases.randomElement())
10+
11+
// Then
12+
XCTAssertEqual("jetpack_install_step", sut.analyticsDescription.keys.first)
13+
}
14+
15+
func test_analyticsDescription_has_correct_value_for_installation_step() throws {
16+
// Given
17+
let sut = JetpackInstallStep.installation
18+
19+
// Then
20+
XCTAssertEqual("installation", sut.analyticsDescription.values.first)
21+
}
22+
23+
func test_analyticsDescription_has_correct_value_for_activation_step() throws {
24+
// Given
25+
let sut = JetpackInstallStep.activation
26+
27+
// Then
28+
XCTAssertEqual("activation", sut.analyticsDescription.values.first)
29+
}
30+
31+
func test_analyticsDescription_has_correct_value_for_connection_step() throws {
32+
// Given
33+
let sut = JetpackInstallStep.connection
34+
35+
// Then
36+
XCTAssertEqual("connection", sut.analyticsDescription.values.first)
37+
}
38+
39+
func test_analyticsDescription_has_correct_value_for_done_step() throws {
40+
// Given
41+
let sut = JetpackInstallStep.done
42+
43+
// Then
44+
XCTAssertEqual("all_done", sut.analyticsDescription.values.first)
45+
}
46+
}

WooCommerce/WooCommerceTests/Authentication/Jetpack Setup/LoginJetpackSetupViewModelTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,4 +538,17 @@ final class LoginJetpackSetupViewModelTests: XCTestCase {
538538
// Then
539539
XCTAssertNotNil(analyticsProvider.receivedEvents.first(where: { $0 == "login_jetpack_setup_error_checking_jetpack_connection" }))
540540
}
541+
542+
func test_it_tracks_correct_event_when_retying_setup() {
543+
// Given
544+
let analyticsProvider = MockAnalyticsProvider()
545+
let analytics = WooAnalytics(analyticsProvider: analyticsProvider)
546+
let viewModel = LoginJetpackSetupViewModel(siteURL: testURL, connectionOnly: false, analytics: analytics)
547+
548+
// When
549+
viewModel.retryAllSteps()
550+
551+
// Then
552+
XCTAssertNotNil(analyticsProvider.receivedEvents.first(where: { $0 == "login_jetpack_setup_try_again_button_tapped" }))
553+
}
541554
}

0 commit comments

Comments
 (0)