Skip to content

UNI-1088: Premium Analytics: Add the Bot activity widget to the AI tab - #55485

Draft
Nikschavan wants to merge 4 commits into
add/uni-1086-top-ai-companiesfrom
add/uni-1088-bot-activity
Draft

Nikschavan wants to merge 4 commits into
add/uni-1086-top-ai-companiesfrom
add/uni-1088-bot-activity

Conversation

@Nikschavan

Copy link
Copy Markdown
Member

Fixes UNI-1088

Proposed changes

Builds on #55334 (Top AI companies), which builds on #55331. This PR's own change is the last commit; the earlier commits belong to #55334.

  • Add the Bot activity widget to the AI tab, beside Top AI companies. It ranks the bots that requested the site in six groups (AI training, AI search, AI assistants & agents, Search engines, Other known bots and Unidentified bots), and a group opens onto its bots.
  • The data comes from stats/ua-queries with the bot-class-and-name template. The template requires bot_category (ai or non-ai) and has no value for both, so the widget sends one request for each and ranks the groups of both together. The template's class_pct and bot_pct are computed within one half, so they cannot be compared across the two and the widget does not use them.
  • The template returns the edge's traffic classes, not the six groups, so the widget maps them in build-bot-groups.ts, with the mapping from UNI-1088. This is a bridge until the template returns the groups itself (DLINK-570); the mapping and the second request go away then. A bot the edge files under two classes of one group, such as Perplexity-User under both AI Assistant and AI Agent, shows as one row.
  • When one of the two requests fails on its first load, the widget shows the error instead of half of the groups, which would rank them as if the other half had no bots. A failed refresh keeps the groups on screen. Errors go through describeError(), so an access error does not offer a Retry that cannot help.
  • A range longer than 366 days sends no request and asks for a shorter period, because the endpoint refuses it. The limit moves into edge-window.ts as EDGE_ROLLUP_MAX_DAYS, and Requests by source reads the same constant.
  • The tab stays behind the jetpack-stats-ai-tab flag, so nothing changes for any site.

Open questions this PR does not settle, all on UNI-1088:

  • The edge's Software Library class (HTTP libraries, mostly a site's own systems calling its REST API) lands in Other known bots. On a large news site that makes it the biggest group, with a bot named WordPress at the top.
  • Generic Feed Fetcher counts under Other known bots, not Unidentified bots.
  • Blocked requests are included, while Top AI companies is meant to count served requests only.

The template takes whole days, so for Last 24 hours the widget counts the whole UTC days the window touches. The post page is a separate PR (UNI-1091).

On a local site with made-up data:

Groups A group opened
The Bot activity widget listing six bot groups with their request counts The AI assistants and agents group opened onto ChatGPT-User, Claude-User and Perplexity-User, with an All groups back link
The six groups, most requests first AI assistants & agents opened; Perplexity-User is one row

Related product discussion/links

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

No.

Testing instructions

The data only exists for VIP sites and the tab is behind the flag, so use Storybook.

  • cd projects/js-packages/storybook && pnpm run storybook:dev
  • Open Packages / Premium Analytics / Widgets / Bot activity.
  • Default lists six groups, Search engines first and AI assistants & agents last.
  • Select AI assistants & agents. It lists ChatGPT-User and Perplexity-User under an "All groups" back link, with Perplexity-User as one row.
  • Select All groups to go back.
  • Loading, Error, Error Retryable and Empty show the widget's states. Error shows "You don't have access to this data." with no Retry.
  • Widget Dashboard With Widget shows it in the dashboard frame.

What I ran:

  • The new Jest suites pass: the group mapping, and the widget rendered through apiFetch, so the hook, the query and the sanitizer run too. Each guard the widget adds (the error on one failed first load, the rows kept after a failed refresh, the error copy and the long-range check) makes its test fail when it is removed.
  • jp test php packages/premium-analytics, tsgo --noEmit, ESLint and PHPCS are clean.
  • On a local site I served made-up rows for both halves of the template from a mu-plugin, and looked at the AI tab in Chrome: the six groups, a group's bots and the way back.

Not checked:

  • The real endpoint. The response shape comes from reading the query template and from running it against the edge tables on a sandbox.
  • I have not opened the Storybook stories in a browser.

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

github-actions Bot commented Nov 26, 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 add/uni-1088-bot-activity branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/uni-1088-bot-activity

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 26, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

No summary data is available for parent commit 953408a, so cannot calculate coverage changes. 😴

If that commit is a feature branch rather than a trunk commit, this is expected. Otherwise, this should be updated once coverage for 953408a is available.

Full summary · PHP report · JS report

@Nikschavan
Nikschavan changed the base branch from trunk to add/uni-1086-top-ai-companies November 26, 2026 08:32
@Nikschavan
Nikschavan force-pushed the add/uni-1088-bot-activity branch from dff1216 to ee3fede Compare November 27, 2026 09:37
Ranks the bots that requested the site in six groups, from AI training to unidentified bots, from the two halves of the bot-class-and-name template. The groups are mapped in the client until the template returns them (DLINK-570).
The template returns the six groups in one request, in display order, with served requests only, so the widget no longer maps edge classes or merges two halves. Ranges ending in the last two UTC days read the raw table, since the rollup has no rows for them yet.
… grows past a year

Stats queries keep the previous range's data as a placeholder, so a range too long to request showed the old groups instead of the message. Also test the rollup cutoff for a short past window and the single request when the host passes comparison dates.
@Nikschavan
Nikschavan force-pushed the add/uni-1088-bot-activity branch from ee3fede to f0ee062 Compare November 27, 2026 09:48
Groups pair by key and bots by name within their group. A bot outside the comparison period's top bots has no previous value, since the template returns only the top bots of each group.

This branch has not been deployed

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant