From 85391f1cadff6541ba0368894d5b1c99914e00ee Mon Sep 17 00:00:00 2001 From: emilylaguna Date: Wed, 24 Nov 2021 10:40:56 -0500 Subject: [PATCH 01/12] Add reader search history tracking item --- WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift b/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift index c2889d1e862d..714d73940c0f 100644 --- a/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift +++ b/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift @@ -90,6 +90,7 @@ import Foundation case readerPostMarkUnseen case readerRelatedPostFromOtherSiteClicked case readerRelatedPostFromSameSiteClicked + case readerSearchHistoryCleared // Stats - Empty Stats nudges case statsPublicizeNudgeShown @@ -408,6 +409,8 @@ import Foundation return "reader_related_post_from_other_site_clicked" case .readerRelatedPostFromSameSiteClicked: return "reader_related_post_from_same_site_clicked" + case .readerSearchHistoryCleared: + return "reader_search_history_cleared" // Stats - Empty Stats nudges case .statsPublicizeNudgeShown: From 94ac00a8abab9a48480e492e066a94d638f1661f Mon Sep 17 00:00:00 2001 From: emilylaguna Date: Wed, 24 Nov 2021 10:41:06 -0500 Subject: [PATCH 02/12] Track when the reader search history is cleared --- .../Reader/ReaderSearchSuggestionsViewController.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WordPress/Classes/ViewRelated/Reader/ReaderSearchSuggestionsViewController.swift b/WordPress/Classes/ViewRelated/Reader/ReaderSearchSuggestionsViewController.swift index ef979e2f15ea..b003d1258b92 100644 --- a/WordPress/Classes/ViewRelated/Reader/ReaderSearchSuggestionsViewController.swift +++ b/WordPress/Classes/ViewRelated/Reader/ReaderSearchSuggestionsViewController.swift @@ -137,6 +137,8 @@ class ReaderSearchSuggestionsViewController: UIViewController { service.deleteAllSuggestions() tableView.reloadData() updateHeightConstraint() + + WPAnalytics.trackReader(.readerSearchHistoryCleared) } From 833929fab68301780c4c62ed1a858e2cd32686df Mon Sep 17 00:00:00 2001 From: emilylaguna Date: Wed, 24 Nov 2021 10:41:24 -0500 Subject: [PATCH 03/12] Track the source and type when performing a reader search --- .../Reader/ReaderSearchViewController.swift | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Reader/ReaderSearchViewController.swift b/WordPress/Classes/ViewRelated/Reader/ReaderSearchViewController.swift index 2d3245614428..f48e635034e5 100644 --- a/WordPress/Classes/ViewRelated/Reader/ReaderSearchViewController.swift +++ b/WordPress/Classes/ViewRelated/Reader/ReaderSearchViewController.swift @@ -20,6 +20,25 @@ import Gridicons case .sites: return NSLocalizedString("Sites", comment: "Title of a Reader tab showing Sites matching a user's search query") } } + + var trackingValue: String { + switch self { + case .posts: return "posts" + case .sites: return "sites" + } + } + } + + private enum SearchSource { + case userInput + case searchHistory + + var value: String { + switch self { + case .userInput: return "user_input" + case .searchHistory: return "search_history" + } + } } // MARK: - Properties @@ -236,13 +255,24 @@ import Gridicons /// Constructs a ReaderSearchTopic from the search phrase and sets the /// embedded stream to the topic. /// - @objc func performSearch() { + private func performSearch(source: SearchSource = .userInput) { guard let phrase = searchBar.text?.trim(), !phrase.isEmpty else { return } performPostsSearch(for: phrase) performSitesSearch(for: phrase) + trackSearchPerformed(source: source) + } + + private func trackSearchPerformed(source: SearchSource) { + let selectedTab: Section = Section(rawValue: filterBar.selectedIndex) ?? .posts + let properties: [AnyHashable: Any] = [ + "source": source.value, + "type": selectedTab.trackingValue + ] + + WPAppAnalytics.track(.readerSearchPerformed, withProperties: properties) } private func performPostsSearch(for phrase: String) { @@ -257,7 +287,6 @@ import Gridicons let topic = service.searchTopic(forSearchPhrase: phrase) streamController.readerTopic = topic - WPAppAnalytics.track(.readerSearchPerformed) // Hide the starting label now that a topic has been set. label.isHidden = true @@ -411,7 +440,7 @@ extension ReaderSearchViewController: ReaderSearchSuggestionsDelegate { @objc func searchSuggestionsController(_ controller: ReaderSearchSuggestionsViewController, selectedItem: String) { searchBar.text = selectedItem - performSearch() + performSearch(source: .searchHistory) } } From 587e5882a75f40af46f0645e44b1796ad3d6593e Mon Sep 17 00:00:00 2001 From: emilylaguna Date: Wed, 24 Nov 2021 10:53:28 -0500 Subject: [PATCH 04/12] Remove duplicated toggle follow tracking method --- .../Classes/ViewRelated/Reader/ReaderShowMenuAction.swift | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Reader/ReaderShowMenuAction.swift b/WordPress/Classes/ViewRelated/Reader/ReaderShowMenuAction.swift index a8f06c77807f..2783d43a2cf0 100644 --- a/WordPress/Classes/ViewRelated/Reader/ReaderShowMenuAction.swift +++ b/WordPress/Classes/ViewRelated/Reader/ReaderShowMenuAction.swift @@ -62,10 +62,7 @@ final class ReaderShowMenuAction { let subscribe = !topic.isSubscribedForPostNotifications ReaderSubscribingNotificationAction().execute(for: topic.siteID, context: context, subscribe: subscribe, completion: { - - let event: WPAnalyticsStat = subscribe ? .readerListNotificationMenuOn : .readerListNotificationMenuOff - WPAnalytics.track(event) - + ReaderHelpers.dispatchToggleNotificationMessage(topic: topic, success: true) }, failure: { _ in ReaderHelpers.dispatchToggleNotificationMessage(topic: topic, success: false) From dd55ed6fb7fc6d5774a731173b1703927860e2d7 Mon Sep 17 00:00:00 2001 From: emilylaguna Date: Wed, 24 Nov 2021 14:35:06 -0500 Subject: [PATCH 05/12] Add tracking events for reader article link/image tapping --- WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift b/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift index 714d73940c0f..c9fbc120475a 100644 --- a/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift +++ b/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift @@ -91,6 +91,8 @@ import Foundation case readerRelatedPostFromOtherSiteClicked case readerRelatedPostFromSameSiteClicked case readerSearchHistoryCleared + case readerArticleLinkTapped + case readerArticleImageTapped // Stats - Empty Stats nudges case statsPublicizeNudgeShown @@ -411,6 +413,10 @@ import Foundation return "reader_related_post_from_same_site_clicked" case .readerSearchHistoryCleared: return "reader_search_history_cleared" + case .readerArticleLinkTapped: + return "reader_article_link_tapped" + case .readerArticleImageTapped: + return "reader_article_image_tapped" // Stats - Empty Stats nudges case .statsPublicizeNudgeShown: From 0df02cbdd7a80f2c3f91d36ede478cad2dc3ab53 Mon Sep 17 00:00:00 2001 From: emilylaguna Date: Wed, 24 Nov 2021 14:35:24 -0500 Subject: [PATCH 06/12] Add events for when commenting enters/leaves fullscreen --- WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift b/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift index c9fbc120475a..6204f6bc1fc6 100644 --- a/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift +++ b/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift @@ -177,6 +177,8 @@ import Foundation case commentRepliedTo case commentFilterChanged case commentSnackbarNext + case commentFullScreenEntered + case commentFullScreenExited // InviteLinks case inviteLinksGetStatus @@ -571,6 +573,10 @@ import Foundation return "comment_filter_changed" case .commentSnackbarNext: return "comment_snackbar_next" + case .commentFullScreenEntered: + return "comment_fullscreen_entered" + case .commentFullScreenExited: + return "comment_fullscreen_exited" // Invite Links case .inviteLinksGetStatus: From 4ac8fd29c8537a5bd627a64e9d29ba20cbad27b7 Mon Sep 17 00:00:00 2001 From: emilylaguna Date: Wed, 24 Nov 2021 14:35:37 -0500 Subject: [PATCH 07/12] Add tracking events when notifications previous/next buttons are tapped --- .../Classes/Utility/Analytics/WPAnalyticsEvent.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift b/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift index 6204f6bc1fc6..50c2b9e952d1 100644 --- a/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift +++ b/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift @@ -259,6 +259,10 @@ import Foundation case privacySettingsOpened case privacySettingsReportCrashesToggled + // Notifications + case notificationsPreviousTapped + case notificationsNextTapped + /// A String that represents the event var value: String { switch self { @@ -699,6 +703,12 @@ import Foundation return "account_close_tapped" case .accountCloseCompleted: return "account_close_completed" + + case .notificationsPreviousTapped: + return "notifications_previous_tapped" + case .notificationsNextTapped: + return "notifications_next_tapped" + } // END OF SWITCH } From 2d87c15814c90af4e29299ca0bc66497898ce99d Mon Sep 17 00:00:00 2001 From: emilylaguna Date: Wed, 24 Nov 2021 14:36:04 -0500 Subject: [PATCH 08/12] Track when comment field enters/exits fullscreen --- .../Comments/FullScreenCommentReplyViewController.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/WordPress/Classes/ViewRelated/Comments/FullScreenCommentReplyViewController.swift b/WordPress/Classes/ViewRelated/Comments/FullScreenCommentReplyViewController.swift index ba9ea189ec4b..924ee12e2ddb 100644 --- a/WordPress/Classes/ViewRelated/Comments/FullScreenCommentReplyViewController.swift +++ b/WordPress/Classes/ViewRelated/Comments/FullScreenCommentReplyViewController.swift @@ -50,6 +50,8 @@ public class FullScreenCommentReplyViewController: EditCommentViewController, Su public override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) setupSuggestionsTableViewIfNeeded() + + WPAnalytics.track(.commentFullScreenEntered) } // MARK: - Public Methods @@ -192,6 +194,7 @@ public class FullScreenCommentReplyViewController: EditCommentViewController, Su let updatedText = textView.text ?? "" completion(shouldSave, updatedText) + WPAnalytics.track(.commentFullScreenExited) } var suggestionsTop: NSLayoutConstraint! From 3978ddb8eef0b278ee90c8581546fb6172526144 Mon Sep 17 00:00:00 2001 From: emilylaguna Date: Wed, 24 Nov 2021 14:36:25 -0500 Subject: [PATCH 09/12] Track when you tap the next/previous buttons on the notifications view --- .../Controllers/NotificationDetailsViewController.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift index a4bda937265c..49ca33d8a778 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift @@ -1350,6 +1350,7 @@ extension NotificationDetailsViewController { } refreshView(with: previous) + WPAnalytics.track(.notificationsPreviousTapped) } @IBAction func nextNotificationWasPressed() { @@ -1358,6 +1359,7 @@ extension NotificationDetailsViewController { } refreshView(with: next) + WPAnalytics.track(.notificationsNextTapped) } private func refreshView(with note: Notification) { From d1f8ee40331131fc2b2eacaaed23b19248ac0361 Mon Sep 17 00:00:00 2001 From: emilylaguna Date: Wed, 24 Nov 2021 14:37:08 -0500 Subject: [PATCH 10/12] Track when the link and images are tapped on reader detail --- .../ViewRelated/Reader/Detail/ReaderDetailCoordinator.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/WordPress/Classes/ViewRelated/Reader/Detail/ReaderDetailCoordinator.swift b/WordPress/Classes/ViewRelated/Reader/Detail/ReaderDetailCoordinator.swift index 7f962c6aaefd..bb6f48e9d26f 100644 --- a/WordPress/Classes/ViewRelated/Reader/Detail/ReaderDetailCoordinator.swift +++ b/WordPress/Classes/ViewRelated/Reader/Detail/ReaderDetailCoordinator.swift @@ -1,4 +1,5 @@ import Foundation +import WordPressShared class ReaderDetailCoordinator { @@ -244,6 +245,8 @@ class ReaderDetailCoordinator { /// /// - Parameter url: URL of the image or gif func presentImage(_ url: URL) { + WPAnalytics.trackReader(.readerArticleImageTapped) + let imageViewController = WPImageViewController(url: url) imageViewController.readerPost = post imageViewController.modalTransitionStyle = .crossDissolve @@ -449,6 +452,8 @@ class ReaderDetailCoordinator { } else if url.isLinkProtocol { readerLinkRouter.handle(url: url, shouldTrack: false, source: .inApp(presenter: viewController)) } else { + WPAnalytics.trackReader(.readerArticleLinkTapped) + presentWebViewController(url) } } From 18cdf72e59341d5cd8708ecb38224f2b51b65859 Mon Sep 17 00:00:00 2001 From: emilylaguna Date: Wed, 24 Nov 2021 15:27:22 -0500 Subject: [PATCH 11/12] Fix whitespace --- WordPress/Classes/ViewRelated/Reader/ReaderShowMenuAction.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/Classes/ViewRelated/Reader/ReaderShowMenuAction.swift b/WordPress/Classes/ViewRelated/Reader/ReaderShowMenuAction.swift index 2783d43a2cf0..d3752185a36c 100644 --- a/WordPress/Classes/ViewRelated/Reader/ReaderShowMenuAction.swift +++ b/WordPress/Classes/ViewRelated/Reader/ReaderShowMenuAction.swift @@ -62,7 +62,6 @@ final class ReaderShowMenuAction { let subscribe = !topic.isSubscribedForPostNotifications ReaderSubscribingNotificationAction().execute(for: topic.siteID, context: context, subscribe: subscribe, completion: { - ReaderHelpers.dispatchToggleNotificationMessage(topic: topic, success: true) }, failure: { _ in ReaderHelpers.dispatchToggleNotificationMessage(topic: topic, success: false) From 035d8dc2415357528a7aa89a222a0b575e5f7c77 Mon Sep 17 00:00:00 2001 From: emilylaguna Date: Mon, 29 Nov 2021 08:20:13 -0500 Subject: [PATCH 12/12] Use a string based enum to simplify the SearchSource code --- .../Reader/ReaderSearchViewController.swift | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Reader/ReaderSearchViewController.swift b/WordPress/Classes/ViewRelated/Reader/ReaderSearchViewController.swift index f48e635034e5..a9ddc6f9c9ab 100644 --- a/WordPress/Classes/ViewRelated/Reader/ReaderSearchViewController.swift +++ b/WordPress/Classes/ViewRelated/Reader/ReaderSearchViewController.swift @@ -29,16 +29,9 @@ import Gridicons } } - private enum SearchSource { - case userInput - case searchHistory - - var value: String { - switch self { - case .userInput: return "user_input" - case .searchHistory: return "search_history" - } - } + private enum SearchSource: String { + case userInput = "user_input" + case searchHistory = "search_history" } // MARK: - Properties @@ -268,7 +261,7 @@ import Gridicons private func trackSearchPerformed(source: SearchSource) { let selectedTab: Section = Section(rawValue: filterBar.selectedIndex) ?? .posts let properties: [AnyHashable: Any] = [ - "source": source.value, + "source": source.rawValue, "type": selectedTab.trackingValue ]