Skip to content

UNI-832: Premium Analytics: Open the dashboard from the admin bar and action bar Stats links - #52905

Merged
Nikschavan merged 9 commits into
trunkfrom
uni-832-point-stats-entry-points-to-v2-for-opted-in-sites
Oct 6, 2026
Merged

Nikschavan merged 9 commits into
trunkfrom
uni-832-point-stats-entry-points-to-v2-for-opted-in-sites

Conversation

@Nikschavan

@Nikschavan Nikschavan commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Fixes UNI-832

Proposed changes

  • Sites that turn on Stats v2 still land on classic Stats from most entry points. Premium Analytics: point the post list views column at the post detail page #51357 moved the post list Views column to the post detail page, but the admin bar sparkline, the admin bar "Stats" link, the post stats link in the newsletter action bar, and the My Jetpack redirect on Atomic Personal and Premium plans still open admin.php?page=stats.
  • Each of those links now goes through a new jetpack_stats_url filter, with an array( 'view' => …, 'id' => … ) argument that names the page the link opens rather than the surface it sits on, with the same keys as the JS AnalyticsView in _inc/shared/analytics-url.ts. Stats_Links in Premium Analytics hooks it and maps dashboard to the dashboard root and post to /post/<id>. Any other view, a post view without a post ID, or a user without the view_analytics capability keeps the classic URL.
  • Premium Analytics hooks the filter only while the dashboard is enabled, so turning v2 off sends every link back to classic Stats with no extra check at the call sites. A site that runs an older copy of one of the packages keeps the classic link for that one surface.
  • The action bar in this repository runs only on Simple, and it is the only copy of the bar there since 240435-ghe-Automattic/wpcom removed the mu-plugin one. Its post stats link therefore opens the post detail page on Simple sites with Stats v2 on as soon as this deploys, winning over the Calypso post stats link the same way the post list column does.
  • Post_List_Link keeps its name and public methods and now delegates to Stats_Links, so the post list column behaves as before.
  • The sparkline image itself is still served from page=stats; only the link target changes.
  • The Odyssey config also sends the site's timezone. The WP Admin dashboard widget, which comes from the Odyssey bundle built in Calypso, links into the dashboard on date ranges in UNI-832: Stats: Open Premium Analytics from the WP Admin dashboard widget wp-calypso#114767 and needs the timezone to keep whole days across daylight-saving changes, which gmt_offset alone cannot. It is empty for a site set to a fixed UTC offset.
  • Not included: the admin bar sparkline on Simple sites comes from WordPress.com, so it changes in 245785-ghe-Automattic/wpcom.
Where the links are
Front-end admin bar with the views sparkline and the Stats item in the site-name menu outlined
The views sparkline in the admin bar, and "Stats" in the site-name menu (front end).

Related product discussion/links

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

No.

Testing instructions

Self-hosted and Atomic. Use a Jurassic Ninja site with this branch through the Jetpack Beta Tester plugin, with Jetpack connected and the Stats module active. Turn Stats v2 on with wp option update jetpack_premium_analytics_enabled 1. Keep the standalone Premium Analytics plugin inactive: it turns the dashboard on unconditionally, so the option has no effect while it runs.

  • Enable the admin bar chart in Jetpack › Settings › Traffic › Jetpack Stats if it is off.
  • Open the front end. Click the views sparkline in the admin bar, and confirm it opens the Premium Analytics dashboard (?page=jetpack-premium-analytics-wp-admin).
  • Hover the site name in the admin bar, click "Stats", and confirm it opens the same dashboard.
  • On the posts list, click a post's Views count and confirm it still opens that post's detail page.
  • Run wp option update jetpack_premium_analytics_enabled 0, reload, and confirm all three links open classic Stats (?page=stats) again.
  • On an Atomic site with this branch, logged in as a WordPress.com user, hover the site name in the admin bar and confirm "Stats" opens the dashboard.
  • On an Atomic site on a Personal or Premium plan, open wp-admin/admin.php?page=my-jetpack and confirm it redirects to the dashboard.

Simple. Sandbox a Simple site that has Stats v2 on, through its own opt-in or the jetpack-premium-analytics sticker. Then put this branch's builds on your sandbox by running both of these from the wpcom root: the jetpack build carries Premium Analytics, which hooks the filter, and the jetpack-mu-wpcom-plugin build carries the site-name "Stats" item.

bin/jetpack-downloader test jetpack 52905
bin/jetpack-downloader test jetpack-mu-wpcom-plugin 52905
  • Open the front end, hover the site name in the admin bar, click "Stats", and confirm it opens admin.php?page=jetpack-premium-analytics-wp-admin&p=%2F.
  • Open a published post on the front end and click the Stats button in the action bar. Confirm it opens the dashboard's post detail page (p=%2Fpost%2F<id>).
  • The admin bar sparkline on Simple changes in 245785-ghe-Automattic/wpcom. To see it as well, check out that branch on the sandbox too.
  • When you are done, run bin/jetpack-downloader reset jetpack and bin/jetpack-downloader reset jetpack-mu-wpcom-plugin.

I checked this with PHP unit tests only. I have not clicked through the links on a site with this branch yet, and the WordPress.com site menu only renders on WordPress.com sites. Action_Bar_Test covers the action bar link.

@github-actions

github-actions Bot commented Sep 29, 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 uni-832-point-stats-entry-points-to-v2-for-opted-in-sites branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack uni-832-point-stats-entry-points-to-v2-for-opted-in-sites
bin/jetpack-downloader test jetpack-mu-wpcom-plugin uni-832-point-stats-entry-points-to-v2-for-opted-in-sites

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 commented Sep 29, 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:

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:

  • Next scheduled release: Atomic deploys happen twice daily on weekdays (p9o2xV-2EN-p2)

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

@Nikschavan
Nikschavan force-pushed the uni-832-point-stats-entry-points-to-v2-for-opted-in-sites branch from a2d1c02 to c3030c8 Compare September 30, 2026 07:12
@Nikschavan
Nikschavan requested a balanced review from Copilot September 30, 2026 10:19

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@jp-launch-control

jp-launch-control Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 4 files.

File Coverage Δ% Δ Uncovered
projects/packages/stats-admin/src/class-admin-bar.php 102/115 (88.70%) 0.10% 0 💚
projects/packages/stats-admin/src/class-admin-post-list-column.php 116/136 (85.29%) 0.92% 0 💚
projects/packages/stats-admin/src/class-odyssey-config-data.php 129/131 (98.47%) 0.01% 0 💚
projects/packages/newsletter/src/class-action-bar.php 374/632 (59.18%) 10.70% -63 💚

1 file is newly checked for coverage.

File Coverage
projects/packages/premium-analytics/src/class-stats-links.php 14/14 (100.00%) 💚

Full summary · PHP report · JS report

@Nikschavan
Nikschavan marked this pull request as ready for review October 1, 2026 09:30
@fushar

fushar commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Please check this comment: Automattic/wp-calypso#114763 (review)

chihsuan
chihsuan previously approved these changes Oct 2, 2026

@chihsuan chihsuan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice work moving the Stats links over! @Nikschavan I tested the admin bar links, Views column and the Simple action bar with v2 on, and they work nicely. Approving. 👍

Before this merges, could we add changelog entries to plugins/jetpack and plugins/wpcomsh, since their users see these links change? I also left two inline notes.

Comment thread projects/packages/stats-admin/src/class-admin-bar.php
Comment thread projects/packages/newsletter/src/class-action-bar.php Outdated
@github-actions github-actions Bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Wpcomsh labels Oct 2, 2026
Add a jetpack_stats_url filter to the admin bar Stats links (stats-admin and jetpack-mu-wpcom) and the newsletter action bar post stats link. Premium Analytics hooks it with Stats_Links and maps each view to a dashboard route, so the links fall back to classic Stats when the dashboard is off.
Move the action bar post stats link into Action_Bar::get_post_stats_url() so it can be tested, and give the unknown-view test a post ID so it fails when the post-view check is removed.
Phan rejects @internal on Action_Bar::get_post_stats_url() because its test lives in the Tests namespace. The capability and post ID guards now live in Stats_Links, whose tests already cover them.
Matches the keys of the JS AnalyticsView in _inc/shared/analytics-url.ts, before the filter becomes a public contract.
Personal and Premium plans on Atomic redirect My Jetpack to Stats, so sites with Stats v2 on now land on the dashboard instead.
Links from the Stats widget into the Premium Analytics dashboard encode date ranges with an offset per day; gmt_offset alone cannot follow daylight saving.
…lpers private

Deprecate jetpack_stats_post_list_column_url in favor of jetpack_stats_url, drop Post_List_Link now that Stats_Links claims the column, test the action bar link through the rendered bar, and add Jetpack and wpcomsh changelog entries.
@Nikschavan
Nikschavan force-pushed the uni-832-point-stats-entry-points-to-v2-for-opted-in-sites branch from ed691ea to 540fdd9 Compare October 6, 2026 03:55
@Nikschavan
Nikschavan requested a review from chihsuan October 6, 2026 03:55

@chihsuan chihsuan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, LGTM!

@Nikschavan
Nikschavan merged commit 6f128e2 into trunk Oct 6, 2026
81 checks passed
@Nikschavan
Nikschavan deleted the uni-832-point-stats-entry-points-to-v2-for-opted-in-sites branch October 6, 2026 06:13
@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 Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants