Skip to content

Premium Analytics: Add promo cards to the Stats options menu and Settings - #55372

Merged
adamwoodnz merged 50 commits into
trunkfrom
stats-657-add-a-promo-slot-extension-api-to-premium
Nov 26, 2026
Merged

adamwoodnz merged 50 commits into
trunkfrom
stats-657-add-a-promo-slot-extension-api-to-premium

Conversation

@adamwoodnz

@adamwoodnz adamwoodnz commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes STATS-657

A third placement, a card at the foot of a dashboard section, is held back for #55375 (STATS-668), which is stacked on this branch. It arrives as one more entry in the per-placement table of required copy.

Why

No user-visible change. The promo cards the "Upgrade to Parse.ly" prompts will render land here, and this PR registers no promo of its own, so the slot publishes an empty list and the client mounts nothing.

What they give a reader, once a promo is registered and available, is one consistent promotion: Premium Analytics owns the card frame, the close control, the dismissal memory and the view, click and dismiss events, so a prompt looks and behaves the same wherever it comes from, and closing one keeps it closed.

This started out as a versioned extension point other plugins would register through. Nothing outside the package registers a promo, and nothing is scheduled to: the Traffic banner is on hold, and the Blaze promo this was modelled on is neither scheduled nor planned against this API. So the registry is internal. register_promo() is marked @internal, carries no version, and fires on no action. What remains is a seam a later placement or promo plugs into, not a contract this PR has to keep.

Proposed changes

  • A promo model and registry in projects/packages/premium-analytics/src/. The package's own promos call register_promo() directly; there is no registration action and no hydration step. The slot carries no feature flag of its own: every promo declares an is_available rule, and the Parse.ly prompts stacked above this PR route theirs through offers_parsely_prompts(), which the merged jetpack-stats-parsely-prompts flag already gates. A second flag in front of that would be a third control on one card.
  • Two placements: a card in the settings panel, and one item in the Stats options menu. The copy each placement cannot render without is one table, so a new placement is an entry rather than a branch.
  • Registration refuses a duplicate slug, an unknown placement, a placement's missing copy, and a cta_label whose cta_url is not http(s). That last one is a real bug the review caught: a menu promo the client cannot link still took the single item the menu offers, hiding a valid one.
  • The card is a Card.Root with a Card.Title, matching the other cards on Settings. The title labels the region through aria-labelledby, and closing the card parks focus on the surrounding region rather than dropping it to <body>.
  • Availability gates, in order: the existing jetpack_show_promotions filter that Gutenberg, plugin search, Search and the old Stats nudges all honour, the promo's capability (manage_options by default, because the Stats roles setting can let an editor or an author open the dashboard and an upgrade is not theirs to buy), and the promo's own is_available rule. A promo that declares no is_available rule is never available, which is deliberate: a promo is an interruption, so the caller has to say who it is for.
  • Dismissal in the core/preferences scope jetpack-premium-analytics/dashboard: the first close snoozes for snooze_days (90 by default), the second is final, and the record stores which of the two it was so raising snooze_days later cannot bring back a promo somebody closed for good. One promo shows per placement per page load, and closing one leaves that placement empty until the next load rather than swapping a card under the reader's cursor.
  • The view event fires on the card's first intersection rather than on mount, so an impression is only reported when the card was actually on screen.

Screenshots

Both placements on a Jurassic Ninja site running this branch's build, from the two promos the snippet below registers.

The Settings shot keeps the Activation card above it in frame, because matching those siblings is the point: same border, same radius, same padding, same heading size and the same gap under the title.

The settings placement The options-menu placement
Two cards on the Stats Settings page. The upper one is headed "Activation" with body text about activating Stats from Jetpack features. Directly below, in an identical frame, a promo card headed "Try Acme" with the body "Reach more readers.", a blue "See Acme" button carrying an opens-in-a-new-tab arrow, and a close control at the end of the title row, vertically centred against the title. The Stats options menu open, listing Customize, Arrange tabs, a separator, Settings, another separator, then "Try Acme" with an opens-in-a-new-tab arrow in a group of its own at the foot of the menu.

Related product discussion/links

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

Yes, three new Tracks events, each carrying the promo's slug and placement:

  • jetpack_premium_analytics_promo_view — a card first comes into view, once per placement per page load; for an options-menu promo, each time the menu opens with the promo in it.
  • jetpack_premium_analytics_promo_click — the reader follows the call to action. Carries label, a fixed value rather than the translated button text, so the same click groups across locales.
  • jetpack_premium_analytics_promo_dismiss — the reader closes a card. Carries dismissal, either snooze or final.

No new user data is collected. The dismissal record (a count, a timestamp and whether the close was final, per promo slug) is a user preference stored through core/preferences, local to this dashboard.

Testing instructions

Nothing renders until a promo is registered, and this PR registers none of its own. Register two by hand from an mu-plugin or a code snippet. Any hook after init and before the admin scripts are enqueued will do; admin_init is the simple one:

add_action(
	'admin_init',
	function () {
		// Guard it: this fires on every admin page, so an unguarded call would fatal wp-admin
		// on a site where Stats v2 is not running.
		if ( ! function_exists( 'Automattic\Jetpack\PremiumAnalytics\register_promo' ) ) {
			return;
		}

		Automattic\Jetpack\PremiumAnalytics\register_promo(
			'acme/offer',
			array(
				'placement'    => 'settings',
				'title'        => 'Try Acme',
				'description'  => 'Reach more readers.',
				'cta_label'    => 'See Acme',
				'cta_url'      => 'https://example.com/acme',
				'is_available' => true,
			)
		);

		Automattic\Jetpack\PremiumAnalytics\register_promo(
			'acme/menu',
			array(
				'placement'    => 'options-menu',
				'cta_label'    => 'Try Acme',
				'cta_url'      => 'https://example.com/acme',
				'is_available' => true,
			)
		);
	}
);
  • Open the Premium Analytics dashboard and the Stats options menu (the three dots). It has a "Try Acme" item that opens in a new tab, with one "opens in a new tab" marker and no second arrow icon.
  • Open Settings. The card sits at the foot of the page and reads as a sibling of the cards above it: same padding, same heading size. It has a title, a description, a call to action and a close control.
  • Load Settings with the card below the fold, watching the Network panel filtered on pixel.wp.com. No jetpack_premium_analytics_promo_view request goes out until you scroll the card into view.
  • Close the Settings card with the keyboard. Focus stays in the Settings region rather than returning to the top of the page, and the next Tab continues from there.
  • Dismiss the card. It goes, that placement stays empty for the rest of the page load, and it is still gone after a reload. Clear dismissedPromos from the jetpack-premium-analytics/dashboard preferences scope to get it back.
  • As an editor or author on a site whose Stats roles setting lets them open the dashboard: no promo in either placement.
  • Give acme/menu a cta_url of javascript:alert(1). It never registers, the options menu has no promo item, and the Settings promo still shows. With WP_DEBUG on, a _doing_it_wrong() notice says why.
  • Remove the snippet and reload: no cards anywhere, and premium_analytics.promos is an empty array in the script data.

Verified

  • PHPUnit 971 tests pass; 5140 Jest tests across 237 suites pass.
  • pnpm run typecheck exits 0. ESLint clean; PHPCS, Prettier and stylelint ran on every commit through the pre-commit hook.
  • Phan did not run locally (jp is not installed on this machine and the host PHP is ahead of the repo matrix), so watch that check here.
  • Both placements exercised in a browser on a Jurassic Ninja site running this branch's build (ge549571b), with the trunk copy of the plugin deactivated so the autoloader could not serve trunk's packages instead. The screenshots are that run. Also checked there: both promos reach premium_analytics.promos in the script data when registered on admin_init; closing the Settings card parks focus on the surrounding region rather than <body>, and the card is still gone after a reload while the menu promo is unaffected. The javascript: step is the one bullet not run end to end, because that host's plugin file editor silently discards saves; the seven data-provider cases in Promo_Registry_Test cover the same refusal. Capturing it caught two things the unit tests could not. The close control sat ahead of Card.Header inside Card.Root, which cost the header its first-child padding and left the title tight against the description beside a sibling card that was not (b6577fb). It was then still pinned to the card corner by absolute positioning rather than aligned with the title as the mock has it, so the header now lays the two out as a row and the stylesheet is gone (255266d). Title and control centre on the same pixel.

🤖 Generated with Claude Code

@adamwoodnz adamwoodnz added Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] In Progress labels Nov 24, 2026
@adamwoodnz adamwoodnz self-assigned this Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 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), and enable the stats-657-add-a-promo-slot-extension-api-to-premium branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack stats-657-add-a-promo-slot-extension-api-to-premium

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 Nov 24, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 3 files.

File Coverage Δ% Δ Uncovered
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/stats-options-menu/stats-options-menu.tsx 45/45 (100.00%) 0.00% 0 💚
projects/packages/premium-analytics/routes/settings/components/stats-settings/stats-settings.tsx 18/18 (100.00%) 0.00% 0 💚
projects/packages/premium-analytics/src/class-analytics.php 216/231 (93.51%) 0.06% 0 💚

8 files are newly checked for coverage. Only the first 5 are listed here.

File Coverage
projects/packages/premium-analytics/src/promos.php 13/33 (39.39%) ❤️‍🩹
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/promo-card/promo-cta.tsx 5/6 (83.33%) 💚
projects/packages/premium-analytics/src/class-promo-registry.php 30/33 (90.91%) 💚
projects/packages/premium-analytics/src/class-promo.php 40/42 (95.24%) 💚
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/promo-card/promo-card.tsx 32/33 (96.97%) 💚

Full summary · PHP report · JS report

@adamwoodnz adamwoodnz added the Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code label Nov 24, 2026
@adamwoodnz

This comment has been minimized.

@claude

This comment has been minimized.

@adamwoodnz

This comment was marked as resolved.

@adamwoodnz adamwoodnz added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Nov 24, 2026
@adamwoodnz
adamwoodnz marked this pull request as ready for review November 24, 2026 05:38
@adamwoodnz
adamwoodnz requested a review from a team as a code owner November 24, 2026 05:38
@adamwoodnz

Copy link
Copy Markdown
Contributor Author

Review cycle summary

Round reviewer: Codex (xhigh), 2 rounds. The phase ended a round early because round 2 returned no P1 or P2 findings. Final review: Claude, one round. No fallback was forced. The round reviews are not on the PR, so the findings are logged below.

Round 1, Codex: 2 findings, both fixed

Finding What it was Outcome
P2-1 docs/dashboard-promos.md The registration example told other plugins to hook Promo_Registry::REGISTER_ACTION. On a site where another plugin's older copy of this package wins the autoloader, reading that constant is a fatal error at add_action() time, before the version check inside the callback can decline. Fixed in 383cbef. The examples use the literal action name, as the widget docs next door already do.
P2-2 stats-options-menu.tsx cta_label defaults to empty, so an options-menu promo that supplied only a URL rendered a focusable menu link with no accessible name, and could be the only reason the options button appeared. Fixed in 0872139. Registration refuses it, and the menu checks the label too, since the payload comes from whichever copy of the package is installed.

Round 2, Codex: no findings

"No blocking correctness, security, or contract issues were identified in the branch changes."

Final round, Claude: 7 findings, all fixed

Finding What it was Outcome
Worth addressing 1 A settings promo could register with no title, giving an <aside> landmark with no accessible name and an empty heading, including as the fallback while a render module loads. Fixed in bd2e4e6. Refused for any card placement, so the follow-up PR's section footer inherits the rule.
Worth addressing 2 get_available_promos() ran twice per dashboard load, so every registrant's is_available rule and the runtime filter ran twice. Fixed in bd2e4e6. The registry keeps the gated list for the request. A test asserts one evaluation however many callers ask, and reports 2 without the memo.
Worth addressing 3 PromoCard had no key, so a promo arriving after the preferences store hydrates could inherit the previous one's error-boundary state and lazy module. Fixed in 0983116.
Nit 1 @since $$next-version$$ on jetpack_show_promotions, which has been a Jetpack filter since 4.8.0 with six other call sites, would stamp this release as its origin. Fixed in bd2e4e6, using the one-line "documented in" reference the other call sites use.
Nit 2 Two descriptions still listed a third placement this PR no longer ships, the feature flag's description included. Fixed in 0983116.
Nit 3 is_available cast any value to bool, so 'is_available' => 'my_rule_typo' was truthy and the gate failed open. Fixed in bd2e4e6. Registration refuses anything neither callable nor boolean, and the gate returns false if a callable stops resolving.
Nit 4 The runtime filter can add promos that passed none of the registration rules. Intended, so documented in bd2e4e6 rather than changed.

Two existing refusal tests turned out to be passing on the wrong rule once the title check landed, since their fixtures registered a settings promo with no title. They carry one now, so each fails on the rule it names.

CI

All 83 checks pass, including both Phan runs, which failed at the start of the cycle on two errors in this branch and were fixed in 1b44451. The coverage check is overridden by Covered by non-unit tests: packages/sdk/src/conformance.ts holds type-level assertions whose job is to fail the type check, and src/promo-fixture-module.js is the browser fixture, excluded from the production mirror. Both are explained in the PR body.

Threads

Two comments minimized as resolved: the final review and its request. No inline threads were opened, and no human reviewer comments are outstanding.

Status: clean.

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

Thanks @adamwoodnz, this is really well put together, and the docs are great. Tested on a local Docker site: the options menu item, the Settings card in both the plain and module versions, dismissing and reloading, and turning jetpack_show_promotions off all worked as described. The early read cache and the final dismissal cases I only read in code.

I left a few inline comments. The three I think we should fix are the menu promo without a URL hiding every other menu promo, the public cache in Promo_Registry, and the view event firing for the Settings card before anyone scrolls to it. The rest are smaller and fine as follow ups. Escaping looked good to me, the copy renders as text and every CTA goes through safeHttpUrl.

My bigger question is whether this should be JITM instead of a new framework. STATS-657 rules out /notices, but I couldn't find JITM discussed, and it already covers most of what the registry does here. The copy and targeting live on WordPress.com, so a new promo or a rule change doesn't need a plugin release. It can target by role, it has snooze then final built in (the jetpack_manage_ad JITM on My Jetpack uses expires of 42 days with max_dismissal of 2, which is the same shape as snooze_days here), and it already works on Simple. A Parse.ly rule could also lean on the traffic data WordPress.com already has, rather than working it out locally.

For reference, this is that JITM on My Jetpack, rendered through JitmSlot:

jitm-my-jetpack-pr

What JITM is missing is mostly support for the new SPA pages, which feels like a good opportunity, as every page moving to that setup (Forms, Newsletter, Social, Backup, My Jetpack) would benefit, not just Stats:

  • JitmSlot taking its own message path, so a page can have more than one slot (Settings footer, options menu, section footer). Today there's one #jp-admin-notices per page and a new card replaces the last one.
  • Route aware message paths for boot pages. My Jetpack already gets this through a special case, we could generalise it from the p param.
  • Rendering in React with named templates the page registers (a card, a menu item), instead of the single vanilla default template. PromoCard, PromoCta and the error boundary from this PR would fit nicely there, and sticking to named templates means WordPress.com can't point a page at an arbitrary script module.
  • Opt in per user dismissal using the core/preferences logic from this PR, keeping site wide as the default for existing JITMs.
  • Allowing JITMs on the Stats page again, stats-admin turns them off at the moment.

Not from this PR, but FYI: JITM dismissal is site wide and the dismiss endpoint only checks read, so any logged in user can hide a JITM for the admins too. Worth fixing if we go this way.

I'd rather we extend JITM than ship a second system that does the same thing, so I'd hold off on locking in PROMO_API_VERSION 1.0.0 until we've talked it through. Happy to be convinced otherwise though, let me know what you think.

Co-reviewed and tested with Claude and Codex.


$promo = new Promo( $slug, $args );

if ( ! in_array( $promo->placement, self::PLACEMENTS, true ) ) {

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.

Maybe we can clean these checks up a bit, most of them branch on the placement. A small per placement rules array (required fields, whether it can be dismissed or take a render module) that we loop through would make the section placement in #55375 one more row. It's also a good spot to trim() the required fields, at the moment a single space passes the title and cta_label checks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 0bca812: one table of what each placement requires and refuses, so the section placement in #55375 is an entry rather than four more branches. Copy is trimmed before the required-field checks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Shrunk again in 47b02bc. With the refusal rules dropped the table holds only the copy each placement cannot render without, which is still the shape the section placement in #55375 plugs into.

return $this->refuse( __( 'A promo card needs a title. The card is labelled by it.', 'jetpack-premium-analytics-pkg' ) );
}

if ( 'options-menu' === $promo->placement && '' === $promo->cta_label ) {

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.

If a menu promo is registered with a label but no URL, it still gets picked first and then the menu drops it, so another plugin's valid menu promo never shows. I could reproduce this in the Stats options menu. Should we refuse a non http(s) cta_url here, and maybe only pick from promos the menu can actually render?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, this was a real bug. 2d60abb refuses a cta_label whose cta_url is not http(s) at registration, so the picker never sees one and it cannot take the single menu item away from a valid promo.

* @param callable $compute Applies the gates to the registered promos.
* @return Promo[] The gated promos.
*/
public function remember_available( callable $compute ) {

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.

As this is public and caches whatever the first caller computes, a get_available_promos() call before init caches an empty list for the rest of the request, which the docs say shouldn't latch. It also lets any caller hand in its own list and skip the flag and jetpack_show_promotions. Maybe we keep the memo private in the registry and only cache once it's hydrated? compute_available_promos() and get_registered() also don't have a caller outside the package yet.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

2d60abb gates the memo on hydration: it computes without storing until the registry has hydrated, so a pre-init read cannot become the answer for the request. The rest is answered by dropping the public surface in 554f672, which removes PROMO_API_VERSION, the docs, the SDK types and the fixtures, and marks register_promo() internal.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Superseded in 47b02bc. With no registration action there is no hydration, so the pre-init latch cannot happen: the memo is a plain per-request cache that only get_available_promos() fills.

}

// Latching this early would drop every registrant hooked later, so the read skips the action.
if ( ! did_action( 'init' ) ) {

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.

A small nitpick, Announcement_Registry also skips a read while init is still running ( here ). I assume we want the same, so a read during init doesn't fire the action before later init callbacks have hooked in?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Matched to Announcement_Registry in 0bca812.

const { isDismissed, willBeFinal, dismiss } = usePromoDismissal( promo );
const trackEvent = useTrackEvent();

useEffect( () => {

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.

On Settings the card is the last thing on the page, so the view event fires on load even if I never scroll down to it ( on my screen it was well below the fold ). Should we record the view on first intersection instead? Meaning the click through rate registrants look at is based on real impressions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

2d60abb records the view on the first IntersectionObserver intersection instead.

const fallback = <DataOnlyContent promo={ promo } trackClick={ trackClick } />;

return (
<aside className={ styles.card } aria-label={ promo.title } data-testid="promo-card">

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.

Every other card on the Settings page is a Card.Root with a Card.Title, so this one ends up with tighter padding and a smaller heading next to them. Could we build the frame from Card.Root instead of the custom styles, keeping the aside if we can?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

d29c9b3 builds the frame from Card.Root with a Card.Title, which now owns the title and labels the region through aria-labelledby as the consent card does, so a render module draws the content region below it rather than its own heading. The aside could not stay: Card.Root types its ref as HTMLDivElement, so the landmark is role="complementary" on its own element.

const dismiss = useCallback( () => {
closedPlacements.add( placement );
listeners.forEach( listener => listener() );
void set( DASHBOARD_PREFERENCES_SCOPE, PREFERENCES_KEY, {

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.

If a promo with snooze_days: 0 is closed we track it as final, but only store count: 1, so if the registrant later bumps snooze_days for the same slug it comes back. Maybe store final: true with the record? Also nothing prunes old slugs from dismissedPromos, fine as a follow up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

764501d records whether the close was final, so raising snooze_days later no longer brings back a promo somebody closed for good. Records written before this still read correctly through the count. Pruning old slugs is still open.

onCustomize,
tabs,
isSiteConnected = true,
withPromo = true,

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.

Should this default to false, with the pages that want a promo opting in? Given a new upsell page would show another plugin's promo next to its own offer unless someone remembers to pass false. Not a blocker.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Left as it is for now. Eighteen call sites mount the menu bare and want the promo; three opt out, and those three are the screens already selling something. Flipping the default makes eighteen files carry a flag to get the intended behaviour, and a report page added later would silently lose the promo instead. Say the word if you would still rather have it opt-in.


Write the action as the literal string, not as `Promo_Registry::REGISTER_ACTION`. Another plugin may put an older copy of this package ahead of yours in the autoloader, and reading a constant off a class that copy does not have is a fatal error at `add_action()` time, before any version check inside your callback can run.

The registry fires the action once, on its first read after `init`, whichever request makes that read: the dashboard page, or a REST request that runs later than `init`. A registrant hooked on `init` reaches one path and misses the other. A read before `init` is a `_doing_it_wrong()` and does not latch, so a registrant hooked later still runs on the first read after `init`.

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.

I don't think the REST path works yet, promos.php is only loaded from load_dashboard_components(), so on a REST request get_available_promos() isn't defined and nothing fires the action. Should we drop that part for now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The doc is gone with the rest of the public surface in 554f672.

'cta_label' => __( 'Try Acme', 'acme' ),
'cta_url' => 'https://example.com/acme',
'dismissible' => false,
'is_available' => true,

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.

With is_available => true this shows to everyone who can open Stats, which can include editors and authors depending on the Stats roles setting, so they'd see an upgrade link they can't act on. Should the examples check manage_options? Or maybe the registry takes a capability like announcements does, defaulting to manage_options.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Taken as you suggested in 0bca812: a registry capability option defaulting to manage_options. Worth more than the examples, since the gate was live in code: an editor or author the Stats roles setting lets into the dashboard was being offered a checkout they cannot complete.

@adamwoodnz

adamwoodnz commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for testing it @louwie17, and for the JITM write-up. I agree with the destination. Copy and targeting on WordPress.com, no plugin release to change a promo, role targeting and snooze already built: that is a better home for this than a registry in Premium Analytics, and your five changes are the right list.

The problem is ordering. We are aiming to have these promos in place by November 30, and that list is multi-slot support, route aware message paths, React named templates, opt in per user dismissal, and re-enabling JITMs on the Stats page. I think we'll struggle to land all that in time.

What makes me think the two are not in competition is that you have already picked out the pieces. PromoCard, PromoCta and the error boundary are what the named-templates change would render, and the core/preferences logic is what the per-user dismissal change would use. Those exist here, tested, and they do not care where the promo came from. Landing them now is how that part of your plan gets built, and the transplant is then a change of source rather than a rewrite.

So, on your actual ask: I will drop PROMO_API_VERSION and the versioned public surface around it, and keep register_promo() as an internal seam, marked as such. Nothing to lock in, nothing to support, and no second public framework. I will also fix the three you flagged: the menu promo with no URL hiding the others, the public cache in Promo_Registry, and the Settings card's view event firing before anyone scrolls to it.

Two things I ran into that are worth knowing for the JITM work. The admin shell that #55075 teaches JITM about is still behind a feature flag that is off by default. And Premium Analytics renders no JitmSlot of its own, so there is currently nowhere in that dashboard for a card to go. Your point about the dismiss endpoint only checking read also matters more once JITM is carrying promos rather than notices, so that one looks worth doing early rather than late.

Your instinct on detection is right, and it goes further than traffic data. A Parse.ly account is keyed on the site's domain, so WordPress.com can answer "is this site already a customer" with no artifact on the site at all. #55232 can only see a customer who wired their account up through wp-parsely. STATS-671 tracks it. It needs Parse.ly, so it is not a November 30 item, and #55232 is correct without it: it never offers the prompt to a customer it can see.

Last thing, and this is retrofox's point rather than yours: the PR straight after this one moves Parse.ly's rule, copy and signup URL into packages/parsely-promo, registering through the seam the way packages/ads already depends on this package, and deletes the direct script-data injection #55232 ships. Keeping an internal register_promo() is what makes that possible, which is why I would rather trim the public surface than remove the seam.

Does that work as a sequence?

@adamwoodnz

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All of it is in, apart from one I pushed back on.

  • Placement checks and trim() — one table of what each placement requires and refuses, so the section placement is an entry rather than four more branches. Copy is trimmed before the required-field checks. 0bca812
  • Menu promo with a label and no URL — registration now refuses a cta_label whose cta_url is not http(s), so the picker never sees one and it cannot take the single menu item from a valid promo. Real bug, thanks for reproducing it. 2d60abb
  • remember_available() latching before init — it computes without storing until the registry has hydrated, so a pre-init read cannot become the answer for the request. 2d60abb The rest of that comment is answered by dropping the public surface: PROMO_API_VERSION, the docs, the SDK types and the fixtures are gone, and register_promo() is marked internal. 554f672
  • A read while init is still running — matched to Announcement_Registry. 0bca812
  • View event on load — recorded on the card's first IntersectionObserver intersection instead. 2d60abb
  • Focus after closing — the surrounding region catches it, the way WidgetState does for a widget whose children unmount. d29c9b3
  • Card.Root — the frame is a Card.Root with a Card.Title, which now owns the title and labels the region through aria-labelledby as the consent card does, so a render module draws the content region below it rather than its own heading. I could not keep the aside: Card.Root types its ref as HTMLDivElement, so the landmark is role="complementary" on its own element. d29c9b3
  • snooze_days: 0 stored as count: 1 — the close now records whether it was final, so raising snooze_days later no longer brings back a promo somebody closed for good. Records written before this still read correctly through the count. Pruning old slugs is still open. 764501d
  • capability — taken as you suggested: a registry option defaulting to manage_options. Worth more than the doc examples, since the gate was live in code: an editor or author the Stats roles setting lets into the dashboard was being offered a checkout they cannot complete. 0bca812
  • REST path in the docs — the doc is gone with the rest of the public surface. 554f672
  • withPromo defaulting to false — I left this one as it is. Eighteen call sites mount the menu bare and want the promo; three opt out, and those three are the screens already selling something. Flipping the default makes eighteen files carry a flag to get the intended behaviour, and a report page added later would silently lose the promo instead, which is the same mistake pointing the other way. Say the word if you would still rather have it opt-in.

@adamwoodnz adamwoodnz changed the title Premium Analytics: Add a promo slot extension API Premium Analytics: Add promo cards to the Stats options menu and Settings Nov 25, 2026

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

Nice work, and the changes from the first round all hold up in the code. No blockers from me, just four small notes inline. I read the code and CI results; I didn't run it locally.

Two things on the description:

  • The last Verified point still talks about packages/sdk/src/conformance.ts, which went out with the SDK types in 554f672. That paragraph and the Covered by non-unit tests label can probably go.
  • The PR carries both [Status] In Progress and [Status] Needs Review.

One for the follow-up, not this PR: when the Parse.ly package registers through this, it will want a function_exists() guard around register_promo(). promos.php only loads on admin screens, and another plugin can bring an older copy of this package that doesn't know a newer placement like section.

* @return void
*/
function configure_promos() {
Feature_Flags::register(

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.

Could the flag register in boot_shared_services() instead, next to Dashboard_Announcements::configure()? configure_promos() runs from load_dashboard_components(), which is admin screens only, so under WP-CLI the flag isn't registered: wp companion feature-flag list doesn't show it and enable warns that nothing registered it. The two filters can stay where they are.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 47b02bc, next to Parsely_Prompts::register_feature_flag() and for the same reason. promos.php is required there too, so register_promo() is defined on every request rather than only the ones that render the dashboard.

* Promos: the registry helpers and the gates a registered promo passes before it shows.
*
* Internal to this package. The dashboard renders what is registered here; nothing outside the
* package registers through it, so there is no versioned contract to hold.

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.

nit: A few comments still describe the earlier public version. This one says nothing outside the package registers, while the Promo class docblock, the require comment in class-analytics.php, the promos comment in jetpack-script-data.d.ts and the flag description all say other packages register here. Could we bring them in line?

The d.ts comment also says the field is absent until the registry hydrates, but it is absent whenever the request isn't rendering the dashboard.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Rewritten across 47b02bc and d7fb750: the file header, the Promo class docblock, the require comment in class-analytics.php and the promos comment in the script-data types. They describe an internal registry now, which is what it is.

href={ safeHref }
variant={ variant === 'primary' ? 'solid' : 'outline' }
openInNewTab
onClick={ () => trackClick( label ) }

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.

nit: For the default card and the menu item, label is the translated cta_label, so one promo reports a different label per locale. slug still identifies it, so counts are fine, but grouping by label splits. Would a fixed value like cta work for the default CTA, leaving free labels to render modules?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Taken in d7fb750: the CTA reports a fixed cta. With the render-module path gone there are no caller-supplied links left to tell apart, so the label is constant by construction rather than by convention.

The Stats roles setting can let an editor or an author open the dashboard,
and an upgrade is not theirs to buy: they would be shown a prompt to a
checkout they cannot complete. Promos now default to manage_options, and a
registrant that wants a wider audience says which capability instead.

Registration also trims the copy before the required-field checks, so a
title or cta_label of nothing but spaces no longer passes as present and
render as an empty card, and it refuses an empty capability rather than
silently showing the promo to everyone.

The per-placement checks move into one table of what each placement
requires and refuses, so adding the section-footer placement is an entry
rather than four more branches. A read while init is still running now
answers without hydrating, matching Announcement_Registry: registrants
hooked later on init itself would otherwise be dropped.
Every other card on Settings is a Card.Root with a Card.Title, and this one
hand-rolled the same surface from its own padding, border and background.
The two drifted apart the moment a token changed, and the card read as
almost-but-not-quite a sibling of the ones above it.

The frame now owns the title, so it labels the region through
aria-labelledby the way the consent card does, and a render module draws
the content region below it rather than repeating a heading.

Closing the card also parked focus on <body>, because the close control
lives inside the subtree that unmounts: the next Tab started again at the
top of Settings. The surrounding region catches it instead, which is what
WidgetState does for a widget whose children unmount.
A close under snooze_days 0 is final, but the record stored only count 1,
and whether that counted as final was re-derived on every later read from
the registrant's current snooze_days. Raising the value afterwards turned
every one of those records back into an unexpired snooze, so a promo
somebody had closed for good reappeared for them.

The close now stores what it decided. Older records, written before this,
still read correctly through the count.
The close control sat directly inside Card.Root, ahead of Card.Header, so
the header was no longer the card first child and the design system gave it
24px 24px 0px instead of 24px all round. On screen the promo card title sat
tight against its description while the Activation card above it had the
usual gap, which is the sibling mismatch the Card.Root work was meant to
remove.

Moving the control inside the header restores the padding. It is still
positioned against the card, which is what carries position: relative.
The control was pinned to the card corner with absolute positioning, which
left it sitting above the title rather than beside it. The mock has the two
vertically aligned, so the header now lays them out as a row with the title
and the control at either end, which is how the consent card already places
its badge.

The stylesheet went with it: the positioning was all it held, and the
relative positioning on the card existed only to anchor it.
Every other widgets-toolkit component story sits under Widgets Toolkit /
Components; this one sat a level above it, away from the components it
belongs beside in the sidebar.

Its description also still told the reader a promo comes from another
plugin and that the card keeps only its frame, neither of which is true
now. Storybook renders that text, so it says what the card actually owns.
The fallback it rendered is the data-only card, so the story was pixel for
pixel the DataOnly story beside it and showed a reader nothing. The
behaviour is covered by promo-card.test.tsx, which drives the same throwing
module through the error boundary.

Both fallback tests were asserting on the title, which the card frame has
drawn for itself since the move to Card.Root, so they passed whether or not
the fallback ran. They assert the description now, which only the data-only
content draws.
Nothing outside this package registers a promo, and nothing is scheduled to.
The Traffic banner that would have been the second placement is on hold, and
the Blaze promo this was modelled on is neither scheduled nor planned against
this API. An extension point with one in-package caller holds a contract it
cannot exercise, so this drops what only an outside registrant needed: the
registration action and the hydration it required, the slug and type checks,
and the render-module field.

What stays is what the package's own promos need. A duplicate-slug guard, a
known placement, the copy each placement cannot render without, and the
http(s) check on a CTA URL, which stops one bad promo from taking the single
item the options menu offers.

The flag now registers at package boot instead of alongside the promos, so
Feature_Flags::all() lists it on requests that never render the dashboard.
The render-module path let a promo replace the card's content region with a
lazily imported script module. With the slot now internal there is nobody to
ship such a module, so the Suspense boundary, the error boundary and the
module resolver were three failure modes guarding a feature with no user.
The card always draws the registered description and call to action.

Click tracking sent the translated button label, so the same click grouped
differently per locale. It sends a fixed value instead.
@adamwoodnz adamwoodnz removed [Status] In Progress Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code labels Nov 25, 2026
Phan reads the two identical adjacent calls the memo tests need as a
copy-paste mistake. Keeping each result and comparing them answers the
sniff and asserts the half the call count cannot: that the second caller
is handed the first one's list rather than an equal one computed again.
@adamwoodnz

Copy link
Copy Markdown
Contributor Author

The extension point is gone. Nothing outside the package registers a promo and nothing is scheduled to, so register_promo() is now @internal, fires on no action, and carries no version. What is left is a seam a later placement or promo plugs into, not a contract this PR has to keep.

Out with it: the registration action and the hydration step it needed, get_registered(), PROMO_PLACEMENTS, the slug-shape and type checks, the dismissible and own-module refusals for menu promos, and the whole render-module path, including PromoRenderProps and PromoCta from the barrels. 627 lines net.

The validation that remains is what the package's own promos need: a duplicate slug, an unknown placement, a placement's missing copy, and the http(s) check on a cta_url. That last one stays because it was a real bug rather than a guard against a hypothetical caller.

Also in this round: the flag registers in boot_shared_services(); the comments that still described the public version are rewritten; the click event sends a fixed cta rather than the translated label; and the flag test asserts on the registered definition, so removing the register call fails it.

The body's testing snippet registers on admin_init now, since there is no action to hook. Every thread has a reply.

It said registration refuses anything that is not a bool or a callable, so
reaching the fallback meant a callable had stopped resolving. Registration
stopped checking is_available when the validation went, so the fallback is
now the ordinary path for a bad value and the comment pointed a reader at a
guard that is not there.
Nothing hooks jetpack_premium_analytics_promos outside the tests written for
it, and with the registry internal nothing outside this package can. It was
the last of the extension-point surface, and the argument for dropping the
registration action covers it unchanged: a hook with no caller is a contract
we cannot exercise.

Two of the three tests it cost existed only to prove the gated list survived
a filter returning null or a non-Promo, which no longer has a way to happen.
Promos now come straight from the gates, re-indexed and sorted.
Both Parse.ly promos route availability through offers_parsely_prompts(),
which short-circuits on jetpack-stats-parsely-prompts ahead of every other
condition. That flag already turns the whole mechanism off: with nothing
available the slot publishes an empty list and the client mounts nothing. A
second flag in front of it was a third control on one card, and two switches
off by default is how a launch gets missed.

The one thing it did that the surviving flag does not is return before the
registry runs, which would mask a fatal in registration or in an
is_available callback. Tests cover that instead.
dognose24
dognose24 previously approved these changes Nov 26, 2026

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

Looks good after the trim. Three small things, none blocking.

The comment above the promos.php require in class-analytics.php still says other packages register into the slot, and the configure_promos() docblock still says the flag registers earlier. Both are left over from before a88094314.

The options menu item reports promo.cta_label as the click label, while the card reports a fixed cta. The menu value is translated, so the Tracks property will change with the site language. A fixed value there would match the card.

Heads up that this and #55476 both touch the same lines in class-analytics.php, so whichever lands second needs a rebase.

The options menu sent the menu item's own text as the Tracks click label,
and that text is translated, so the property would have grouped by site
language and fragmented the event across locales. It reports 'cta' now, the
same value the card sends. The placement already tells the two apart.

Also two comments left over from the flag removal: the promos require no
longer says other packages register into the slot, and configure_promos()
no longer says a flag registers earlier.
@adamwoodnz

Copy link
Copy Markdown
Contributor Author

Thanks, all three addressed in 0398540.

The Tracks label was the one with a real consequence, and it was worse than cosmetic: promo.cta_label is translated, so click events from the menu would have grouped by site language and the placement's clicks would have fragmented across every locale. It now sends a fixed 'cta', matching the card, and placement already tells the two apart. The assertion that pinned the old value carries a note saying why it is not the item's text.

Both leftover comments are gone: the promos.php require no longer claims other packages register into the slot, and the configure_promos() docblock no longer mentions a flag registering earlier.

On the rebase: agreed, and #55476 is the one that will move. It deletes the block in class-analytics.php that this PR edits, so merging this first leaves that one a small conflict to resolve in the direction of deletion. I will take care of it rather than leave it for a reviewer.

971 PHP tests and the 23 options-menu JS tests pass; PHPCS clean on both changed PHP files.

@adamwoodnz
adamwoodnz added this pull request to stack #55478 November 26, 2026 02:41
@adamwoodnz
adamwoodnz merged commit 1316650 into trunk Nov 26, 2026
112 of 113 checks passed
@adamwoodnz
adamwoodnz deleted the stats-657-add-a-promo-slot-extension-api-to-premium branch November 26, 2026 03:13
@github-actions github-actions Bot removed the [Status] Needs Review This PR is ready for review. label Nov 26, 2026
@louwie17

Copy link
Copy Markdown
Contributor

Thanks @adamwoodnz, appreciate the updates and iterations on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Docs Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Package] Premium Analytics RNA [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants