Skip to content

Commit 056191c

Browse files
Merge pull request #18560 from wordpress-mobile/task/18408-qs-analytics
Quick Start for Existing Users: Update track events
2 parents db74bb4 + f489f50 commit 056191c

File tree

10 files changed

+113
-32
lines changed

10 files changed

+113
-32
lines changed

WordPress/Classes/Categories/UIViewController+RemoveQuickStart.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ - (void)removeQuickStartFromBlog:(Blog *)blog sourceView:(UIView *)sourceView so
1515

1616
UIAlertController *removeConfirmation = [UIAlertController alertControllerWithTitle:removeTitle message:removeMessage preferredStyle:UIAlertControllerStyleAlert];
1717
[removeConfirmation addCancelActionWithTitle:cancelTitle handler:^(UIAlertAction * _Nonnull action) {
18-
[WPAnalytics track:WPAnalyticsStatQuickStartRemoveDialogButtonCancelTapped];
18+
[WPAnalytics trackQuickStartStat:WPAnalyticsStatQuickStartRemoveDialogButtonCancelTapped blog: blog];
1919
[NoticesDispatch unlock];
2020
}];
2121
[removeConfirmation addDefaultActionWithTitle:confirmationTitle handler:^(UIAlertAction * _Nonnull action) {
22-
[WPAnalytics track:WPAnalyticsStatQuickStartRemoveDialogButtonRemoveTapped];
22+
[WPAnalytics trackQuickStartStat:WPAnalyticsStatQuickStartRemoveDialogButtonRemoveTapped blog: blog];
2323
[[QuickStartTourGuide shared] removeFrom:blog];
2424
[NoticesDispatch unlock];
2525
}];
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import Foundation
2+
3+
extension WPAnalytics {
4+
5+
static let WPAppAnalyticsKeyQuickStartSiteType: String = "site_type"
6+
7+
/// Track a Quick Start event
8+
///
9+
/// This will call each registered tracker and fire the given event
10+
/// - Parameter event: a `WPAnalyticsEvent` that represents the Quick Start event to track
11+
/// - Parameter properties: a `Hash` that represents the properties
12+
/// - Parameter blog: a `Blog` to which the Quick Start event relates to. Used to determine the Quick Start Type
13+
///
14+
static func trackQuickStartEvent(_ event: WPAnalyticsEvent, properties: [AnyHashable: Any] = [:], blog: Blog) {
15+
var props = properties
16+
props[WPAppAnalyticsKeyQuickStartSiteType] = blog.quickStartType.key
17+
WPAnalytics.track(event, properties: props)
18+
}
19+
20+
/// Track a Quick Start stat
21+
///
22+
/// This will call each registered tracker and fire the given stat
23+
/// - Parameter stat: a `WPAnalyticsStat` that represents the Quick Start stat to track
24+
/// - Parameter properties: a `Hash` that represents the properties
25+
/// - Parameter blog: a `Blog` to which the Quick Start stat relates to. Used to determine the Quick Start Type
26+
///
27+
static func trackQuickStartStat(_ stat: WPAnalyticsStat, properties: [AnyHashable: Any] = [:], blog: Blog) {
28+
var props = properties
29+
props[WPAppAnalyticsKeyQuickStartSiteType] = blog.quickStartType.key
30+
WPAnalytics.track(stat, withProperties: props)
31+
}
32+
33+
/// Track a Quick Start stat in Obj-C
34+
///
35+
/// This will call each registered tracker and fire the given stat
36+
/// - Parameter stat: a `WPAnalyticsStat` that represents the Quick Start stat to track
37+
/// - Parameter blog: a `Blog` to which the Quick Start stat relates to. Used to determine the Quick Start Type
38+
///
39+
@objc static func trackQuickStartStat(_ stat: WPAnalyticsStat, blog: Blog) {
40+
let props = [WPAppAnalyticsKeyQuickStartSiteType: blog.quickStartType.key]
41+
WPAnalytics.track(stat, withProperties: props)
42+
}
43+
}

WordPress/Classes/Utility/PushNotificationsManager.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,17 +427,19 @@ extension PushNotificationsManager {
427427
}
428428
WPTabBarController.sharedInstance()?.showMySitesTab()
429429

430-
if let taskName = userInfo.string(forKey: QuickStartTracking.taskNameKey) {
430+
if let taskName = userInfo.string(forKey: QuickStartTracking.taskNameKey),
431+
let quickStartType = userInfo.string(forKey: QuickStartTracking.quickStartTypeKey) {
431432
WPAnalytics.track(.quickStartNotificationTapped,
432-
withProperties: [QuickStartTracking.taskNameKey: taskName])
433+
withProperties: [QuickStartTracking.taskNameKey: taskName,
434+
WPAnalytics.WPAppAnalyticsKeyQuickStartSiteType: quickStartType])
433435
}
434436

435437
completionHandler?(.newData)
436438

437439
return true
438440
}
439441

440-
func postNotification(for tour: QuickStartTour) {
442+
func postNotification(for tour: QuickStartTour, quickStartType: QuickStartType) {
441443
deletePendingLocalNotifications()
442444

443445
let content = UNMutableNotificationContent()
@@ -459,7 +461,8 @@ extension PushNotificationsManager {
459461
UNUserNotificationCenter.current().add(request)
460462

461463
WPAnalytics.track(.quickStartNotificationStarted,
462-
withProperties: [QuickStartTracking.taskNameKey: tour.analyticsKey])
464+
withProperties: [QuickStartTracking.taskNameKey: tour.analyticsKey,
465+
WPAnalytics.WPAppAnalyticsKeyQuickStartSiteType: quickStartType.key])
463466
}
464467

465468
@objc func deletePendingLocalNotifications() {
@@ -473,6 +476,7 @@ extension PushNotificationsManager {
473476

474477
private enum QuickStartTracking {
475478
static let taskNameKey = "task_name"
479+
static let quickStartTypeKey = "site_type"
476480
}
477481
}
478482

WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Quick Start/QuickStartTourStateView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ extension QuickStartTourStateView {
5353
private func showQuickStart(with collection: QuickStartToursCollection, from sourceController: UIViewController, for blog: Blog, tracker: QuickStartChecklistTappedTracker? = nil) {
5454

5555
if let tracker = tracker {
56-
WPAnalytics.track(tracker.event,
57-
properties: tracker.properties,
58-
blog: blog)
56+
WPAnalytics.trackQuickStartEvent(tracker.event,
57+
properties: tracker.properties,
58+
blog: blog)
5959
}
6060

6161
let checklist = QuickStartChecklistViewController(blog: blog, collection: collection)

WordPress/Classes/ViewRelated/Blog/QuickStartChecklistManager.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,9 @@ private extension QuickStartChecklistManager {
196196
completedTours.append(tour)
197197
completedToursKeys.insert(tour.key)
198198

199-
WPAnalytics.track(.quickStartListItemSkipped,
200-
withProperties: ["task_name": tour.analyticsKey])
199+
WPAnalytics.trackQuickStartStat(.quickStartListItemSkipped,
200+
properties: ["task_name": tour.analyticsKey],
201+
blog: blog)
201202

202203
tableView.perform(update: { tableView in
203204
tableView.deleteRows(at: [indexPath], with: .automatic)

WordPress/Classes/ViewRelated/Blog/QuickStartChecklistViewController.swift

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,14 @@ class QuickStartChecklistViewController: UITableViewController {
5757
tours: collection.tours,
5858
didSelectTour: { [weak self] tour in
5959
DispatchQueue.main.async { [weak self] in
60-
WPAnalytics.track(.quickStartChecklistItemTapped, withProperties: ["task_name": tour.analyticsKey])
61-
6260
guard let self = self else {
6361
return
6462
}
6563

64+
WPAnalytics.trackQuickStartStat(.quickStartChecklistItemTapped,
65+
properties: ["task_name": tour.analyticsKey],
66+
blog: self.blog)
67+
6668
QuickStartTourGuide.shared.prepare(tour: tour, for: self.blog)
6769

6870
self.dismiss(animated: true) {
@@ -71,7 +73,9 @@ class QuickStartChecklistViewController: UITableViewController {
7173
}
7274
}, didTapHeader: { [unowned self] expand in
7375
let event: WPAnalyticsStat = expand ? .quickStartListExpanded : .quickStartListCollapsed
74-
WPAnalytics.track(event, withProperties: [Constants.analyticsTypeKey: self.collection.analyticsKey])
76+
WPAnalytics.trackQuickStartStat(event,
77+
properties: [Constants.analyticsTypeKey: self.collection.analyticsKey],
78+
blog: blog)
7579
self.checkForSuccessScreen(expand)
7680
})
7781

@@ -83,8 +87,9 @@ class QuickStartChecklistViewController: UITableViewController {
8387

8488
// should display bg and trigger qs notification
8589

86-
WPAnalytics.track(.quickStartChecklistViewed,
87-
withProperties: [Constants.analyticsTypeKey: collection.analyticsKey])
90+
WPAnalytics.trackQuickStartStat(.quickStartChecklistViewed,
91+
properties: [Constants.analyticsTypeKey: collection.analyticsKey],
92+
blog: blog)
8893
}
8994

9095
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
@@ -146,8 +151,9 @@ private extension QuickStartChecklistViewController {
146151
}
147152

148153
@objc private func closeWasPressed(sender: UIButton) {
149-
WPAnalytics.track(.quickStartTypeDismissed,
150-
withProperties: [Constants.analyticsTypeKey: collection.analyticsKey])
154+
WPAnalytics.trackQuickStartStat(.quickStartTypeDismissed,
155+
properties: [Constants.analyticsTypeKey: collection.analyticsKey],
156+
blog: blog)
151157
dismiss(animated: true, completion: nil)
152158
}
153159
}

WordPress/Classes/ViewRelated/Blog/QuickStartFactory.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ enum QuickStartType: Int {
44
case undefined
55
case newSite
66
case existingSite
7+
8+
var key: String {
9+
switch self {
10+
case .undefined:
11+
return "undefined"
12+
case .newSite:
13+
return "new_site"
14+
case .existingSite:
15+
return "existing_site"
16+
}
17+
}
718
}
819

920
class QuickStartFactory {

WordPress/Classes/ViewRelated/Blog/QuickStartPromptViewController.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,19 @@ final class QuickStartPromptViewController: UIViewController {
139139
onDismiss?(blog, true)
140140
dismiss(animated: true)
141141

142-
WPAnalytics.track(.quickStartRequestAlertButtonTapped, withProperties: ["type": "positive"])
142+
WPAnalytics.trackQuickStartStat(.quickStartRequestAlertButtonTapped,
143+
properties: ["type": "positive"],
144+
blog: blog)
143145
}
144146

145147
@IBAction private func noThanksButtonTapped(_ sender: Any) {
146148
quickStartSettings.setPromptWasDismissed(true, for: blog)
147149
onDismiss?(blog, false)
148150
dismiss(animated: true)
149151

150-
WPAnalytics.track(.quickStartRequestAlertButtonTapped, withProperties: ["type": "neutral"])
152+
WPAnalytics.trackQuickStartStat(.quickStartRequestAlertButtonTapped,
153+
properties: ["type": "neutral"],
154+
blog: blog)
151155
}
152156
}
153157

WordPress/Classes/ViewRelated/Blog/QuickStartTourGuide.swift

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ open class QuickStartTourGuide: NSObject {
5858
blog.quickStartType = type
5959

6060
NotificationCenter.default.post(name: .QuickStartTourElementChangedNotification, object: self)
61-
WPAnalytics.track(.quickStartStarted)
61+
WPAnalytics.trackQuickStartEvent(.quickStartStarted, blog: blog)
6262

6363
NotificationCenter.default.post(name: .QuickStartTourElementChangedNotification,
6464
object: self,
@@ -143,17 +143,21 @@ open class QuickStartTourGuide: NSObject {
143143
self?.prepare(tour: tour, for: blog)
144144
self?.begin()
145145
cancelTimer(false)
146-
WPAnalytics.track(.quickStartSuggestionButtonTapped, withProperties: ["type": "positive"])
146+
WPAnalytics.trackQuickStartStat(.quickStartSuggestionButtonTapped,
147+
properties: ["type": "positive"],
148+
blog: blog)
147149
} else {
148150
self?.skipped(tour, for: blog)
149151
cancelTimer(true)
150-
WPAnalytics.track(.quickStartSuggestionButtonTapped, withProperties: ["type": "negative"])
152+
WPAnalytics.trackQuickStartStat(.quickStartSuggestionButtonTapped,
153+
properties: ["type": "negative"],
154+
blog: blog)
151155
}
152156
}
153157

154158
ActionDispatcher.dispatch(NoticeAction.post(notice))
155159

156-
WPAnalytics.track(.quickStartSuggestionViewed)
160+
WPAnalytics.trackQuickStartStat(.quickStartSuggestionViewed, blog: blog)
157161
}
158162

159163
/// Prepares to begin the specified tour.
@@ -247,7 +251,7 @@ open class QuickStartTourGuide: NSObject {
247251

248252
ActionDispatcher.dispatch(NoticeAction.post(notice))
249253

250-
WPAnalytics.track(.quickStartCongratulationsViewed)
254+
WPAnalytics.trackQuickStartStat(.quickStartCongratulationsViewed, blog: blog)
251255
}
252256

253257
// we have this because poor stupid ObjC doesn't know what the heck an optional is
@@ -355,27 +359,29 @@ private extension QuickStartTourGuide {
355359

356360
blog.completeTour(tour.key)
357361

362+
// Create a site is completed automatically, we don't want to track
363+
if tour.analyticsKey != "create_site" {
364+
WPAnalytics.trackQuickStartStat(.quickStartTourCompleted,
365+
properties: ["task_name": tour.analyticsKey],
366+
blog: blog)
367+
}
368+
358369
if postNotification {
359370
NotificationCenter.default.post(name: .QuickStartTourElementChangedNotification, object: self, userInfo: [QuickStartTourGuide.notificationElementKey: QuickStartTourElement.tourCompleted])
360371

361-
// Create a site is completed automatically, we don't want to track
362-
if tour.analyticsKey != "create_site" {
363-
WPAnalytics.track(.quickStartTourCompleted, withProperties: ["task_name": tour.analyticsKey])
364-
}
365-
366372
recentlyTouredBlog = blog
367373
} else {
368374
recentlyTouredBlog = nil
369375
}
370376

371377
if allToursCompleted(for: blog) {
372-
WPAnalytics.track(.quickStartAllToursCompleted)
378+
WPAnalytics.trackQuickStartStat(.quickStartAllToursCompleted, blog: blog)
373379
grantCongratulationsAward(for: blog)
374380
tourInProgress = false
375381
shouldShowCongratsNotice = true
376382
} else {
377383
if let nextTour = tourToSuggest(for: blog) {
378-
PushNotificationsManager.shared.postNotification(for: nextTour)
384+
PushNotificationsManager.shared.postNotification(for: nextTour, quickStartType: blog.quickStartType)
379385
}
380386
}
381387
}

WordPress/WordPress.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,8 @@
13731373
80EF929028105CFA0064A971 /* QuickStartFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80EF928F28105CFA0064A971 /* QuickStartFactory.swift */; };
13741374
80EF929128105CFA0064A971 /* QuickStartFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80EF928F28105CFA0064A971 /* QuickStartFactory.swift */; };
13751375
80EF92932810FA5A0064A971 /* QuickStartFactoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80EF92922810FA5A0064A971 /* QuickStartFactoryTests.swift */; };
1376+
80F8DAC1282B6546007434A0 /* WPAnalytics+QuickStart.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80F8DAC0282B6546007434A0 /* WPAnalytics+QuickStart.swift */; };
1377+
80F8DAC2282B6546007434A0 /* WPAnalytics+QuickStart.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80F8DAC0282B6546007434A0 /* WPAnalytics+QuickStart.swift */; };
13761378
820ADD701F3A1F88002D7F93 /* ThemeBrowserSectionHeaderView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 820ADD6F1F3A1F88002D7F93 /* ThemeBrowserSectionHeaderView.xib */; };
13771379
820ADD721F3A226E002D7F93 /* ThemeBrowserSectionHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 820ADD711F3A226E002D7F93 /* ThemeBrowserSectionHeaderView.swift */; };
13781380
821738091FE04A9E00BEC94C /* DateAndTimeFormatSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 821738081FE04A9E00BEC94C /* DateAndTimeFormatSettingsViewController.swift */; };
@@ -6143,6 +6145,7 @@
61436145
80EF928C280E83110064A971 /* QuickStartToursCollection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickStartToursCollection.swift; sourceTree = "<group>"; };
61446146
80EF928F28105CFA0064A971 /* QuickStartFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickStartFactory.swift; sourceTree = "<group>"; };
61456147
80EF92922810FA5A0064A971 /* QuickStartFactoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickStartFactoryTests.swift; sourceTree = "<group>"; };
6148+
80F8DAC0282B6546007434A0 /* WPAnalytics+QuickStart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WPAnalytics+QuickStart.swift"; sourceTree = "<group>"; };
61466149
820ADD6C1F3A0DA0002D7F93 /* WordPress 64.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "WordPress 64.xcdatamodel"; sourceTree = "<group>"; };
61476150
820ADD6F1F3A1F88002D7F93 /* ThemeBrowserSectionHeaderView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ThemeBrowserSectionHeaderView.xib; sourceTree = "<group>"; };
61486151
820ADD711F3A226E002D7F93 /* ThemeBrowserSectionHeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ThemeBrowserSectionHeaderView.swift; sourceTree = "<group>"; };
@@ -11569,6 +11572,7 @@
1156911572
8BAD53D5241922B900230F4B /* WPAnalyticsEvent.swift */,
1157011573
0828D7F91E6E09AE00C7C7D4 /* WPAppAnalytics+Media.swift */,
1157111574
175CC17B2723103000622FB4 /* WPAnalytics+Domains.swift */,
11575+
80F8DAC0282B6546007434A0 /* WPAnalytics+QuickStart.swift */,
1157211576
);
1157311577
path = Analytics;
1157411578
sourceTree = "<group>";
@@ -18408,6 +18412,7 @@
1840818412
2FA6511721F26A24009AA935 /* ChangePasswordViewController.swift in Sources */,
1840918413
D816C1F020E0893A00C4D82F /* LikeComment.swift in Sources */,
1841018414
982DA9A7263B1E2F00E5743B /* CommentService+Likes.swift in Sources */,
18415+
80F8DAC1282B6546007434A0 /* WPAnalytics+QuickStart.swift in Sources */,
1841118416
59E1D46E1CEF77B500126697 /* Page.swift in Sources */,
1841218417
321955BF24BE234C00E3F316 /* ReaderInterestsCoordinator.swift in Sources */,
1841318418
FAE4327425874D140039EB8C /* ReaderSavedPostCellActions.swift in Sources */,
@@ -21170,6 +21175,7 @@
2117021175
FABB24CC2602FC2C00C8785C /* CollapsableHeaderViewController.swift in Sources */,
2117121176
FABB24CD2602FC2C00C8785C /* Blog+Lookup.swift in Sources */,
2117221177
FABB24CE2602FC2C00C8785C /* ReaderTopicService.m in Sources */,
21178+
80F8DAC2282B6546007434A0 /* WPAnalytics+QuickStart.swift in Sources */,
2117321179
FABB24CF2602FC2C00C8785C /* HeaderDetailsContentStyles.swift in Sources */,
2117421180
FABB24D02602FC2C00C8785C /* RewindStatusRow.swift in Sources */,
2117521181
8BD34F0C27D14B3C005E931C /* Blog+DashboardState.swift in Sources */,

0 commit comments

Comments
 (0)