STATS-505: Premium Analytics: Show day totals for Visitors, Likes, and Comments on the hourly Traffic summary - #52858
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 2 files.
|
e22f4c2 to
9595504
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
One or more issues must be addressed before approval.
Review effort: Lite
Findings: 1
Open (3)
What changed in this PR
Updates the Premium Analytics Traffic summary to show daily Visitors, Likes, and Comments totals when displaying hourly charts.
Changes:
- Adds daily totals requests for whole-day hourly ranges.
- Supports card-only values with unavailable chart series.
- Expands widget/toolkit tests and documentation.
| File | Description |
|---|---|
| projects/packages/premium-analytics/widgets/traffic-chart/use-traffic-chart.ts | Updated as part of this pull request. |
| projects/packages/premium-analytics/widgets/traffic-chart/stories/traffic-chart-widget.stories.tsx | Updated as part of this pull request. |
| projects/packages/premium-analytics/widgets/traffic-chart/render.tsx | Updated as part of this pull request. |
| projects/packages/premium-analytics/widgets/traffic-chart/__tests__/use-traffic-chart.test.tsx | Updated as part of this pull request. |
| projects/packages/premium-analytics/packages/widgets-toolkit/src/components/metric-tabs-chart/metric-tabs-chart.tsx | Updated as part of this pull request. |
| projects/packages/premium-analytics/packages/widgets-toolkit/src/components/metric-tabs-chart/__tests__/metric-tabs-chart.test.tsx | Updated as part of this pull request. |
| projects/packages/premium-analytics/changelog/stats-505-daily-visitors-hourly | Updated as part of this pull request. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
At the hourly grain stats/visits fills only views, so the Visitors, Likes and Comments cards showed a dash. For ranges covering whole days, fetch those metrics in daily buckets for the card totals, as Calypso does, and keep their chart marked unavailable.
getDateRangeSpan() reports a partial-day range longer than 48 hours as days, so a URL range such as 13:00 to 12:59 three days later fetched daily totals for four whole calendar days.
The daily request only fills the Visitors, Likes and Comments cards at the hourly grain, so its failure now drops those tabs back to unavailable instead of replacing the whole summary, including the Views chart that loaded, with the error state.
The package requires fake timers for tests that wait on React Query, so a stalled CI runner cannot push an update past the waitFor deadline.
b487dbb to
9f0d48d
Compare
louwie17
left a comment
There was a problem hiding this comment.
Thanks @Nikschavan, this tested well and the code looks good! I tested it on a local Docker site with Today, Yesterday, a single custom day, a 3-day custom range on hourly, and Last 24 hours. The Visitors, Comments and Likes cards matched the daily stats/visits totals, and comparison showed the right change against the previous day.
LGTM 🚀



Fixes STATS-505
Proposed changes
stats/visitsfills onlyviewsatunit=hour, so the widget marked the other three metrics unavailable and had no total to show. Classic Stats has the same hourly limit, but its cards read a separateunit=dayrequest for those three fields (Stats: Add/day data for hourly view tabs wp-calypso#96656).stats/visitsrequest now asks forvisitors,likes,commentsin daily buckets, and the cards show those totals with the change against the comparison period. The chart for those three metrics still says "Hourly data isn't available for this metric.", and Views does not change.MetricTabgets aseriesUnavailablefield for this case: the card shows its value and the chart shows the reason.unavailablestill hides both, which is what WordAds CPM uses.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
Get the branch onto a site with some traffic today or yesterday: a Jurassic Ninja site with the Jetpack Beta Tester plugin pointed at this branch, or a Jurassic Ninja site with the branch synced.
I checked it on my local site on "Today": the cards match classic Stats (764 views, 18 visitors). I did not check comparison or "Last 24 hours" in the browser.