Skip to content

Stats abilities: limit new free sites to the last 30 days behind a start-date switch - #55591

Merged
chubes4 merged 3 commits into
trunkfrom
update/stats-abilities-plan-limits
Nov 30, 2026
Merged

chubes4 merged 3 commits into
trunkfrom
update/stats-abilities-plan-limits

Conversation

@chubes4

@chubes4 chubes4 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Part of the Stats MCP plan limits work (UNI-1081).

Proposed changes

The new pricing gives free sites created after launch the last 30 days of Stats. Existing sites and paid plans keep full history. This adds that rule to the Stats abilities, switched off until a launch day is set.

  • Plan_Window (new, Stats package) decides how many days of Stats a site's plan covers.
    • Free sites created on or after the jetpack_stats_plan_window_start day get 30 days.
    • Every other site keeps full history: sites created earlier, plans with stats-paid or stats-commercial, and sites whose plan data hasn't synced (so a paying site is never limited because data is missing).
    • The filter returns null by default, so nothing changes until a start day is set.
    • The rule lives in the Stats package so the Stats dashboard can read the same value later, without a second date to manage.
  • Creation date: a site's WordPress.com registration date, or Jetpack's assumed creation date on a self-hosted site.
  • Windowed abilities refuse earlier windows. get-visits (comparison window included), get-top-content (dated types), get-post-views, get-author-views, get-video-stats, get-followers (with period) and get-ad-stats refuse a window that starts before the plan's first day. They return jetpack_stats_requires_plan with feature: history and earliest_date.
  • Plan refusals share one code. When WordPress.com refuses a type the plan lacks (regions, cities, browsers, platforms, screen sizes, UTM), get-top-content now returns jetpack_stats_requires_plan naming the type, instead of passing the raw stats_error through.

Not limited here: all-time figures (a post's total views, insights, get-email-stats without a start date, the per-post email detail), and history download, which pricing keeps open on every plan. Questions about these go on UNI-1081.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Linear: UNI-1081, project Jetpack Stats Exit Ramps. Pricing: unifiedanalyticsp2 "New pricing for Jetpack Stats and WooCommerce Stats".

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

No.

Testing instructions

Primary evidence: a sandbox run through the real WordPress.com MCP JSON-RPC (tools/call → execute), with this branch's Stats package patched into jetpack-mu-wpcom-plugin and the filter driven by an environment variable.

Site Switch Request Result
Free Simple site created 2026-11-20 off visits, 31 days data
same 2026-11-01 visits, 30 days data
same 2026-11-01 visits, 31 days This site's plan covers the last 30 days of Stats, from 2026-11-02.
same 2026-11-01 visits, 2 months refused
same 2026-11-01 visits, 7 days compared with previous year refused
same 2026-11-01 top-content posts, 60 days refused
same 2026-11-01 top-content tags (undated) data
same off top-content regions This site's plan does not include regions stats.
en.blog (created years earlier) 2026-11-01 visits, 90 days data
Free Jetpack site created 2026-11-17 2026-11-01 visits, 30 / 31 days data / refused

Cost of Plan_Window::get_days(): about 1 µs per call with the switch off, and about 85 µs with it on (one blog lookup and one feature check).

To try it locally:

  • add_filter( 'jetpack_stats_plan_window_start', fn() => '2026-01-01' ); on a free site created after that day.
  • Call jetpack-stats/get-visits with num: 31. It returns jetpack_stats_requires_plan; with num: 30 it returns data.
  • composer phpunit -- --filter 'plan_window|plan_lacks' in projects/packages/stats. The refused cases fail on trunk.

Written with Claude (Anthropic) via Pi: code, tests and the sandbox verification. Chris Huber directed.

@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!

@github-actions

github-actions Bot commented Nov 30, 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/stats-abilities-plan-limits branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/stats-abilities-plan-limits
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/stats-abilities-plan-limits

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

@jp-launch-control

jp-launch-control Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/stats/src/abilities/class-stats-abilities.php 2713/2737 (99.12%) 0.02% 0 💚

1 file is newly checked for coverage.

File Coverage
projects/packages/stats/src/class-plan-window.php 18/26 (69.23%) 💚

Full summary · PHP report · JS report

@chubes4
chubes4 marked this pull request as ready for review November 30, 2026 16:14
@chubes4
chubes4 requested a review from a team as a code owner November 30, 2026 16:14
…art-date switch

Plan_Window decides the days a site's plan covers: free sites created on or
after the jetpack_stats_plan_window_start day see the last 30 days; older
sites, paid plans and unknown plans keep full history. The filter returns null
by default, so nothing changes until a start day is set.

Windowed abilities refuse a window that starts earlier with
jetpack_stats_requires_plan, and get-top-content returns the same code when
WordPress.com refuses a type the plan lacks.
@chubes4
chubes4 force-pushed the update/stats-abilities-plan-limits branch from 6cc651d to 06a361d Compare November 30, 2026 21:40
@chubes4
chubes4 force-pushed the update/stats-abilities-plan-limits branch from 06a361d to 327af9e Compare November 30, 2026 22:25
@chubes4
chubes4 merged commit 6d8cda0 into trunk Nov 30, 2026
99 checks passed
@chubes4
chubes4 deleted the update/stats-abilities-plan-limits branch November 30, 2026 22:38
@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 Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Stats Data [Package] Stats [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.

1 participant