WOOA7S-1497: add Videos widget backed by Jetpack Stats#49573
WOOA7S-1497: add Videos widget backed by Jetpack Stats#49573Nikschavan wants to merge 3 commits into
Conversation
|
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! 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. |
5bb6dd9 to
7ff7f71
Compare
7ff7f71 to
22e10a7
Compare
Show the most-played videos via the Stats video-plays endpoint (through the stats-admin proxy), plus a Storybook mock for the endpoint.
9035839 to
405994b
Compare
Code Coverage SummaryThis 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. 🤷 |
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.
There was a problem hiding this comment.
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/videoswidget definition (TS + JSON), render entry, Storybook stories, and a data-to-leaderboard transformer with unit tests. - Extends Storybook report mocks to return realistic
video-playsresponses (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. |
| /** | ||
| * 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 ); | ||
| } |
| 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 ) ); |
Proposed changes
Ports the Videos widget from the Jetpack Stats module into the Premium Analytics dashboard, backed by the Jetpack Stats API.
stats-fetchAPI client that goes through the stats-admin proxy (/jetpack/v4/stats-app/sites/{blog_id}/stats/{resource}), plusstatsQuery/statsVideoPlaysQueryquery builders anduseStatsVideoPlays/useStatsBlogIdhooks. The blog ID is resolved once from/jetpack/v4/connection/dataand cached for the page lifetime; queries useskipTokenwhile the blog ID or report date is unresolved.VideosWidget(leaderboard chart of most played videos with comparison support) and abuildVideoPlaysDatahelper, with loading/refetching overlays and empty/error states.jpa/videosdashboard widget (render entry,widget.json,widget.tswith a configurablemaxattribute). The render entry defaults to an all-time report range until the host can pass the site launch date.withDevtoolsprop so React Query devtools render once at the page level instead of per widget.videoicon 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
/jetpack/v4/stats-app/sites/{blog_id}/stats/video-plays).Maximum videosattribute and verify the list respects the limit.