Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds more tracking to the reader, comments, and notifications #17558

Merged
merged 14 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ import Foundation
case readerPostMarkUnseen
case readerRelatedPostFromOtherSiteClicked
case readerRelatedPostFromSameSiteClicked
case readerSearchHistoryCleared
case readerArticleLinkTapped
case readerArticleImageTapped

// Stats - Empty Stats nudges
case statsPublicizeNudgeShown
Expand Down Expand Up @@ -174,6 +177,8 @@ import Foundation
case commentRepliedTo
case commentFilterChanged
case commentSnackbarNext
case commentFullScreenEntered
case commentFullScreenExited

// InviteLinks
case inviteLinksGetStatus
Expand Down Expand Up @@ -256,6 +261,9 @@ import Foundation
case privacySettingsOpened
case privacySettingsReportCrashesToggled

// Notifications
case notificationsPreviousTapped
case notificationsNextTapped
// Sharing Buttons
case sharingButtonsEditSharingButtonsToggled
case sharingButtonsEditMoreButtonToggled
Expand Down Expand Up @@ -422,6 +430,12 @@ 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"
case .readerArticleLinkTapped:
return "reader_article_link_tapped"
case .readerArticleImageTapped:
return "reader_article_image_tapped"

// Stats - Empty Stats nudges
case .statsPublicizeNudgeShown:
Expand Down Expand Up @@ -576,6 +590,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:
Expand Down Expand Up @@ -703,6 +721,11 @@ import Foundation
case .accountCloseCompleted:
return "account_close_completed"

case .notificationsPreviousTapped:
return "notifications_previous_tapped"
case .notificationsNextTapped:
return "notifications_next_tapped"

// Sharing
case .sharingButtonsEditSharingButtonsToggled:
return "sharing_buttons_edit_sharing_buttons_toggled"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -192,6 +194,7 @@ public class FullScreenCommentReplyViewController: EditCommentViewController, Su
let updatedText = textView.text ?? ""

completion(shouldSave, updatedText)
WPAnalytics.track(.commentFullScreenExited)
}

var suggestionsTop: NSLayoutConstraint!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,7 @@ extension NotificationDetailsViewController {
}

refreshView(with: previous)
WPAnalytics.track(.notificationsPreviousTapped)
}

@IBAction func nextNotificationWasPressed() {
Expand All @@ -1358,6 +1359,7 @@ extension NotificationDetailsViewController {
}

refreshView(with: next)
WPAnalytics.track(.notificationsNextTapped)
}

private func refreshView(with note: Notification) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressShared

class ReaderDetailCoordinator {

Expand Down Expand Up @@ -265,6 +266,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
Expand Down Expand Up @@ -470,6 +473,8 @@ class ReaderDetailCoordinator {
} else if url.isLinkProtocol {
readerLinkRouter.handle(url: url, shouldTrack: false, source: .inApp(presenter: viewController))
} else {
WPAnalytics.trackReader(.readerArticleLinkTapped)

presentWebViewController(url)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class ReaderSearchSuggestionsViewController: UIViewController {
service.deleteAllSuggestions()
tableView.reloadData()
updateHeightConstraint()

WPAnalytics.trackReader(.readerSearchHistoryCleared)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ 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: String {
case userInput = "user_input"
case searchHistory = "search_history"
}

// MARK: - Properties
Expand Down Expand Up @@ -236,13 +248,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.rawValue,
"type": selectedTab.trackingValue
]

WPAppAnalytics.track(.readerSearchPerformed, withProperties: properties)
}

private func performPostsSearch(for phrase: String) {
Expand All @@ -257,7 +280,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
Expand Down Expand Up @@ -411,7 +433,7 @@ extension ReaderSearchViewController: ReaderSearchSuggestionsDelegate {

@objc func searchSuggestionsController(_ controller: ReaderSearchSuggestionsViewController, selectedItem: String) {
searchBar.text = selectedItem
performSearch()
performSearch(source: .searchHistory)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ 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)
Expand Down