Skip to content

Commit 8c70bf1

Browse files
authored
Stats: Make Views & Visitors, Total Likes, and Total Comments cards data consistent with the Web (#19900)
* Load weekly data for Views&Visitors, Total Likes, and Total Comments Insights excluding today * Update Views & Visitors labels from "week" to "7-days" * Update TotalLikes and TotalComments labels from "week" to "7-days" * Create yesterdayDateForSite() * Allow opening details from Followers card - For routing to work, we need to include `.insightsFollowersWordPress` in allInsights - For insight management to work, we need to remove `insightsFollowersWordPress` to avoid double `Followers` rows appearing. It happens because `insightsFollowersWordPress` and insightsFollowersEmail` share the same `InsightType` and are represented by a single card. * Show "View More" action button for total likes, making it the same as on Android
1 parent 47d7400 commit 8c70bf1

File tree

9 files changed

+56
-26
lines changed

9 files changed

+56
-26
lines changed

WordPress/Classes/ViewRelated/Stats/Charts/InsightsLineChart.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ class InsightsLineChart {
8383
var chartData = [LineChartData]()
8484

8585
let thisWeekDataSet = LineChartDataSet(entries: thisWeekEntries,
86-
label: NSLocalizedString("This Week", comment: "Accessibility label used for distinguishing Views and Visitors in the Stats → Insights Views Visitors Line chart."))
86+
label: NSLocalizedString("stats.insights.accessibility.label.viewsVisitorsLastDays", value: "Last 7-days", comment: "Accessibility label used for distinguishing Views and Visitors in the Stats → Insights Views Visitors Line chart."))
8787
let prevWeekDataSet = LineChartDataSet(entries: prevWeekEntries,
88-
label: NSLocalizedString("Previous Week", comment: "Accessibility label used for distinguishing Views and Visitors in the Stats → Insights Views Visitors Line chart."))
88+
label: NSLocalizedString("stats.insights.accessibility.label.viewsVisitorsPreviousDays", value: "Previous 7-days", comment: "Accessibility label used for distinguishing Views and Visitors in the Stats → Insights Views Visitors Line chart."))
8989
let viewsDataSets = [ thisWeekDataSet, prevWeekDataSet ]
9090
let viewsChartData = LineChartData(dataSets: viewsDataSets)
9191
chartData.append(viewsChartData)

WordPress/Classes/ViewRelated/Stats/Helpers/SiteStatsImmuTableRows.swift

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,23 @@ class SiteStatsImmuTableRows {
9797
}
9898

9999
enum Constants {
100-
static let viewsHigher = NSLocalizedString("Your views this week are %@ higher than the previous week.\n", comment: "Stats insights views higher than previous week")
101-
static let viewsLower = NSLocalizedString("Your views this week are %@ lower than the previous week.\n", comment: "Stats insights views lower than previous week")
102-
static let visitorsHigher = NSLocalizedString("Your visitors this week are %@ higher than the previous week.\n", comment: "Stats insights visitors higher than previous week")
103-
static let visitorsLower = NSLocalizedString("Your visitors this week are %@ lower than the previous week.\n", comment: "Stats insights visitors lower than previous week")
104-
static let viewsNoDifference = NSLocalizedString("Your views this week are the same as the previous week.\n", comment: "Stats insights label shown when the user's view count is the same as the previous week.")
105-
static let visitorsNoDifference = NSLocalizedString("Your visitors this week are the same as the previous week.\n", comment: "Stats insights label shown when the user's visitor count is the same as the previous week.")
100+
static let viewsHigher = NSLocalizedString("stats.insights.label.views.sevenDays.higher",
101+
value: "Your views in the last 7-days are %@ higher than the previous 7-days.\n",
102+
comment: "Stats insights views higher than previous 7 days")
103+
static let viewsLower = NSLocalizedString("stats.insights.label.views.sevenDays.lower",
104+
value: "Your views in the last 7-days are %@ lower than the previous 7-days.\n",
105+
comment: "Stats insights views lower than previous 7 days")
106+
static let visitorsHigher = NSLocalizedString("stats.insights.label.visitors.sevenDays.higher",
107+
value: "Your visitors in the last 7-days are %@ higher than the previous 7-days.\n",
108+
comment: "Stats insights visitors higher than previous 7 days")
109+
static let visitorsLower = NSLocalizedString("stats.insights.label.visitors.sevenDays.lower",
110+
value: "Your visitors in the last 7-days are %@ lower than the previous 7-days.\n",
111+
comment: "Stats insights visitors lower than previous 7 days")
112+
static let viewsNoDifference = NSLocalizedString("stats.insights.label.views.sevenDays.same",
113+
value: "Your views in the last 7-days are the same as the previous 7-days.\n",
114+
comment: "Stats insights label shown when the user's view count is the same as the previous 7 days.")
115+
static let visitorsNoDifference = NSLocalizedString("stats.insights.label.visitors.sevenDays.same",
116+
value: "Your visitors in the last 7-days are the same as the previous 7-days.\n",
117+
comment: "Stats insights label shown when the user's visitor count is the same as the previous 7 days.")
106118
}
107119
}

WordPress/Classes/ViewRelated/Stats/Helpers/StatSection.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
.insightsTodaysStats,
4848
.insightsPostingActivity,
4949
.insightsTagsAndCategories,
50+
.insightsFollowersWordPress,
5051
.insightsFollowersEmail,
5152
.insightsPublicize]
5253
} else {

WordPress/Classes/ViewRelated/Stats/Helpers/StatsDataHelper.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ import Foundation
135135
let siteTimeZone = SiteStatsInformation.sharedInstance.siteTimeZone ?? .autoupdatingCurrent
136136
return Date().convert(from: siteTimeZone)
137137
}
138+
139+
class func yesterdayDateForSite() -> Date {
140+
let components = DateComponents(day: -1)
141+
return StatsDataHelper.calendar.date(byAdding: components, to: currentDateForSite()) ?? currentDateForSite()
142+
}
138143
}
139144

140145
fileprivate extension Date {

WordPress/Classes/ViewRelated/Stats/Insights/Insights Management/InsightsManagementViewController.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class InsightsManagementViewController: UITableViewController {
2222
}
2323

2424
private var insightsInactive: [StatSection] {
25-
StatSection.allInsights.filter({ !self.insightsShown.contains($0) })
25+
StatSection.allInsights
26+
.filter({ !self.insightsShown.contains($0) && !InsightsManagementViewController.insightsNotSupportedForManagement.contains($0) })
2627
}
2728

2829
private var hasChanges: Bool {
@@ -55,8 +56,9 @@ class InsightsManagementViewController: UITableViewController {
5556
self.init(style: FeatureFlag.statsNewAppearance.enabled ? .insetGrouped : .grouped)
5657
self.insightsDelegate = insightsDelegate
5758
self.insightsManagementDelegate = insightsManagementDelegate
58-
self.insightsShown = insightsShown
59-
self.originalInsightsShown = insightsShown
59+
let insightsShownSupportedForManagement = insightsShown.filter { !InsightsManagementViewController.insightsNotSupportedForManagement.contains($0) }
60+
self.insightsShown = insightsShownSupportedForManagement
61+
self.originalInsightsShown = insightsShownSupportedForManagement
6062
}
6163

6264
// MARK: - View
@@ -388,6 +390,15 @@ private extension InsightsManagementViewController {
388390
action: nil)
389391
}
390392

393+
/// Insight StatSections who share the same insightType are represented by a single card
394+
/// Only display a single one of them for Insight Management
395+
/// insightsCommentsPosts and insightsCommentsAuthors have the same insightType
396+
/// insightsFollowersEmail and insightsFollowersWordpress have the same insightType
397+
private static let insightsNotSupportedForManagement: [StatSection] = [
398+
.insightsFollowersWordPress,
399+
.insightsCommentsAuthors
400+
]
401+
391402
// MARK: - Insights Categories
392403

393404
enum InsightsCategories {

WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsInsightsViewModel.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ class SiteStatsInsightsViewModel: Observable {
6161
self.periodStore = periodStore
6262
let viewsCount = insightsStore.getAllTimeStats()?.viewsCount ?? 0
6363
self.itemToDisplay = pinnedItemStore?.itemToDisplay(for: viewsCount)
64-
self.lastRequestedDate = StatsDataHelper.currentDateForSite()
64+
65+
// Exclude today's data for weekly insights
66+
self.lastRequestedDate = StatsDataHelper.yesterdayDateForSite()
6567
self.lastRequestedPeriod = StatsPeriodUnit.day
6668

6769
insightsChangeReceipt = self.insightsStore.onChange { [weak self] in

WordPress/Classes/ViewRelated/Stats/Insights/StatsBaseCell.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ class StatsBaseCell: UITableViewCell {
117117
showDetailsButton.isHidden = false
118118

119119
switch statSection {
120-
case .insightsViewsVisitors, .insightsLikesTotals:
120+
case .insightsViewsVisitors:
121121
showDetailsButton.setTitle(LocalizedText.buttonTitleThisWeek, for: .normal)
122-
case .insightsFollowerTotals, .insightsCommentsTotals:
122+
case .insightsFollowerTotals, .insightsCommentsTotals, .insightsLikesTotals:
123123
showDetailsButton.setTitle(LocalizedText.buttonTitleViewMore, for: .normal)
124124
default:
125125
showDetailsButton.setTitle("", for: .normal)

WordPress/Classes/ViewRelated/Stats/Insights/StatsTotalInsightsCell.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,14 @@ class StatsTotalInsightsCell: StatsBaseCell {
376376

377377
private enum TextContent {
378378
static let differenceDelimiter = Character("*")
379-
static let differenceHigher = NSLocalizedString("*%@%@ (%@%%)* higher than the previous week", comment: "Label shown on some metrics in the Stats Insights section, such as Comments count. The placeholders will be populated with a change and a percentage – e.g. '+17 (40%) higher than the previous week'. The *s mark the numerical values, which will be highlighted differently from the rest of the text.")
380-
static let differenceLower = NSLocalizedString("*%@%@ (%@%%)* lower than the previous week", comment: "Label shown on some metrics in the Stats Insights section, such as Comments count. The placeholders will be populated with a change and a percentage – e.g. '-17 (40%) lower than the previous week'. The *s mark the numerical values, which will be highlighted differently from the rest of the text.")
381-
static let differenceSame = NSLocalizedString("The same as the previous week", comment: "Label shown in Stats Insights when a metric is showing the same level as the previous week")
379+
static let differenceHigher = NSLocalizedString("stats.insights.label.totalLikes.higher",
380+
value: "*%@%@ (%@%%)* higher than the previous 7-days",
381+
comment: "Label shown on some metrics in the Stats Insights section, such as Comments count. The placeholders will be populated with a change and a percentage – e.g. '+17 (40%) higher than the previous 7-days'. The *s mark the numerical values, which will be highlighted differently from the rest of the text.")
382+
static let differenceLower = NSLocalizedString("stats.insights.label.totalLikes.higher",
383+
value: "*%@%@ (%@%%)* lower than the previous 7-days",
384+
comment: "Label shown on some metrics in the Stats Insights section, such as Comments count. The placeholders will be populated with a change and a percentage – e.g. '-17 (40%) lower than the previous 7-days'. The *s mark the numerical values, which will be highlighted differently from the rest of the text.")
385+
static let differenceSame = NSLocalizedString("stats.insights.label.totalLikes.same",
386+
value: "The same as the previous 7-days",
387+
comment: "Label shown in Stats Insights when a metric is showing the same level as the previous 7 days")
382388
}
383389
}

WordPress/Classes/ViewRelated/Stats/Insights/ViewsVisitors/ViewsVisitorsLineChartCell.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,6 @@ struct StatsSegmentedControlData {
112112
var accessibilityValue: String? {
113113
return segmentDataStub != nil ? "" : "\(segmentData)"
114114
}
115-
116-
enum Constants {
117-
static let viewsHigher = NSLocalizedString("Your views this week are %@ higher than the previous week.\n", comment: "Stats insights views higher than previous week")
118-
static let viewsLower = NSLocalizedString("Your views this week are %@ lower than the previous week.\n", comment: "Stats insights views lower than previous week")
119-
static let visitorsHigher = NSLocalizedString("Your visitors this week are %@ higher than the previous week.\n", comment: "Stats insights visitors higher than previous week")
120-
static let visitorsLower = NSLocalizedString("Your visitors this week are %@ lower than the previous week.\n", comment: "Stats insights visitors lower than previous week")
121-
}
122115
}
123116

124117

@@ -230,9 +223,9 @@ private extension ViewsVisitorsLineChartCell {
230223
previousData.adjustsFontSizeToFitWidth = true
231224
previousLabel.adjustsFontSizeToFitWidth = true
232225

233-
legendLatestLabel.text = NSLocalizedString("This week", comment: "This week legend label")
226+
legendLatestLabel.text = NSLocalizedString("stats.insights.label.viewsVisitorsLastDays", value: "Last 7-days", comment: "Last 7-days legend label")
234227
legendLatestLabel.adjustsFontSizeToFitWidth = true
235-
legendPreviousLabel.text = NSLocalizedString("Previous week", comment: "Previous week legend label")
228+
legendPreviousLabel.text = NSLocalizedString("stats.insights.label.viewsVisitorsPreviousDays", value: "Previous 7-days", comment: "Previous 7-days legend label")
236229
legendPreviousLabel.adjustsFontSizeToFitWidth = true
237230
}
238231

0 commit comments

Comments
 (0)