Skip to content

Premium Analytics: gate the Subscribers section on the subscriptions module - #51242

Merged
chihsuan merged 3 commits into
trunkfrom
change/wooa7s-1726-subscribers-gate
Aug 14, 2026
Merged

chihsuan merged 3 commits into
trunkfrom
change/wooa7s-1726-subscribers-gate

Conversation

@chihsuan

@chihsuan chihsuan commented Aug 13, 2026 •

Copy link
Copy Markdown
Member

Proposed changes

  • Hide the Subscribers section in Premium Analytics when the Jetpack Subscriptions module is inactive.
  • Apply the same availability check to the Subscribers default-layout endpoint, so direct access does not return a layout for a hidden section.
  • Keep the section available on WordPress.com Simple and sites without the Jetpack plugin, matching the existing behavior.
  • Keep subscriber widgets registered because they can still load data without the module, and removing them would break widgets already placed in other sections.

Related product discussion/links

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

No.

Testing instructions

Premium Analytics has to be switched on for the dashboard to exist: wp option update jetpack_premium_analytics_enabled 1. Then, on a Jetpack-connected site running this branch:

  • Open Stats v2 in the admin menu and confirm the Subscribers tab is present.
  • Deactivate the Subscriptions module (Jetpack → Settings → Discussion, or wp jetpack module deactivate subscriptions).
  • Reload: the Subscribers tab is gone and the view falls back to Traffic.
  • GET /wp-json/wpcom/v2/dashboards/jetpack-premium-analytics_dashboard/sections no longer lists subscribers.
  • GET /wp-json/wpcom/v2/dashboards/subscribers/default-layout now 404s. On trunk it still returns the full subscriber layout — that is the second gate in this PR.
  • Visiting ?section=subscribers directly rewrites the URL to section=traffic and lands on Traffic rather than an empty tab.
  • Reactivate the module and confirm the tab comes back.
  • Optional: add_filter( 'jetpack_premium_analytics_subscribers_dashboard_section_available', '__return_false' ) hides the tab with the module still on.
  • Expected, not a bug: the subscriber widgets stay in the Customize picker with the module off, and still load data if added.

Verified on a Jurassic Ninja site running this branch, toggling the module both ways.

…module

Replicates the Calypso Stats tab check for Jetpack sites: the section is
registered as always, but only offered when the module is active.
@github-actions

github-actions Bot commented Aug 13, 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 change/wooa7s-1726-subscribers-gate branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack change/wooa7s-1726-subscribers-gate
bin/jetpack-downloader test jetpack-mu-wpcom-plugin change/wooa7s-1726-subscribers-gate

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

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!

@jp-launch-control

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

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 2 files.

File Coverage Δ% Δ Uncovered
projects/packages/premium-analytics/src/dashboard-layout.php 397/401 (99.00%) 0.01% 0 💚
projects/packages/premium-analytics/src/dashboard-sections.php 181/187 (96.79%) 0.05% 0 💚

Full summary · PHP report · JS report

… default-layout route

Modules::is_active() intersects `jetpack_active_modules` with the modules
available to the site, and without the Jetpack plugin that list is only what
standalone plugins register -- nothing registers `subscriptions`. The gate
could therefore never open on the standalone plugin, hiding a tab whose data
comes from the WPCOM proxy and works with the module off. Sites with no module
system to consult are now exempt rather than refused.

Also:

- Resolve availability through a filter, matching the sibling WooCommerce gate.
- Gate /dashboards/{name}/default-layout on a tab map rather than a hardcoded
  Store check, so it stops serving a layout the sections route no longer lists.
- Record why the subscriber widget types are deliberately left registered.
@chihsuan
chihsuan marked this pull request as ready for review August 13, 2026 09:02
@chihsuan
chihsuan requested a review from a team as a code owner August 13, 2026 09:02
@chihsuan chihsuan added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Aug 13, 2026

@layoutd layoutd 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.

🚀 LGTM! Tested locally and confirmed the module gating works as expected, including the default-layout 404 and subscribers being removed from the sections response.

Image Image

@chihsuan
chihsuan merged commit 001751c into trunk Aug 14, 2026
85 checks passed
@chihsuan
chihsuan deleted the change/wooa7s-1726-subscribers-gate branch August 14, 2026 07:02
@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. [Status] In Progress labels Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Premium Analytics [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants