Repository navigation
WOOA7S-1769: Premium Analytics: Add a Settings tab to the dashboard - #53357
Nikschavan wants to merge 7 commits into
Conversation
|
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! Jetpack 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. Wpcomsh plugin:
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. |
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Code Coverage SummaryCoverage changed in 6 files. Only the first 5 are listed here.
8 files are newly checked for coverage. Only the first 5 are listed here.
|
There was a problem hiding this comment.
🟡 Changes recommended
Save rollback, Reader write failure reporting, and unavailable navigation destinations need correction.
4 open findings
What changed in this PR
Adds a Settings tab to Premium Analytics, bringing Stats configuration and plan usage into the new dashboard.
Changes:
- Adds an admin-only Settings tab with role selectors, automatic saving, and plan usage.
- Registers settings through WordPress’s settings API and shares usage helpers.
- Updates navigation, tests, documentation, and changelogs.
| File | Description |
|---|---|
| projects/plugins/wpcomsh/changelog/wooa7s-1769-stats-settings-tab | Records the Atomic-facing change. |
| projects/plugins/premium-analytics/changelog/wooa7s-1769-stats-settings-tab | Records the standalone plugin change. |
| projects/plugins/jetpack/changelog/wooa7s-1769-stats-settings-tab | Records the Jetpack-facing change. |
| projects/plugins/jetpack/_inc/shared/analytics-url.ts | Supports Settings URLs. |
| projects/plugins/jetpack/_inc/client/traffic/test/site-stats.test.jsx | Tests the updated Settings link. |
| projects/plugins/jetpack/_inc/client/traffic/site-stats.jsx | Links to the new Settings tab. |
| projects/packages/premium-analytics/widgets/plan-usage/render.tsx | Reuses shared usage helpers. |
| projects/packages/premium-analytics/tests/php/Stats_Settings_Test.php | Tests settings persistence and script data. |
| projects/packages/premium-analytics/tests/php/Dashboard_Section_Test.php | Tests the reserved Settings slug. |
| projects/packages/premium-analytics/src/widget-type-support.php | Updates the usage-placement comment. |
| projects/packages/premium-analytics/src/class-stats-settings.php | Registers settings and role context. |
| projects/packages/premium-analytics/src/class-dashboard-section-registry.php | Reserves the Settings slug. |
| projects/packages/premium-analytics/src/class-analytics.php | Initializes settings integration. |
| projects/packages/premium-analytics/routes/dashboard/stage.tsx | Integrates Settings and customization guards. |
| projects/packages/premium-analytics/routes/dashboard/stage.test.tsx | Tests Settings customization restrictions. |
| projects/packages/premium-analytics/routes/dashboard/package.json | Adds the formatters dependency. |
| projects/packages/premium-analytics/routes/dashboard/hooks/use-active-section/use-active-section.ts | Accepts stage-owned tabs. |
| projects/packages/premium-analytics/routes/dashboard/hooks/use-active-section/use-active-section.test.ts | Tests Settings URL preservation. |
| projects/packages/premium-analytics/routes/dashboard/config/sections.ts | Defines and resolves Settings. |
| projects/packages/premium-analytics/routes/dashboard/config/index.ts | Exports the Settings constant. |
| projects/packages/premium-analytics/routes/dashboard/components/stats-settings/stats-settings.tsx | Renders settings cards and save notices. |
| projects/packages/premium-analytics/routes/dashboard/components/stats-settings/stats-settings.test.tsx | Tests errors and Activation visibility. |
| projects/packages/premium-analytics/routes/dashboard/components/stats-settings/stats-settings.module.scss | Styles settings and usage cards. |
| projects/packages/premium-analytics/routes/dashboard/components/stats-settings/stats-settings-fields.tsx | Defines editable settings fields. |
| projects/packages/premium-analytics/routes/dashboard/components/stats-settings/stats-settings-fields.test.ts | Tests role-field behavior. |
| projects/packages/premium-analytics/routes/dashboard/components/stats-settings/plan-usage-card.tsx | Displays usage and Upgrade. |
| projects/packages/premium-analytics/routes/dashboard/components/stats-settings/plan-usage-card.test.tsx | Tests usage states and links. |
| projects/packages/premium-analytics/routes/dashboard/components/stats-settings/chip-select-edit.tsx | Adds the role-chip editor. |
| projects/packages/premium-analytics/routes/dashboard/components/stats-settings/chip-select-edit.test.tsx | Tests retired-role preservation. |
| projects/packages/premium-analytics/routes/dashboard/components/index.ts | Exports the Settings panel. |
| projects/packages/premium-analytics/routes/dashboard/components/dashboard-sections/dashboard-sections.tsx | Appends Settings as the last tab. |
| projects/packages/premium-analytics/packages/widgets-toolkit/src/index.ts | Exports shared usage utilities. |
| projects/packages/premium-analytics/packages/widgets-toolkit/src/hooks/use-plan-usage.ts | Shares plan-usage state. |
| projects/packages/premium-analytics/packages/widgets-toolkit/src/hooks/index.ts | Exports the usage hook. |
| projects/packages/premium-analytics/packages/widgets-toolkit/src/helpers/plan-usage.ts | Shares warnings and purchase URLs. |
| projects/packages/premium-analytics/packages/widgets-toolkit/src/helpers/index.ts | Exports usage helpers. |
| projects/packages/premium-analytics/packages/ui/src/section-tabs/section-tabs.tsx | Supports disabled tabs. |
| projects/packages/premium-analytics/packages/site-sync/src/jetpack-script-data.d.ts | Types settings script data. |
| projects/packages/premium-analytics/packages/externals/src/index.ts | Exports required UI components. |
| projects/packages/premium-analytics/packages/data/src/hooks/use-stats-settings.ts | Implements automatic saves and rollback. |
| projects/packages/premium-analytics/packages/data/src/hooks/index.ts | Exports the settings hook. |
| projects/packages/premium-analytics/packages/data/src/hooks/__tests__/use-stats-settings.test.ts | Tests save-failure rollback. |
| projects/packages/premium-analytics/docs/dashboard-sections.md | Documents the reserved slug. |
| projects/packages/premium-analytics/changelog/wooa7s-1769-stats-settings-tab | Records the package change. |
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
ee4a4b2 to
e0bc2f5
Compare
The tab shows the plan usage and edits the Stats settings (admin bar chart, who can view stats, which logged-in views count, Reader view counts) through core's wp/v2/settings route. Jetpack's Traffic settings link to it.
Cover each save rollback guard on its own, make the Settings tab stage tests set up their own section, and drop two PHP tests that only repeat the Stats package's behaviour.
Test the card's rules (meter capped at the limit, Upgrade link, over-limit warnings, VIP sites, no-limit state, Retry) and the panel's (the site's reason on a refused save, the load error, the Activation card only with a Features screen).
Roll back only the settings a failed save still owns, check that the Reader setting was stored, and link to Jetpack features only when My Jetpack's screen is registered.
e0bc2f5 to
5014c7e
Compare


Part of WOOA7S-1769
Fixes STATS-511
Fixes WOOA7S-2037
Proposed changes
Site owners on the new Stats dashboard had nowhere to change the Stats settings or see how much of their plan they had used: both still lived only in the old Odyssey Stats screen. The team decided to put them in one Settings tab at the end of the dashboard, hardcoded in the dashboard stage rather than registered through the sections filter, so another plugin's section cannot push it out of last place. This replaces #52870, #52904 and #52906, which built the same surface as a drawer, a widget and a menu.
?section=settings, it is disabled while the layout is being customized (a layout is arranged on a widget section), and Customize is not offered on it, soWidgetDashboarddoes not open edit mode over an empty first section behind it. Thesettingsslug is now reserved in the section registry, so a registered section cannot take the same URL.widgets-toolkitso the widget and the card share them.DataFormin card layout: the admin bar chart, who can view stats, which logged-in roles count, and whether the WordPress.com Reader shows view counts. The two role fields useSearchableChipSelectControlfrom@wordpress/uithrough a small DataFormEdit, because DataForm's ownarraycontrol still renders the legacy token field. Administrator is not offered as a chip: the Stats package always keeps it, and the help text says so. A saved role that the site no longer lists, for example one from a deactivated plugin, stays as a chip, so editing another role does not drop it.wp/v2/settingsroute and theroot/siteentity.stats_optionsandwpcom_reader_views_enabledare registered there and written through the existingStats\Settingswriter, which keeps the option's internal state. A write the writer refuses now answers with an error, because core ignores errors fromrest_pre_update_setting. When a save fails, only the settings that change touched go back to their stored values, so a later change that already saved is kept.count_users()is slow there. Nothing is registered on WordPress.com Simple, where WordPress.com owns these settings.Follow-ups, not in this PR:
ProgressBarfrom@wordpress/components.@wordpress/ui0.24.0 (Update wordpress monorepo #53004) addsMeter, which matches a measured quantity against a limit better thanProgress, and I will switch to it once that update lands.Tabs, as before this PR. Moving them to thePagecomponent'snavigationprop is tracked separately.arraycontrols still render@wordpress/components. I want to raise both upstream.Related product discussion/links
Does this pull request change what data or activity we track or use?
Yes. It adds two Tracks events.
jetpack_premium_analytics_settings_changedrecords each changed setting, withsetting,enabledand, for the role fields, theroleadded or removed, in the same shape as Odyssey Stats'jetpack_odyssey_stats_settings_changed.jetpack_premium_analytics_plan_upgrade_clickrecords a click on the plan usage card's upgrade link.Testing instructions
Use a Jurassic Ninja site, or any self-hosted site, with Jetpack and Premium Analytics from this branch (Jetpack Beta Tester pointed at
wooa7s-1769-stats-settings-tab-chips), connected, with Stats on. Log in as an administrator and add a user with the Editor role.section=settings.I checked saving, the role chips, the disabled tab and the Features link on my local Docker site. I did not test on WordPress.com Atomic or on a site over its plan limit.