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 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
2 changes: 1 addition & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -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
-----
Expand Down
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,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):
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)

// 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
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this to prevent the event from being fired multiple times?

if that's the case, this is something we should not be worried about, given that normally we look at "unique" events.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, this is a workaround to make sure the correct event will be fired once.

If you go to a site with more than 30 views (i.e. customize should be showing) and comment out the if viewsCount != nilstatement, you'll see that the publicize_nudge_shown event is fired right before the correct event, customize_insights_shown.

I tried doing b4fb243 in an attempt to fix this behavior, but that actually ended up breaking the presentation logic. (after dismissing a card, the next card shown would be the incorrect card, etc.) Maybe @nikola-milicevic has some insight on how to address this issue without breaking the presentation logic?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh ok! If that's the case then don't worry. Just wanted to make sure.

if viewsCount != nil {
WPAnalytics.trackEvent(.statsCustomizeInsightsShown)
}

default:
break
}
Expand All @@ -246,6 +258,8 @@ private extension SiteStatsInsightsTableViewController {
}
insightsToShow = insightsToShow.filter { $0 != .growAudience }
pinnedItemStore?.markPinnedItemAsHidden(item)

trackNudgeDismissed(for: item)
}

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

applyTableUpdates()

trackNudgeEvent(.statsPublicizeNudgeTapped)
}

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

applyTableUpdates()

trackNudgeEvent(.statsBloggingRemindersNudgeTapped)
}

func showAddInsight() {
Expand Down Expand Up @@ -549,7 +567,10 @@ extension SiteStatsInsightsTableViewController: SiteStatsInsightsDelegate {
extension SiteStatsInsightsTableViewController: SharingViewControllerDelegate {
func didChangePublicizeServices() {
viewModel?.markEmptyStatsNudgeAsCompleted()
insightsToShow = insightsToShow.filter { $0 != .growAudience }
refreshTableView()

trackNudgeEvent(.statsPublicizeNudgeCompleted)
}
}

Expand All @@ -558,7 +579,10 @@ extension SiteStatsInsightsTableViewController: SharingViewControllerDelegate {
extension SiteStatsInsightsTableViewController: BloggingRemindersFlowDelegate {
func didSetUpBloggingReminders() {
viewModel?.markEmptyStatsNudgeAsCompleted()
insightsToShow = insightsToShow.filter { $0 != .growAudience }
refreshTableView()

trackNudgeEvent(.statsBloggingRemindersNudgeCompleted)
}
}

Expand Down Expand Up @@ -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)
}
}
}