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

Empty Stats: Add event tracking for Publicize / Blogging Reminders #17313

Merged
merged 15 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from 10 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
35 changes: 35 additions & 0 deletions WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ import Foundation
case readerRelatedPostFromOtherSiteClicked
case readerRelatedPostFromSameSiteClicked

// Stats - Empty Stats nudges
case statsPublicizeNudgeShown
case statsPublicizeNudgeTapped
case statsPublicizeNudgeDismissed
case statsPublicizeNudgeCompleted
case statsBloggingRemindersNudgeShown
case statsBloggingRemindersNudgeTapped
case statsBloggingRemindersNudgeDismissed
case statsBloggingRemindersNudgeCompleted

// Stats - Customize card
case statsCustomizeInsightsShown

// What's New - Feature announcements
case featureAnnouncementShown
case featureAnnouncementButtonTapped
Expand Down Expand Up @@ -333,6 +346,28 @@ import Foundation
case .readerRelatedPostFromSameSiteClicked:
return "reader_related_post_from_same_site_clicked"

// Stats - Empty Stats nudges
case .statsPublicizeNudgeShown:
return "stats_publicize_nudge_shown"
case .statsPublicizeNudgeTapped:
return "stats_publicize_nudge_tapped"
case .statsPublicizeNudgeDismissed:
return "stats_publicize_nudge_dismissed"
case .statsPublicizeNudgeCompleted:
return "stats_publicize_nudge_completed"
case .statsBloggingRemindersNudgeShown:
return "stats_blogging_reminders_nudge_shown"
case .statsBloggingRemindersNudgeTapped:
return "stats_blogging_reminders_nudge_tapped"
case .statsBloggingRemindersNudgeDismissed:
return "stats_blogging_reminders_nudge_dismissed"
case .statsBloggingRemindersNudgeCompleted:
return "stats_blogging_reminders_nudge_completed"

// Stats - Customize card
case .statsCustomizeInsightsShown:
return "stats_customize_insights_shown"

// What's New - Feature announcements
case .featureAnnouncementShown:
return "feature_announcement_shown"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,20 @@ private extension SiteStatsInsightsTableViewController {
}

func loadPinnedCards() {
let viewsCount = insightsStore.getAllTimeStats()?.viewsCount ?? 0
let viewsCount = insightsStore.getAllTimeStats()?.viewsCount
switch pinnedItemStore?.itemToDisplay(for: viewsCount) {
case .none:
insightsToShow = insightsToShow.filter { $0 != .growAudience || $0 != .customize }
case .some(let item):
switch item {
case is GrowAudienceCell.HintType where !insightsToShow.contains(.growAudience):
case let hintType as GrowAudienceCell.HintType where !insightsToShow.contains(.growAudience):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

insightsToShow = insightsToShow.filter { $0 != .customize }
insightsToShow.insert(.growAudience, at: 0)
trackNudgeShown(for: hintType)
case InsightType.customize where !insightsToShow.contains(.customize):
insightsToShow = insightsToShow.filter { $0 != .growAudience }
insightsToShow.insert(.customize, at: 0)
WPAnalytics.trackEvent(.statsCustomizeInsightsShown)
default:
break
}
Expand All @@ -246,6 +248,8 @@ private extension SiteStatsInsightsTableViewController {
}
insightsToShow = insightsToShow.filter { $0 != .growAudience }
pinnedItemStore?.markPinnedItemAsHidden(item)

trackNudgeDismissed(for: item)
}

func refreshGrowAudienceCardIfNecessary() {
Expand Down Expand Up @@ -466,6 +470,8 @@ extension SiteStatsInsightsTableViewController: SiteStatsInsightsDelegate {
present(navigationController, animated: true)

applyTableUpdates()

trackNudgeEvent(.statsPublicizeNudgeTapped)
}

func growAudienceBloggingRemindersButtonTapped() {
Expand All @@ -481,6 +487,8 @@ extension SiteStatsInsightsTableViewController: SiteStatsInsightsDelegate {
delegate: self)

applyTableUpdates()

trackNudgeEvent(.statsBloggingRemindersNudgeTapped)
}

func showAddInsight() {
Expand Down Expand Up @@ -550,6 +558,8 @@ extension SiteStatsInsightsTableViewController: SharingViewControllerDelegate {
func didChangePublicizeServices() {
viewModel?.markEmptyStatsNudgeAsCompleted()
refreshTableView()

trackNudgeEvent(.statsPublicizeNudgeCompleted)
}
}

Expand All @@ -559,6 +569,8 @@ extension SiteStatsInsightsTableViewController: BloggingRemindersFlowDelegate {
func didSetUpBloggingReminders() {
viewModel?.markEmptyStatsNudgeAsCompleted()
refreshTableView()

trackNudgeEvent(.statsBloggingRemindersNudgeCompleted)
}
}

Expand Down Expand Up @@ -622,3 +634,35 @@ extension SiteStatsInsightsTableViewController: NoResultsViewHost {
static let manageInsightsButtonTitle = NSLocalizedString("Add stats card", comment: "Button title displayed when the user has removed all Insights from display.")
}
}

// MARK: - Tracks Support

private extension SiteStatsInsightsTableViewController {

func trackNudgeEvent(_ event: WPAnalyticsEvent) {
if let blogId = SiteStatsInformation.sharedInstance.siteID,
let blog = Blog.lookup(withID: blogId, in: mainContext) {
WPAnalytics.track(event, properties: [:], blog: blog)
} else {
WPAnalytics.track(event)
}
}

func trackNudgeShown(for hintType: GrowAudienceCell.HintType) {
switch hintType {
case .social:
trackNudgeEvent(.statsPublicizeNudgeShown)
case .bloggingReminders:
trackNudgeEvent(.statsBloggingRemindersNudgeShown)
}
}

func trackNudgeDismissed(for hintType: GrowAudienceCell.HintType) {
switch hintType {
case .social:
trackNudgeEvent(.statsPublicizeNudgeDismissed)
case .bloggingReminders:
trackNudgeEvent(.statsBloggingRemindersNudgeDismissed)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SiteStatsInsightsViewModel: Observable {
self.insightsToShow = insightsToShow
self.insightsStore = insightsStore
self.pinnedItemStore = pinnedItemStore
let viewsCount = insightsStore.getAllTimeStats()?.viewsCount ?? 0
let viewsCount = insightsStore.getAllTimeStats()?.viewsCount
self.itemToDisplay = pinnedItemStore?.itemToDisplay(for: viewsCount)

insightsChangeReceipt = self.insightsStore.onChange { [weak self] in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ final class SiteStatsPinnedItemStore {
self.siteId = siteId
}

func itemToDisplay(for siteViewsCount: Int) -> SiteStatsPinnable? {
func itemToDisplay(for siteViewsCount: Int?) -> SiteStatsPinnable? {
guard let siteViewsCount = siteViewsCount else {
return nil
}

if siteViewsCount < lowSiteViewsCountTreshold {
return nudgeToDisplay ?? customizeToDisplay
} else {
Expand Down