diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 8f27904763cf..abfa5ad6aa23 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -1,7 +1,7 @@ 18.5 ----- * [**] Block editor: Embed block: Include Jetpack embed variants. [https://github.com/wordpress-mobile/gutenberg-mobile/pull/4008] - +* [**] Stats: added Publicize and Blogging Reminders nudges for sites with low traffic in order to increase it. [#17142, #17261, #17294, #17312, #17323] 18.4 ----- diff --git a/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift b/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift index 03c717f51a63..c0c97470f2e8 100644 --- a/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift +++ b/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift @@ -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 @@ -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" diff --git a/WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsInsightsTableViewController.swift b/WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsInsightsTableViewController.swift index 8a9c29191e7d..279b425ec368 100644 --- a/WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsInsightsTableViewController.swift +++ b/WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsInsightsTableViewController.swift @@ -211,18 +211,30 @@ private extension SiteStatsInsightsTableViewController { } func loadPinnedCards() { - let viewsCount = insightsStore.getAllTimeStats()?.viewsCount ?? 0 - switch pinnedItemStore?.itemToDisplay(for: viewsCount) { + let viewsCount = insightsStore.getAllTimeStats()?.viewsCount + switch pinnedItemStore?.itemToDisplay(for: viewsCount ?? 0) { 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): insightsToShow = insightsToShow.filter { $0 != .customize } insightsToShow.insert(.growAudience, at: 0) + + // Work around to make sure nudge shown is tracked only once + if viewsCount != nil { + trackNudgeShown(for: hintType) + } + case InsightType.customize where !insightsToShow.contains(.customize): insightsToShow = insightsToShow.filter { $0 != .growAudience } insightsToShow.insert(.customize, at: 0) + + // Work around to make sure customize insights shown is tracked only once + if viewsCount != nil { + WPAnalytics.trackEvent(.statsCustomizeInsightsShown) + } + default: break } @@ -246,6 +258,8 @@ private extension SiteStatsInsightsTableViewController { } insightsToShow = insightsToShow.filter { $0 != .growAudience } pinnedItemStore?.markPinnedItemAsHidden(item) + + trackNudgeDismissed(for: item) } func refreshGrowAudienceCardIfNecessary() { @@ -466,6 +480,8 @@ extension SiteStatsInsightsTableViewController: SiteStatsInsightsDelegate { present(navigationController, animated: true) applyTableUpdates() + + trackNudgeEvent(.statsPublicizeNudgeTapped) } func growAudienceBloggingRemindersButtonTapped() { @@ -481,6 +497,8 @@ extension SiteStatsInsightsTableViewController: SiteStatsInsightsDelegate { delegate: self) applyTableUpdates() + + trackNudgeEvent(.statsBloggingRemindersNudgeTapped) } func showAddInsight() { @@ -549,7 +567,10 @@ extension SiteStatsInsightsTableViewController: SiteStatsInsightsDelegate { extension SiteStatsInsightsTableViewController: SharingViewControllerDelegate { func didChangePublicizeServices() { viewModel?.markEmptyStatsNudgeAsCompleted() + insightsToShow = insightsToShow.filter { $0 != .growAudience } refreshTableView() + + trackNudgeEvent(.statsPublicizeNudgeCompleted) } } @@ -558,7 +579,10 @@ extension SiteStatsInsightsTableViewController: SharingViewControllerDelegate { extension SiteStatsInsightsTableViewController: BloggingRemindersFlowDelegate { func didSetUpBloggingReminders() { viewModel?.markEmptyStatsNudgeAsCompleted() + insightsToShow = insightsToShow.filter { $0 != .growAudience } refreshTableView() + + trackNudgeEvent(.statsBloggingRemindersNudgeCompleted) } } @@ -622,3 +646,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) + } + } +}