Skip to content

WOOA7S-1497: add Videos widget backed by Jetpack Stats#49573

Open
Nikschavan wants to merge 3 commits into
trunkfrom
wooa7s-1497-port-jetpack-stats-module-videos
Open

WOOA7S-1497: add Videos widget backed by Jetpack Stats#49573
Nikschavan wants to merge 3 commits into
trunkfrom
wooa7s-1497-port-jetpack-stats-module-videos

Conversation

@Nikschavan

@Nikschavan Nikschavan commented Jun 12, 2026

Copy link
Copy Markdown
Member

Proposed changes

Ports the Videos widget from the Jetpack Stats module into the Premium Analytics dashboard, backed by the Jetpack Stats API.

Google Chrome -2026-06-30 at 20 19 41@2x
  • data package: adds a stats-fetch API client that goes through the stats-admin proxy (/jetpack/v4/stats-app/sites/{blog_id}/stats/{resource}), plus statsQuery/statsVideoPlaysQuery query builders and useStatsVideoPlays/useStatsBlogId hooks. The blog ID is resolved once from /jetpack/v4/connection/data and cached for the page lifetime; queries use skipToken while the blog ID or report date is unresolved.
  • widgets-toolkit: adds VideosWidget (leaderboard chart of most played videos with comparison support) and a buildVideoPlaysData helper, with loading/refetching overlays and empty/error states.
  • premium-analytics plugin: registers the jpa/videos dashboard widget (render entry, widget.json, widget.ts with a configurable max attribute). The render entry defaults to an all-time report range until the host can pass the site launch date.
  • chart empty state: centers the empty state across the full widget width instead of the chart column.
  • query client provider: adds a withDevtools prop so React Query devtools render once at the page level instead of per widget.
  • icons: adds a video icon used for the chart empty state.

Note: the diff also carries the "add dynamic widget registry and REST endpoint" commit until the base branch catches up with it.

Related product discussion/links

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

No.

Testing instructions

  • Set up a Jetpack-connected site with the Premium Analytics plugin active, ideally one with VideoPress/video traffic.
  • Go to the Premium Analytics dashboard and open the widget picker.
  • Add the Videos widget.
  • Verify it renders a leaderboard of the most played videos, sourced from Jetpack Stats (check the network tab for requests to /jetpack/v4/stats-app/sites/{blog_id}/stats/video-plays).
  • Change the Maximum videos attribute and verify the list respects the limit.
  • On a site with no video plays, verify the empty state copy renders centered across the widget instead of the chart.

@github-actions

github-actions Bot commented Jun 12, 2026

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!


Premium Analytics plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jun 12, 2026
@nerrad nerrad force-pushed the update/pa-introduce-customize-dashboard branch 2 times, most recently from 5bb6dd9 to 7ff7f71 Compare June 17, 2026 11:19
@louwie17 louwie17 force-pushed the update/pa-introduce-customize-dashboard branch from 7ff7f71 to 22e10a7 Compare June 19, 2026 12:21
Show the most-played videos via the Stats video-plays endpoint (through the stats-admin proxy), plus a Storybook mock for the endpoint.
@Nikschavan Nikschavan force-pushed the wooa7s-1497-port-jetpack-stats-module-videos branch from 9035839 to 405994b Compare June 30, 2026 13:58
@Nikschavan Nikschavan changed the base branch from update/pa-introduce-customize-dashboard to trunk June 30, 2026 13:58
@jp-launch-control

Copy link
Copy Markdown

Code Coverage Summary

This PR did not change code coverage!

That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷

Full summary · PHP report

Forward the dashboard setError handler to WidgetRoot, and rename toPositiveInt to toMaxRows so max=0 (all rows per the Stats widget contract) passes through instead of falling back to the default.
@Nikschavan Nikschavan marked this pull request as ready for review June 30, 2026 14:49
@Nikschavan Nikschavan requested review from a team as code owners June 30, 2026 14:49
Copilot AI review requested due to automatic review settings June 30, 2026 14:49

Copilot AI 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.

Pull request overview

Adds a new Videos dashboard widget to the Premium Analytics experience, sourcing “most played videos” data from the Jetpack Stats API and wiring it into the existing widget + report-query infrastructure.

Changes:

  • Introduces the jpa/videos widget definition (TS + JSON), render entry, Storybook stories, and a data-to-leaderboard transformer with unit tests.
  • Extends Storybook report mocks to return realistic video-plays responses (including comparison-window scaling).
  • Adds a Premium Analytics changelog entry documenting the new widget.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
projects/packages/premium-analytics/widgets/videos/widget.ts Defines the jpa/videos widget type and configurable max attribute.
projects/packages/premium-analytics/widgets/videos/widget.json Declares widget metadata (title/description/category/presentation).
projects/packages/premium-analytics/widgets/videos/stories/videos-widget.stories.tsx Adds Storybook stories (standalone + dashboard harness) for the Videos widget.
projects/packages/premium-analytics/widgets/videos/render.tsx Implements the data-connected widget render (fetch, loading/refetch overlays, error/empty/populated states).
projects/packages/premium-analytics/widgets/videos/package.json Adds the widget package and its dependencies.
projects/packages/premium-analytics/widgets/videos/build-video-plays-data.ts Transforms Stats “video-plays” reports into LeaderboardChart rows (with comparison alignment).
projects/packages/premium-analytics/widgets/videos/tests/build-video-plays-data.test.ts Unit tests for the video plays data transformer.
projects/packages/premium-analytics/packages/widgets-toolkit/src/stories/mocks/register-report-mocks.ts Adds a video-plays mock response generator for Storybook.
projects/packages/premium-analytics/changelog/add-pa-videos-widget Changelog entry announcing the Videos widget.

Comment on lines +24 to +34
/**
* Resolve the key used to align a video across the primary and comparison
* periods. Prefers the stable post ID and falls back to the display label when
* the API omits one.
*
* @param video - The video-plays item.
* @return The alignment key.
*/
function getVideoKey( video: StatsVideoPlaysItem ) {
return video.id != null ? String( video.id ) : getVideoLabel( video );
}
Comment on lines +532 to +538
const end = new Date( `${ endDate }T00:00:00` ).getTime();

if ( Number.isNaN( end ) ) {
return 1;
}

const daysAgo = Math.max( 0, ( Date.now() - end ) / ( 24 * 60 * 60 * 1000 ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants