Repository navigation
Premium Analytics: Decide which sites and users see the Upgrade to Parse.ly prompts - #55232
adamwoodnz merged 23 commits into
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
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: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 2 files.
2 files are newly checked for coverage.
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Review cycle summaryThree AI review rounds plus a final pass. Everything below is addressed or answered.
Suite: 917 tests pass. Every required check is green on the last commit, static analysis included. |
chihsuan
left a comment
There was a problem hiding this comment.
Nice work! @adamwoodnz left a few notes inline, the main one is about which views figure the threshold reads.
nit: Could we document offers_parsely_prompts and its filter in docs/dashboard-widgets.md, next to plan_gates?
| * Not `current_usage.views_count`, which counts the open billing period so far: a site that | ||
| * reliably clears the threshold would qualify late each month and lose it at every reset. | ||
| */ | ||
| $views = $usage['billable_monthly_views'] ?? null; |
There was a problem hiding this comment.
Could we take the min of recent_usages[].views_count here instead? I noticed billable_monthly_views also subtracts the views the plan already includes, so a Complete site with a steady 150k views a month reports 50k and never qualifies. Worth confirming with Bob, but I read "views a month" in STATS-645 as raw traffic.
There was a problem hiding this comment.
You were right, and it is worse than a near-the-line disagreement. Fixed in 29b95d6.
I checked the endpoint rather than guessing. billable_monthly_views is built like this:
$billable_monthly_views = min( $recent_view_counts );
$final_billable_monthly_views = max( $billable_monthly_views - $purchased_plan_quantity_limit, 0 );So it is the lowest of the last three months less the views the site's plan already paid for, floored at zero. The figure falls as a site buys more, and a site provisioned for its own traffic reports 0. Since the gate also requires a paid Stats plan, the two conditions were fighting: a commercial site at 150,000 views a month that had bought for 150,000 reported nothing and would never have seen a prompt. Only sites well over what they had paid for would have qualified.
Your suggestion is also exactly the pre-subtraction figure, so the gate now takes the lowest of the recent whole months from recent_usages. It skips the month in progress, since its part month is what the lowest of the set would otherwise read as a slump, which was my reason for avoiding current_usage.views_count in the first place. A site with no whole month on record does not qualify.
No need to put the metric to Bob now: raw traffic and the issue's "views a month" agree here, and the field that disagreed was the one I had picked. Two tests cover what the fixture's equal months cannot, that the quietest month decides rather than the busiest, and that a site with no whole month on record is refused rather than crashing on min() of nothing.
One thing I did not touch: withoutLowerTiers() in packages/data/src/processing/stats/upgrade-tiers.ts also treats billable_monthly_views as a traffic figure, as a floor against tier limits. If the reading above is right that looks wrong too, but it is shipped code outside this PR, so I have left it alone rather than changing upgrade pricing here. Worth its own issue.
| * @return bool | ||
| */ | ||
| function has_parsely_integration() { | ||
| if ( class_exists( 'Parsely\Parsely' ) ) { |
There was a problem hiding this comment.
Would it be better to check the Site ID here instead of class_exists()? When I activated wp-parsely without a Site ID, the prompt was hidden, but that site is probably the most interested non-customer. STATS-645 also describes the signal as the plugin with a Site ID.
$parsely = $GLOBALS['parsely'] ?? null;
if ( is_object( $parsely ) && method_exists( $parsely, 'site_id_is_set' ) ) {
return $parsely->site_id_is_set();
}There was a problem hiding this comment.
Fixed in f405f11. The plugin now answers for itself through site_id_is_set() where it can, and the parsely option is the fallback for an older plugin or a deactivated one that left its Site ID behind. A site running wp-parsely with no Site ID set now sees the prompt.
| return null; | ||
| } | ||
|
|
||
| $usage = $stats->get_stats_usage(); |
There was a problem hiding this comment.
WPCOM_Statsgives a call site no way to lower its 20 second timeout
Would it be worth adding that to get_stats_usage(), so this call can use 5s like the package's other pre-render requests (Plans::get_plan(), Current_Plan::refresh_from_wpcom())? Otherwise, when WordPress.com is slow, a qualifying site's admin could wait up to 20s on the dashboard about once an hour.
There was a problem hiding this comment.
Agreed, and done: get_stats_usage() takes request arguments in 7602988, and this call asks for 5 seconds in cee06de.
fetch_remote_stats() hardcoded 20 for every request, so the only way to lower it was from inside the stats package. It now merges the caller's arguments over a REQUEST_TIMEOUT default that is still 20, matching how Plans::get_plan() and Current_Plan::refresh_from_wpcom() already take theirs. The arguments stay out of the response cache key, so two callers asking for different timeouts still share one answer.
Your numbers were right on the exposure: a failed answer is held for an hour, so a qualifying site's admin would have waited up to 20 seconds for the dashboard about hourly while WordPress.com was slow. A test now asserts the request goes out with 5.
An older copy of jetpack-stats loaded by another plugin ignores the extra argument and keeps its 20 seconds, which is the same copy the existing method_exists() guard above it is there for.
| self::FLAG, | ||
| array( | ||
| 'default' => false, | ||
| 'description' => 'Show the Upgrade to Parsely prompts to sites that qualify: a paid Stats plan, 100,000 monthly views, and no Parsely of their own.', |
There was a problem hiding this comment.
nit: Would it be worth keeping the threshold and tiers out of this description? It copies PARSELY_PROMPTS_VIEWS_THRESHOLD, so it drifts when that changes, and "a paid Stats plan" is wider than commercial and paid.
There was a problem hiding this comment.
Fixed in e62cc3b. The description now points at offers_parsely_prompts() rather than restating the threshold and the tiers.
|
I think for the sake of the infrastructure, any code belonging to Parsely WordPress plugin should be defined within the Parse plugin. |
Or eventually in a different place 😅. It seems that we want to prompt the users to install the plugin. |
dognose24
left a comment
There was a problem hiding this comment.
Nice work, the ordering and the caching read clearly, and the tests pin both down. PHPUnit and Phan pass locally on this head.
Nothing blocking from me. I left three notes inline, mostly about scope. I agree with @chihsuan's notes too, the views figure being the main one.
I'm building the Traffic card on top of this in #55251, and offers_parsely_prompts in the script data is all it needs.
| * | ||
| * @var string[] | ||
| */ | ||
| const PARSELY_PROMPTS_TIERS = array( STATS_TIER_COMMERCIAL, STATS_TIER_PAID ); |
There was a problem hiding this comment.
Is it intended that VIP sites qualify? They resolve to commercial, so a VIP site with enough views and no Parsely detected gets the prompt. VIP customers usually get Parsely through their contract, so the self-serve offer may not fit them. Worth confirming with Laura. If they should be left out, ! $host->is_vip_site() next to the Simple check would do it.
There was a problem hiding this comment.
Intended, and already settled on the issue. STATS-645's notes say VIP sites are not excluded, that an existing Parse.ly customer is the only skip, and that no separate VIP rule is needed because get_stats_plan_tier() returns commercial for them. Laura wrote those notes, so the confirmation you were after is there.
The issue also explains where the other expectation comes from: it calls out that the mock's "not VIP" annotation is stale and that the issue is the current rule. So the design did exclude VIP at one point, and the rule no longer does.
Your reasoning does sharpen something, though this part is my inference rather than anything the issue says. If VIP customers usually get Parse.ly through their contract, they are the population most likely to be existing customers this gate cannot see, since detection rests on wp-parsely holding a Site ID. That points at STATS-645's open question about customers without the plugin rather than at a VIP rule: a VIP site with genuinely no Parse.ly is one the offer suits.
Leaving the code as it is.
| && current_user_can( 'manage_options' ) | ||
| // WordPress.com Simple cannot complete the one-step Parsely setup yet. | ||
| && ! ( new Host() )->is_wpcom_simple() | ||
| && in_array( get_stats_plan_tier(), PARSELY_PROMPTS_TIERS, true ) |
There was a problem hiding this comment.
nit: STATS_TIER_PAID only ever comes from WordPress.com. On a self-hosted site get_jetpack_stats_plan_tier() returns commercial, jetpack-free or unknown, so a paid PWYW site counts as jetpack-free and never qualifies. That is probably right for a site at 100,000 views, but STATS-645 says "a paid Stats plan", so it may be worth a line in the description.
There was a problem hiding this comment.
Added to the tiers docblock in f405f11: paid only ever comes from WordPress.com, so a self-hosted PWYW purchase reads jetpack-free and does not qualify however much it pays.
| * | ||
| * @param bool $offers Whether every condition passed. | ||
| */ | ||
| return (bool) apply_filters( OFFERS_PARSELY_PROMPTS_FILTER, $offers ); |
There was a problem hiding this comment.
nit: this filter also overrides the flag, since it runs after every condition. That is handy for testing the prompts, but Parsely_Prompts::is_enabled() says every other condition sits behind the flag. Could the docblock here say that returning true shows the prompts with the flag off as well?
There was a problem hiding this comment.
Added to the filter docblock in f405f11: it runs after every condition, the feature flag included, so returning true shows the prompts with the flag off.
e62cc3b to
5dbb2a8
Compare
|
On the review's own nit, documenting Both inline notes are addressed, and the views one turned out to be a real bug rather than a near-the-line disagreement. Details are on each thread; in short, |
The three Upgrade to Parsely prompts each need the same answer about whether this site and this user should see them. A copy of the rule per surface would drift, so they share one check. A feature flag, off by default, holds it closed. That lets the prompt surfaces be built and reviewed against the real check before anyone sees them, and keeps the launch decision separate from the rule itself. The conditions run cheapest first. Only the monthly views figure costs a request to WordPress.com, so a site that fails any other condition never makes one.
All three prompt surfaces live in the dashboard SPA, so the answer has to reach the client. Publishing one boolean in script data keeps the rule on the server, where the plan tier and the views figure already are, and leaves the surfaces nothing to decide. The key is injected only on the dashboard. Script data prints on every Jetpack admin page, and the gate costs a WordPress.com request on a site that passes the cheaper conditions.
The stats client gives the call site no way to lower its 20 second timeout, so a WordPress.com slowdown blocked an admin page render for that long, once every five minutes on a qualifying site. Worse, the client deliberately does not cache a connection failure, so a site whose blog token had gone stale while its cached plan still read commercial re-sent the request on every single page render. Caching the failure here is the point, not a side effect. The tests now count the requests each condition costs, so the ordering the gate relies on cannot be rearranged silently.
current_usage.views_count counts the open billing period so far, so a site that reliably gets 150,000 views a month sat near 10,000 on day two. It would have qualified around day 20 and lost the prompt at every reset, which no one could reproduce on demand. billable_monthly_views is the settled monthly figure in the same payload, and the dashboard already treats it as the size of a site when it decides which upgrade tiers are worth offering. Both fields count billable views, so this changes the window and nothing else.
chihsuan
left a comment
There was a problem hiding this comment.
Thanks for the updates! @adamwoodnz LGTM 🚀 A few small nits inline.
| 'views null' => array( array( 'billable_monthly_views' => null ) ), | ||
| 'views not a number' => array( array( 'billable_monthly_views' => '150000 views' ) ), | ||
| 'views an array' => array( array( 'billable_monthly_views' => array( 150000 ) ) ), |
There was a problem hiding this comment.
Could we move these rows onto recent_usages? The gate no longer reads billable_monthly_views, so removing the is_numeric guard keeps them green.
| 'views null' => array( array( 'billable_monthly_views' => null ) ), | |
| 'views not a number' => array( array( 'billable_monthly_views' => '150000 views' ) ), | |
| 'views an array' => array( array( 'billable_monthly_views' => array( 150000 ) ) ), | |
| 'views null' => array( array( 'recent_usages' => array( array( 'views_count' => null ) ) ) ), | |
| 'views not a number' => array( array( 'recent_usages' => array( array( 'views_count' => '150000 views' ) ) ) ), | |
| 'views an array' => array( array( 'recent_usages' => array( array( 'views_count' => array( 150000 ) ) ) ) ), |
There was a problem hiding this comment.
Taken in c250c2a, and the reason is worse than the rows looking stale: all three passed for the same reason the empty row does, nothing in recent_usages, so they would have passed with the is_numeric guard deleted. On views_count they exercise it, and removing the guard now fails the 150000 views row.
I added two things your suggestion does not have. A row whose month is not an array at all, for the other half of the guard, and a test for a payload with one unreadable month beside a valid one: nothing distinguished skipping the bad month from abandoning the whole set, and replacing the continue with a return null now fails it.
| $endpoint = $this->build_endpoint(); | ||
| protected function fetch_stats( $args = array(), $api_version = self::STATS_REST_API_VERSION, $base_api_path = 'rest', $request_args = array() ) { | ||
| $endpoint = $this->build_endpoint(); | ||
| // `$request_args` stays out of the key: callers asking for different timeouts want the same answer. |
There was a problem hiding this comment.
Should a failure under a shorter timeout skip this cache? Otherwise a 5s timeout error is shared for 5 minutes with default 20s callers.
There was a problem hiding this comment.
Good catch, and it is a defect I introduced rather than a nit. Fixed in b731761.
Only three connection-failure codes skip the cache; every other WP_Error is stored for five minutes, a timeout included. And I had deliberately kept $request_args out of the key, which is right for a successful answer and wrong for a timeout: a request that gave up after 5 seconds says nothing about one willing to wait 20.
The caller it would have reached is concrete. /jetpack-stats/usage has exactly two callers, this gate at 5 seconds and the jetpack/stats-insights ability at the default 20, and get_stats_usage() takes no query args, so both land on one key. compose_subcalls would have folded the short failure into the insights response, so the ability degrades on a sub-call that never ran at its own deadline, somewhere an agent rather than a person is reading.
The timeout is in the key now. Successes stop being shared between callers with different deadlines, which here costs at most one extra request an hour, since the gate sits behind its own hourly cache. A test asserts the request goes out twice rather than once; with the timeout taken back out of the key it fails with "expected 2 times, actually called 1 time".
| self::FLAG, | ||
| array( | ||
| 'default' => false, | ||
| 'description' => 'Show the Upgrade to Parsely prompts to the sites and users that qualify, as offers_parsely_prompts() decides.', |
There was a problem hiding this comment.
nit: Would it be worth using Parse.ly in prose, like the changelog? Coding agents tend to copy whichever spelling lands first.
| 'description' => 'Show the Upgrade to Parsely prompts to the sites and users that qualify, as offers_parsely_prompts() decides.', | |
| 'description' => 'Show the Upgrade to Parse.ly prompts to the sites and users that qualify, as offers_parsely_prompts() decides.', |
There was a problem hiding this comment.
Done in 2292f48, and wider than the one line: seven prose mentions across both files still said Parsely, in the two file headers, three docblocks, the Simple setup comment and the flag description. Changing only the description would have left the file disagreeing with itself, and your reason for raising it is the argument for the sweep. Identifiers keep the undotted form.
There was a problem hiding this comment.
Thanks for sweeping the whole file! 🙏 A few more "Parsely" mentions, if you'd like:
There was a problem hiding this comment.
All four done in 04c56c03. A git grep across the package for the undotted spelling outside identifiers now comes back empty.
dognose24
left a comment
There was a problem hiding this comment.
Looks good to me. I re-read the head after the rebase: my three notes are covered (the PWYW and filter docblocks say what I asked for, and the VIP question is settled by the STATS-645 notes), and the views figure now reads the quietest whole month from recent_usages, which is the right call given what billable_monthly_views subtracts.
One non-blocking thought on top of @chihsuan's nits, which I agree with: in quietest_monthly_views() the client type allows current_usage.current_start to be null. In that case the open month is not skipped and its part-month total can refuse a qualifying site. It fails toward suppressing, which is the safe side, so a short comment making that deliberate would be enough.
Approving.
Letting a caller cap the timeout left every caller sharing one cache entry, and failures are cached for five minutes. A request that gave up after 5 seconds would therefore answer one willing to wait 20, handing it a deadline it never asked for and a failure it had no part in. `/jetpack-stats/usage` has exactly that pair: the Parse.ly prompt gate asks for 5 seconds, and the jetpack/stats-insights ability takes the default 20 and folds the result into a response an agent reads. The timeout is part of the key now. Successes stop being shared between callers asking for different deadlines, which costs at most one extra request an hour here, since the only short-timeout caller sits behind its own hourly cache.
The rows set billable_monthly_views, which the gate stopped reading when it moved to the quietest whole month. All three therefore passed for the same reason the empty row does, nothing in recent_usages, and would have passed with the is_numeric guard deleted. They set views_count now, and deleting that guard fails the row carrying '150000 views'. The new test covers what none of them can: an unreadable month is skipped rather than abandoning the set, so a valid month beside it still decides. Returning null there in place of the continue fails it.
The changelog already does, and these two files did not, so whichever a reader or a coding agent met first is the one it would copy. Seven prose mentions across the file headers, the docblocks, the Simple setup comment and the feature flag description. Identifiers keep the undotted form: the namespace, the class, the hook names and the PARSELY_ constants.
dognose24
left a comment
There was a problem hiding this comment.
The cache fix in b731761 reads right to me, and it answers the shared-failure problem. One thing it will trip: Jetpack_Top_Posts_Helper_Test in plugins/jetpack builds the stats cache key by hand from three parts, and the key now has a fourth, so its seeded transient is no longer read. That test is written to fail loudly when the key stops matching, so it needs the timeout added too.
Happy to re-approve once that is green. My earlier thought about a null current_start still stands as optional.
The test seeds a Stats transient and rebuilds the key itself, so keying the cache on the caller's timeout left it one part short. The helper then missed the primed entry and fell back to random posts, which the test fails loudly on by design rather than silently exercising the fallback. All five cases failed; with the timeout appended they pass, and removing it again fails all five.
The client type allows it, and then there is nothing to match the month in progress on, so its part-month total stays in the set and can refuse a site that qualifies. That is the side to fail on, but nothing in the code said so, and the next reader would have taken it for an oversight.
adamwoodnz
left a comment
There was a problem hiding this comment.
Both done.
bf42adc adds the timeout to that test's hand-built key. You read it right, and the loud-failure guard earned its keep: all five cases failed, not silently on the random-posts fallback. I checked it both ways rather than trusting the pass, since the key is rebuilt by hand and a test that matches for the wrong reason would look identical. Removing the fourth part again fails all five.
Worth knowing it is not the only hand-built copy of that key: stats_get_from_restapi() in modules/stats.php builds the same three parts under the same transient prefix. It is deprecated since 11.5 and reads and writes its own key consistently, so the effect is that it stops sharing entries with WPCOM_Stats, not that either side reads a key the other wrote. A duplicate fetch between a deprecated function and its replacement is not worth touching deprecated code for, so I left it. Nothing else reconstructs the key: the transient cleanup matches on the prefix alone.
b38daa6 takes your optional note on a null current_start. The comment says the open month then stays in the set and can refuse a qualifying site, and that suppressing is the side to fail on. Its own test would need a payload whose recent_usages carries the open month while current_usage omits current_start, which asserts the absence of a skip rather than a behaviour anyone wants, so I left it at the comment you asked for.
A dev site cannot reach most of this gate, so an untested branch here has nothing behind it. Six were unreached, each confirmed by a mutant the suite let through and now fails on: A usage response that is not a payload, and a `premium_analytics` value that is not an array, both of which fatal on an admin page render without their guards. The answer's 12-hour lifetime, which nothing held apart from the failure's hour. Counts quoted as strings, which `is_int` in place of `is_numeric` would silently drop, refusing every site. An `apikey` that is not a string, which would read as a Parse.ly customer and withhold the offer. And the filter saying no to a site that qualifies, where only the opposite direction was covered. Two remain uncovered deliberately. `fetch_monthly_stats_views()` news up its own client, so the `method_exists()` guard for an older jetpack-stats is unreachable from a test. The `(int)` cast on a count changes no outcome the gate can observe, since a numeric string compares the same against the threshold, so a test for it would pass with the cast deleted.
chihsuan
left a comment
There was a problem hiding this comment.
Thanks for the quick follow-ups! @adamwoodnz LGTM 🚀 Left one non-blocking note inline about the open-month skip.
| /* | ||
| * The month in progress is a part month, and the lowest of the set would read it as a | ||
| * slump. Without `current_start` there is nothing to match it on, so it stays in and can | ||
| * refuse a site that qualifies. Deliberate: withholding an offer costs less than making | ||
| * one on a month that has not finished. | ||
| */ | ||
| if ( null !== $open_month && ( $month['current_start'] ?? null ) === $open_month ) { |
There was a problem hiding this comment.
Could we drop the open-month skip rather than document its null case? On the WordPress.com side, recent_usages only holds the three previous periods, and the period in progress lives in current_usage. A live payload shows the same, so this branch never matches, and the test fixtures add an open month the endpoint never sends.
There was a problem hiding this comment.
Agreed, and dropped in 69efb146. I checked it against the live payload for a connected site before cutting it, and it is exactly as you describe: recent_usages held three closed periods, running the 26th to the 26th, with the period in progress reported apart from them in current_usage.
The part that makes this more than dead code is the one you pointed at: the fixture was adding a recent_usages entry carrying the open period, which the endpoint does not send, so the branch and the shape that exercised it were holding each other up. Neither would have failed without the other.
The fixture follows the live payload now, next_start and days_to_reset included, and keeps the open period at a count of 1. That is the guard the skip was really providing, and it is a better one: folding current_usage back into the figure fails ten tests, where against the old fixture it would have passed.
`recent_usages` carries only periods that have closed. The live payload for a connected site shows three of them, running the 26th to the 26th, while the period in progress is reported apart from them in `current_usage`. So the skip could never match, and the fixture that exercised it was adding a `recent_usages` entry the endpoint does not send: the branch and the shape proving it were holding each other up. The fixture follows the live payload now, `next_start` and `days_to_reset` included, and keeps the open period's count at 1, far below the threshold. That is the guard the skip was really providing, and it is a stronger one: folding `current_usage` back into the figure fails ten tests, where before it would have passed. Also drops the phpdoc that said a string is not a valid response for the usage mock, which Phan read as a real type and failed the static analysis job on.
Four mentions the first sweep did not reach, outside the two files it covered: the dashboard widgets doc, the script data type, the script data comment in class-analytics.php, and the test file header.
|
A note for @dognose24, since this supersedes the comment you asked for: the open-period branch is gone in The live payload settled it. The behaviour you were asking about is still pinned, by the fixture rather than a comment: the open period keeps a count of 1, far below the threshold, so folding |
dognose24
left a comment
There was a problem hiding this comment.
Looks good to me. I read the commits since my last pass and checked the usage payload from a connected local site: recent_usages came back with three closed periods and the one in progress only in current_usage, so dropping the open-period skip in 69efb146 is right. The timeout in the hand-built cache key and the Parse.ly spelling are in too. I did not run the PHP suite locally, CI is green on this head.
One thing to keep in mind, not for this PR: a period before the site had traffic counts as 0, so a site that is new to Jetpack waits until it has three full periods above the threshold. That seems fine for a first launch.
Fixes STATS-645
This targets
trunkand stands alone. It adds the shared eligibility rule only; the three prompts that read it come in their own PRs, and none of this code is reachable until then.This rule has a planned home outside Premium Analytics. Once #55372 lands its promo seam, a follow-up moves
parsely-prompts.phpinto apackages/parsely-promopackage that registers through it, the waypackages/adsalready depends on this package, and drops thepremium_analytics.offers_parsely_promptsscript data this PR adds. It lands here first because that seam does not exist yet, and putting it in #55372 would stack the two PRs together again.Why
"Upgrade to Parse.ly" prompts are coming to Stats: an item in the page options menu and a card on the Settings page at launch, plus a widget on the Traffic page that is built but held for a later, stronger push. They all have to answer the same question first, which is whether this site and this person should be offered Parse.ly at all. A copy of that rule per surface would drift, and the three would disagree with each other on the same site.
This adds the single check they will share. Nothing is visible to any user yet: a feature flag holds it closed, so the prompts can be built and reviewed against the real rule before anybody sees one.
Proposed changes
offers_parsely_prompts()in a newprojects/packages/premium-analytics/src/parsely-prompts.php, modelled on the neighbouringstats-plan-gates.php. A site and user qualify when all of these hold:commercialorpaid. VIP needs no rule of its own, as it already resolves tocommercial.manage_options.jetpack-stats-parsely-promptsfeature flag, default off. Every condition sits behind it.premium_analytics.offers_parsely_prompts, on the dashboard page only, and add its TypeScript type.Review notes
The conditions are ordered deliberately, cheapest first. The views figure is the only one that costs a WordPress.com request, so it is evaluated last and a site that fails anything earlier never makes one. The tests assert the request count for each condition, so the ordering cannot be rearranged silently.
That request is cached here, including its failures.
WPCOM_Statsdeliberately does not cache a connection failure. Without a cache of our own, a site whose blog token had gone stale while its cached plan still readcommercialwould re-send that request on every admin page render. A failure is held for one hour rather than twelve, so a single bad response from WordPress.com does not hide the prompt for half a day. It also asks for a 5 second timeout, matching the package's other pre-render requests;WPCOM_Statswaits 20 seconds and had no way for a call site to ask for less, which is the one change this PR makes outside Premium Analytics.The quietest recent whole month, not
billable_monthly_views. The obvious field is the wrong one. WordPress.com takes the lowest of the last three months and then subtracts the views the site's plan already paid for, flooring at zero, so the figure falls as a site buys more and reads 0 on a site provisioned for its own traffic. Since the gate also requires a paid plan, the two conditions fought each other: a commercial site at 150,000 views a month that had bought for 150,000 reported nothing. The gate now reads the same figure before that subtraction, fromrecent_usages, and skips the month in progress, whose part month the lowest of the set would otherwise read as a slump.Two conditions that are product calls, not code ones
offers_free_site_upgrade()already does for the Stats upgrade banner. Confirmed as the launch rule: the prompts go to Jetpack-connected sites only, and more sites can follow later (p1795557541714749/1795050553739799-slack-jetpack-stats). Worth a reviewer's eye on the mapping rather than the decision, since "not Simple" is the wider set: an Atomic site still qualifies, which is intended because it is Jetpack-connected, and a site with no connection cannot pass the tier or views conditions anyway.site_id_is_set()wherever it can, and theparselyoption holds that Site ID for an older plugin and for one that has been deactivated and left it behind. A customer who has never wired their Parse.ly account to this site through the plugin cannot be detected, and a site that once ran wp-parsely stays suppressed. The fallback errs that way on purpose, since showing the prompt to a customer is the worse failure. STATS-671 tracks closing that residual case with a WordPress.com lookup, which needs no artifact on the site; it is a cross-team dependency and does not block this PR.Does this pull request change what data or activity we track or use?
No. It reads the Stats usage figure the dashboard already requests, and the
parselyoption if one exists. Nothing new is sent anywhere.Testing instructions
Nothing is visible by default, so this is tested through the script data.
jetpack build packages/premium-analytics.admin.php?page=jetpack-premium-analytics-wp-admin) as an administrator.window.JetpackScriptData.premium_analytics.offers_parsely_prompts. It isfalse, because the feature flag is off.add_filter( 'jetpack_feature_flag_enabled_jetpack-stats-parsely-prompts', '__return_true' );. Reload and check again. It is stillfalseon a site under 100,000 monthly views.add_filter( 'jetpack_premium_analytics_offers_parsely_prompts', '__return_true' );. Reload. It is nowtrue. This is the lever the three prompt PRs will use for their own testing.window.JetpackScriptData.premium_analytics. Theoffers_parsely_promptskey is absent: it is published on the dashboard alone.Automated coverage:
jetpack test php packages/premium-analyticsruns 37 tests for this file, covering each condition, the ordering, the caching, the capped wait, and every way the views lookup can fail. 937 PHP tests pass in the package, and thepackages/statssuite passes with the new request argument (333 tests). Phan could not be run locally: it crashes parsing the WordPress stubs on this machine's PHP 8.5.🤖 Generated with Claude Code