Skip to content

Premium Analytics: build the comparison menu from the applied date range - #51779

Merged
retrofox merged 6 commits into
trunkfrom
update/comparison-options-from-range
Sep 1, 2026
Merged

retrofox merged 6 commits into
trunkfrom
update/comparison-options-from-range

Conversation

@retrofox

@retrofox retrofox commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Proposed changes

The Compare menu was a fixed list of three presets. It is now derived from the applied range, so presets, custom ranges, and stepped or drilled windows all resolve through the same rules.

Let n be the range's length.

Option Offered when Label
Previous period always named by the range's own length: "Previous day", "Previous 7 days", "Previous month"
Same period from last week n ≤ 7 days —
Same period in {month} n ≤ 28 days names the month it lands in
Same period in {year} n < 365 days names the year it lands in
No comparison always now last in the menu

Three rules on top:

  • An option resolving to the same window as an earlier one is dropped. A 7-day range lists no last-week entry; Last 12 months lists only "Previous 12 months".
  • A whole-month window steps back by months, not days. Last year compares against calendar 2024, not a Jan 2 – Dec 31 window.
  • When a range change drops the active preset, the comparison falls back to the previous period instead of leaving the URL naming something the menu cannot.

Also here: previous-week is restored, so links saved before #51094 work again.

The trigger face is untouched. The vs prefix and the exact-dates tooltip are in #51820.

Related product discussion/links

Does this pull request change what data or activity we track or use?

No.

Testing instructions

Build: jetpack build --deps packages/premium-analytics.

Open the Compare menu under each range and check what it offers:

Range Expected menu
Today / Yesterday Previous day · last week · {month} · {year}
Last 24 hours Previous 24 hours · last week · {month} · {year}
Last 7 days Previous 7 days · {month} · {year}
Last 30 / 90 days Previous 30/90 days · {year}
Last month Previous month · {year}
Last 12 months Previous 12 months, alone
Custom, drawn in 2025 follows the length, and names 2024

"No comparison" sits last in every one of them.

Then:

  • On Last month, pick "Previous month". It compares against the previous calendar month.
  • On Last 7 days, pick "Same period in {month}", then switch to Last 30 days. The comparison stays active and becomes "Prev. period".
  • Open a link carrying comp=1, compare_preset=previous-week and the compare dates. The week-shifted comparison renders.

One known gap, flagged by @kangzj: a link carrying compare_preset with no compare dates names the trigger but compares nothing. It predates this PR and is not specific to previous-week. #51820 fixes it.

Screen.Recording.2026-09-01.at.1.30.14.PM.mov

previous-week returns; whole-months previous period steps by month count
labels come from getComparisonOptions; No comparison moves last
derive resolves the preset too and patches stage it
@retrofox
retrofox requested a review from a team as a code owner August 31, 2026 16:05
@retrofox retrofox added Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Needs Review This PR is ready for review. labels Aug 31, 2026
@retrofox retrofox self-assigned this Aug 31, 2026
@github-actions

github-actions Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the update/comparison-options-from-range branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/comparison-options-from-range
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/comparison-options-from-range

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions Bot added [Package] Premium Analytics [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Premium Analytics Docs labels Aug 31, 2026
@github-actions

github-actions Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: September 7, 2026

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Premium Analytics plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@jp-launch-control

jp-launch-control Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 6 files. Only the first 5 are listed here.

File Coverage Δ% Δ Uncovered
projects/packages/premium-analytics/packages/fields/src/report-params-field/report-params-field.tsx 55/58 (94.83%) -1.66% 1 ❤️‍🩹
projects/packages/premium-analytics/packages/datetime/src/get-comparison-range.ts 49/51 (96.08%) 1.96% 0 💚
projects/packages/premium-analytics/packages/routing/src/hooks/use-report-date-filters/build-range-patch.ts 16/16 (100.00%) 0.00% 0 💚
projects/packages/premium-analytics/packages/datetime/src/presets/comparison.ts 58/59 (98.31%) 18.31% -1 💚
projects/packages/premium-analytics/packages/ui/src/use-comparison-date-presets/use-comparison-date-presets.ts 1/1 (100.00%) 14.29% -1 💚

Full summary · PHP report · JS report

kangzj
kangzj previously approved these changes Sep 1, 2026

@kangzj kangzj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving 👍 The menu follows the applied range everywhere I poked at it, the whole-month stepping lands on real calendar months, and the restored previous-week works both from the menu and from a saved link.

Blockers: none.

One note that had nowhere to sit on a line - a URL carrying comp=1&compare_preset=previous-week but no compare_from/compare_to names the trigger "Prev. week" and then renders no comparison at all, because nothing re-derives on mount. Every link the app writes carries the compare dates so in practice it's fine, and it's pre-existing and not specific to previous-week, but the deep-link bullet in the testing instructions reads a bit stronger than what actually happens. Just flagging it, not asking for anything.

Testing performed

On my local docker env (Premium Analytics dashboard in wp-admin, built from this branch), plus the package's own jest and typecheck:

# What I checked What I saw Status
1 Last 30 days menu Previous 30 days · Same period in 2025 · No comparison ✅
2 Last 7 days menu Previous 7 days · Same period in July · Same period in 2025, no last-week entry ✅
3 Last 24 hours menu Previous 24 hours · Same period from last week · Same period in July · Same period in 2025 ✅
4 12 months menu only Previous 12 months, and the window steps back 12 calendar months ✅
5 Single day (custom Aug 30) Previous day · last week · July · 2025 ✅
6 Custom 57-day range drawn in 2025 "Previous 57 days" and "Same period in 2024" ✅
7 Whole month Jul 1-31, pick Previous month compares Jun 1-30, the previous calendar month ✅
8 Calendar year 2025, pick Previous 12 months compares Jan 1 - Dec 31 2024, not a Jan 2 window ✅
9 28 vs 29 day boundary month shift offered at 28 days, gone at 29 ✅
10 "Same period in July" on 7 days, then switch to 30 days trigger becomes "Prev. period" and compare_preset=previous-period ✅
11 Step back from calendar 2025 with the arrow range 2024, comparison calendar 2023, preset kept ✅
12 Deep link with compare_preset=previous-week + compare dates trigger reads "Prev. week", comparison renders ✅
13 Pick "Same period from last week" on a single day writes previous-week and the Aug 23 window ✅
14 Custom range Aug 1-5 drawn in the calendar compares Jul 27-31, menu follows the 5-day length ✅
15 "No comparison" sits last, and clears comp/compare_* from the URL ✅
16 jest for packages/premium-analytics 19 suites / 280 tests pass; datetime + date-filter suites also green under UTC, America/Los_Angeles, Asia/Tokyo and Pacific/Auckland ✅
17 tsgo --noEmit and eslint on the changed files clean ✅
18 The report-params-field staging of compare_preset couldn't reach it - no widget on the dashboard exposes a per-widget date control, so only its unit tests cover that path ⚠️
19 Deep link with compare_preset but no compare dates trigger names the preset, widgets show no comparison (pre-existing, same for every preset) ⚠️

Evidence

Compare menu on Last 24 hours, merge-base build vs this branch:

Compare menu before and after

Nice work on this one, the labels naming the target rather than the offset makes it a lot easier to read. Thanks!

const years = wholeMonths / MONTHS_PER_YEAR;
return sprintf(
/* translators: %d: number of years covered by the selected date range. */
_n( 'Previous %d year', 'Previous %d years', years, 'jetpack-premium-analytics-pkg' ),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks like the one branch of the label helper that isn't covered - a two-year custom range hits Previous %d years, and an hour-sized window hits the singular Previous hour just below. Both are reachable I think, so maybe worth a couple more rows in comparison-presets.test.ts? Not blocking.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Both reachable indeed — added two rows in 929df70: a two-year custom range hitting "Previous 2 years" and a drilled single hour hitting "Previous hour". Thanks for the thorough matrix!

@retrofox
retrofox merged commit 2cc6198 into trunk Sep 1, 2026
83 checks passed
@retrofox
retrofox deleted the update/comparison-options-from-range branch September 1, 2026 12:33
@github-actions github-actions Bot added [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. and removed [Status] Needs Review This PR is ready for review. labels Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Docs Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Package] Premium Analytics [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Premium Analytics [Status] UI Changes Add this to PRs that change the UI so documentation can be updated.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants