Skip to content

Commit 6c9ab99

Browse files
committed
Implement analytics for account closure.
1 parent 6a21f2a commit 6c9ab99

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

WooCommerce/Classes/Analytics/WooAnalyticsEvent.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,31 @@ extension WooAnalyticsEvent {
11251125
}
11261126
}
11271127

1128+
// MARK: - Close Account
1129+
//
1130+
extension WooAnalyticsEvent {
1131+
/// The source that presents the Jetpack install screen.
1132+
enum CloseAccountSource: String {
1133+
case settings
1134+
case emptyStores = "empty_stores"
1135+
}
1136+
1137+
/// Tracked when the user taps to close their WordPress.com account.
1138+
static func closeAccountTapped(source: CloseAccountSource) -> WooAnalyticsEvent {
1139+
WooAnalyticsEvent(statName: .closeAccountTapped, properties: ["source": source.rawValue])
1140+
}
1141+
1142+
/// Tracked when the WordPress.com account closure succeeds.
1143+
static func closeAccountSuccess() -> WooAnalyticsEvent {
1144+
WooAnalyticsEvent(statName: .closeAccountSuccess, properties: [:])
1145+
}
1146+
1147+
/// Tracked when the WordPress.com account closure fails.
1148+
static func closeAccountFailed(error: Error) -> WooAnalyticsEvent {
1149+
WooAnalyticsEvent(statName: .closeAccountFailed, properties: [:], error: error)
1150+
}
1151+
}
1152+
11281153
private extension PaymentMethod {
11291154
var analyticsValue: String {
11301155
switch self {

WooCommerce/Classes/Analytics/WooAnalyticsStat.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,11 @@ public enum WooAnalyticsStat: String {
595595
case inboxNotesLoaded = "inbox_notes_loaded"
596596
case inboxNotesLoadedFailed = "inbox_notes_load_failed"
597597
case inboxNoteAction = "inbox_note_action"
598+
599+
// MARK: Close Account
600+
case closeAccountTapped = "close_account_tapped"
601+
case closeAccountSuccess = "close_account_success"
602+
case closeAccountFailed = "close_account_failed"
598603
}
599604

600605
public extension WooAnalyticsStat {

WooCommerce/Classes/Authentication/Epilogue/StorePickerViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ extension StorePickerViewController: UITableViewDataSource {
650650
if isRemoveAppleIDAccessButtonVisible {
651651
cell.onCloseAccountButtonTapped = { [weak self] in
652652
guard let self = self else { return }
653+
ServiceLocator.analytics.track(event: .closeAccountTapped(source: .emptyStores))
653654
self.removeAppleIDAccessCoordinator.start()
654655
}
655656
}

WooCommerce/Classes/ViewRelated/Dashboard/Settings/RemoveAppleIDAccessCoordinator.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import protocol Yosemite.StoresManager
77
private let removeAction: () async -> Result<Void, Error>
88
private let onRemoveSuccess: () -> Void
99
private let stores: StoresManager
10+
private let analytics: Analytics
1011

1112
/// - Parameters:
1213
/// - sourceViewController: the view controller that presents the in-progress UI and alerts.
@@ -15,11 +16,13 @@ import protocol Yosemite.StoresManager
1516
init(sourceViewController: UIViewController,
1617
removeAction: @escaping () async -> Result<Void, Error>,
1718
onRemoveSuccess: @escaping () -> Void,
18-
stores: StoresManager = ServiceLocator.stores) {
19+
stores: StoresManager = ServiceLocator.stores,
20+
analytics: Analytics = ServiceLocator.analytics) {
1921
self.sourceViewController = sourceViewController
2022
self.removeAction = removeAction
2123
self.onRemoveSuccess = onRemoveSuccess
2224
self.stores = stores
25+
self.analytics = analytics
2326
}
2427

2528
func start() {
@@ -52,8 +55,10 @@ private extension RemoveAppleIDAccessCoordinator {
5255
guard let self = self else { return }
5356
switch result {
5457
case .success:
58+
self.analytics.track(event: .closeAccountSuccess())
5559
self.onRemoveSuccess()
5660
case .failure(let error):
61+
self.analytics.track(event: .closeAccountFailed(error: error))
5762
DDLogError("⛔️ Cannot close account: \(error)")
5863
self.presentErrorAlert(error: error)
5964
}

WooCommerce/Classes/ViewRelated/Dashboard/Settings/Settings/SettingsViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ private extension SettingsViewController {
258258
//
259259
private extension SettingsViewController {
260260
func removeAppleIDAccessWasPressed() {
261+
ServiceLocator.analytics.track(event: .closeAccountTapped(source: .settings))
261262
removeAppleIDAccessCoordinator.start()
262263
}
263264

0 commit comments

Comments
 (0)