Skip to content

Content Gap Suggestions: shared Stats_Provider layer + dashboard widget (1/2 for #338) - #929

Merged
dkotter merged 23 commits into
WordPress:developfrom
zeus2611:feature/issue-338-content-gap-suggestions
Nov 4, 2026
Merged

dkotter merged 23 commits into
WordPress:developfrom
zeus2611:feature/issue-338-content-gap-suggestions

Conversation

@zeus2611

@zeus2611 zeus2611 commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

What?

See #338 (1 of 2 PRs — Traffic Surge Amplification follows separately)

Adds the Content Gap Suggestions experiment: a dashboard widget that surfaces new post topic ideas based on anonymized search patterns from a connected analytics plugin (Jetpack Stats for v1). Also adds the shared Stats_Provider abstraction and anonymization layer that PR 2 (Traffic Surge Amplification) will build on.

Why?

Issue #338 asks for two AI-assisted editorial signals sourced from site analytics: content gaps (this PR) and traffic-spike amplification (follow-up PR). The issue explicitly scoped v1 to Jetpack Stats only, a dashboard widget over an admin page, and no on-site search-log fallback — all reflected here. Any resulting draft must require human review before publishing, so suggestions only ever create a WordPress draft; nothing is published or posted automatically.

How?

  • includes/Stats/Stats_Provider.php — interface for analytics adapters (is_available(), get_search_queries(), get_post_traffic())
  • includes/Stats/Stats_Provider_Registry.php — resolves the first available provider; extensible via wpai_stats_providers filter
  • includes/Stats/Providers/Jetpack_Stats_Provider.php — wraps stats_get_from_restapi(). Note: Jetpack's search-terms data is external search-engine referrer terms, not on-site search queries — used here as a proxy signal for content gaps, not a literal zero-result-search report (Jetpack has no on-site search tracking)
  • includes/Stats/Anonymizer.php — the AI-safety boundary: drops low-count/single-occurrence terms, strips anything that looks like an email or long digit run (phone/order IDs), normalizes and merges the rest into aggregate patterns. Only these patterns are sent to the AI provider — raw query strings never leave this layer
  • includes/Experiments/Content_Gap_Suggestions/ + includes/Abilities/Content_Gap_Suggestions/ — the experiment and its ability, following the existing Abstract_Feature/Abstract_Ability pattern used elsewhere in the plugin. Structured JSON output via as_json_response()
  • includes/Admin/Dashboard/Content_Opportunities_Widget.php — dashboard widget, gated on the experiment being enabled. Renders only a mount point + "Generate" button; loading the dashboard never triggers an AI call, only clicking does
  • Frontend (src/experiments/content-gap-suggestions/): generate → list suggestions → "Create Draft" (creates a real post_status: draft post via REST and opens it in the editor) or "Dismiss"

Use of AI Tools

AI assistance: Implementation was planned with assistance from Claude Code (Anthropic). All code was reviewed, tested, and validated.

Testing Instructions

  1. npm install && composer install

  2. npm run build

  3. Enable Experiments globally, then enable "Content Gap Suggestions" (Settings → AI)

  4. Connect an AI provider (OpenAI or Google)

  5. Jetpack Stats won't have real data on a fresh install, so add a throwaway must-use plugin that registers a fake stats provider. Save this as wp-content/mu-plugins/fake-stats-provider.php (no activation needed, delete it afterwards):

    <?php
    add_filter( 'wpai_stats_providers', function ( array $providers ): array {
    	$providers[] = new class() implements \WordPress\AI\Stats\Stats_Provider_Interface {
    		public function get_id(): string {
    			return 'fake-stats';
    		}
    		public function is_available(): bool {
    			return true;
    		}
    		public function get_search_queries( array $args = array() ) {
    			return array(
    				array( 'term' => 'how to start a vegetable garden', 'count' => 5 ),
    				array( 'term' => 'how to start a vegetable garden', 'count' => 3 ),
    				array( 'term' => 'best low maintenance houseplants', 'count' => 4 ),
    			);
    		}
    		public function get_post_traffic( int $post_id, array $args = array() ) {
    			return array();
    		}
    	};
    	return $providers;
    } );
  6. Dashboard → Content Opportunities widget → Generate suggestions

  7. Confirm a suggestion appears with title + outline

  8. Click Create draft → confirm it opens in the editor with the title pre-filled and status is Draft (not published)

  9. Click Dismiss on another suggestion → confirm it's removed from the list

  10. To check the error state, make the AI call fail (for example, disconnect the AI provider) and click Generate suggestions → confirm the error message shows above Try again

  11. Delete the mu-plugin and reload the Dashboard → confirm the widget no longer appears (no stats provider available)

  12. Optional, with a real site: install and connect Jetpack with the Stats module on, and confirm the widget appears and returns suggestions. Jetpack only reports search terms from external search engines, so the site needs recent traffic.

Screenshots or screencast

Before After
(no widget) Screenshot 2026-08-11 at 11 57 35 PM Screenshot 2026-08-11 at 11 56 52 PM Screenshot 2026-08-11 at 11 57 06 PM

Changelog Entry

Added - Content Gap Suggestions experiment: a dashboard widget that surfaces AI-generated post topic ideas from anonymized site search patterns (via Jetpack Stats), with a draft-only workflow requiring human review before publishing.

Open WordPress Playground Preview

- Shared Stats_Provider abstraction, Jetpack Stats adapter, and Anonymizer
- Content Gap Suggestions experiment, ability, and dashboard widget
- PHPUnit + e2e coverage; phpstan/phpcs clean
@codecov

codecov Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.25982% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.08%. Comparing base (b2f708b) to head (aed997a).

Files with missing lines Patch % Lines
...ontent_Gap_Suggestions/Content_Gap_Suggestions.php 93.89% 8 Missing ⚠️
...ncludes/Stats/Providers/Jetpack_Stats_Provider.php 88.05% 8 Missing ⚠️
...s/Admin/Dashboard/Content_Opportunities_Widget.php 87.50% 1 Missing ⚠️
includes/Stats/Search_Term_Filter.php 97.77% 1 Missing ⚠️
includes/Stats/Stats_Provider_Interface.php 0.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop     #929      +/-   ##
=============================================
+ Coverage      84.90%   85.08%   +0.17%     
- Complexity      4727     4826      +99     
=============================================
  Files            182      189       +7     
  Lines          17572    17903     +331     
=============================================
+ Hits           14920    15232     +312     
- Misses          2652     2671      +19     
Flag Coverage Δ
unit 85.08% <94.25%> (+0.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jeffpaul jeffpaul modified the milestones: 1.4.0, Future Release Aug 12, 2026
@zeus2611
zeus2611 marked this pull request as ready for review August 23, 2026 13:46
@zeus2611
zeus2611 requested a review from a team August 23, 2026 13:46
@github-actions

github-actions Bot commented Aug 23, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: zeus2611 <n1schay@git.wordpress.org>
Co-authored-by: dkotter <dkotter@git.wordpress.org>
Co-authored-by: jeffpaul <jeffpaul@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

…8-content-gap-suggestions

# Conflicts:
#	tests/e2e-testing/e2e-testing.php
@zeus2611

Copy link
Copy Markdown
Contributor Author

@jeffpaul CI is passing. It's ready for review whenever you have the chance.

@jeffpaul jeffpaul modified the milestones: Future Release, 1.5.0 Sep 21, 2026
@jeffpaul
jeffpaul requested a review from dkotter September 29, 2026 13:44
…ions

- Drop removed enableExperiments helper from the e2e spec
- Dismiss the welcome guide reliably in the create-draft test
- Add Jetpack provider and ability tests with a Jetpack Stats stub
- Make ability registration test independent of test order
…ase labels

- Require manage_options in the ability and script enqueue to match the dashboard widget gate
- Rename 'Create Draft' to 'Create draft'
@zeus2611

zeus2611 commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

@dkotter CI is green and this is ready for review whenever you have the chance.

@jeffpaul jeffpaul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not able to test this quickly (@zeus2611 if you can share the snippet in the PR description for others to try and load in test info), so this comment focuses more on the null/empty state...

Image

After clicking the Generate suggestions button the preceding copy and button are updated to just a Try again button with no other info.

Image

If there's an error or warning that we can throw in this case to give a site owner a little more context on what's not working, that would be ideal.

zeus2611 and others added 2 commits October 10, 2026 14:38
Errors were sent to a snackbar that the dashboard never renders, leaving
only a 'Try again' button with no context. Render the message in an inline
notice and cover it with an e2e test.

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

I've given this an initial code review (haven't tested yet as I don't have an easy Jetpack enabled site to use) and have a handful of concerns.

We'll also want to ensure we get proper documentation here to match our other experiments.

Comment thread includes/Stats/Search_Term_Filter.php Resolved
Comment thread includes/Experiments/Experiments.php Resolved
- Use WPCOM_Stats instead of the deprecated stats_get_from_restapi and parse its real response shapes
- Require Jetpack to be connected with the Stats module active
- Rename Stats_Provider to Stats_Provider_Interface
- Validate filtered providers and skip invalid or duplicate IDs with _doing_it_wrong
- Drop formatted phone, SSN, and card numbers in the anonymizer
- Hide the dashboard widget when no stats provider is available
- Escape suggestion text before writing it into draft block markup
- Document the experiment and update the description
@zeus2611

Copy link
Copy Markdown
Contributor Author

@jeffpaul I've pushed updates:

  • Snippet for testing: added to the PR description under Testing Instructions, and also in the new experiment docs.
  • Try again with no other info: the widget now shows the actual error message in an inline notice above the button, with an e2e test covering it.

@zeus2611

Copy link
Copy Markdown
Contributor Author

@dkotter I've made all the requested changes, including the docs, and CI is green. Ready for another look whenever you have a chance.

Also, I couldn't test against a live Jetpack site, so @jeffpaul, if you have one, it would be great if you could try it there.

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

I do have a site with Jetpack connected (though very minimal traffic) and in testing, I couldn't get any results and just got the generic error No content opportunities found right now. Check back after more traffic data is available. I can test again if we can make some updates to return the actual error message, if there is one, to see if there's something else going on

…estions

- Prefer the summary over per-day search terms to avoid double counting
- Rename Anonymizer to Search_Term_Filter and drop anonymization wording
- Explain empty results in the widget instead of a generic message
@jeffpaul

Copy link
Copy Markdown
Member

At this point, I'd say let's address Darin's latest questions/code review feedback and then look to get this merged in for 1.5.0 to hopefully get more testing with folks using some connected stats providers with more data.

…ck test stub

- Drop get_post_traffic from the provider interface and Jetpack adapter; nothing uses it yet and it returned the whole history rather than a daily window
- Make the Jetpack checks and client overridable so tests no longer define fake Jetpack classes that stay loaded for the rest of the run
@jeffpaul jeffpaul mentioned this pull request Oct 28, 2026
31 of 46 tasks
@dkotter dkotter modified the milestones: 1.5.0, 1.6.0 Oct 28, 2026
zeus2611 and others added 5 commits October 30, 2026 17:44
…red abilities

The test re-fired wp_abilities_api_init, which re-registers every hooked ability. When another test had already registered one (for example alt-text generation) WordPress raised an 'already registered' notice. Fire only this experiment's registration instead.

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

Code-wise this looks good to me though I still haven't been able to get any results to show on the couple Jetpack-connected sites I've tested on. I'm assuming that's just due to lack of data on those sites (very low traffic, likely very little if any search traffic).

Based on @jeffpaul's comment here, I think next step is to merge this in and see if we can get any testing feedback from others.

@dkotter
dkotter merged commit 55f29cc into WordPress:develop Nov 4, 2026
36 checks passed
@zeus2611
zeus2611 deleted the feature/issue-338-content-gap-suggestions branch November 5, 2026 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New Experiments: Analytics-aware content and amplification recommendations

3 participants