Premium Analytics: add Top posts & pages stats widget#49508
Open
louwie17 wants to merge 33 commits into
Open
Conversation
…' into wooa7s-1319-base-all-deps
…d ciab-admin packages
…eact-native peer issue
Port the Jetpack Stats "Top posts & pages" card as the jpa/stats-top-posts dashboard widget (WOOA7S-1489): - widgets/top-posts: framed list widget rendering the leaderboard chart with post-title links, hardcoded period/date/num defaults for v1 - data package: useReportTopPosts hook (useQuery directly, no comparison), top-posts fetcher against the existing jetpack/v4/stats-app proxy, and getJpaConfig() reading the new window.jpaConfig boot config - Config_Data PHP class emits window.jpaConfig (siteId, apiRoot, nonce) before the boot script on both generated page variants Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
| Are you an Automattician? The PR will need to be tested on WordPress.com. This comment will be updated with testing instructions as soon the build is complete. |
Contributor
|
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. |
Base automatically changed from
wooa7s-1319-integrate-widgets-toolkit-package-into-analytics
to
trunk
June 10, 2026 23:16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes WOOA7S-1489
Proposed changes
Ports the Jetpack Stats "Top posts & pages" card to Premium Analytics as the
jpa/stats-top-postsdashboard widget. This is the kickoff Stats card port, establishing the pattern for the rest of the Stats cards.widgets/top-posts/— new widget (framedpresentation): renders the top-viewed posts/pages for the site as aLeaderboardChart(no comparison period), with each row label linking to the published post in a new tab. Period/date/count are hardcoded for v1 via attribute defaults (period: day,num: 10, date = today in the site timezone, computed at render time). Attributes flow to the inner component via props, notWidgetRootContext(whose report params are WC-Analytics-shaped).packages/data):useReportTopPostshook — usesuseQuerydirectly (stats has no comparison concept in v1), client-side post-type filtering via thenameparam, and returns normalized{ label, value, href, type }rows (a port of Calypso'sstatsTopPostsnormalizer minus the Calypso UI fields).fetchReportTopPostsfetcher against the existingjetpack/v4/stats-app/sites/{site_id}/stats/top-postsproxy provided by thejetpack-stats-adminpackage — no new REST proxy and no new composer dependency. The hook'snum(post count) maps to the WPCOM API'smaxparam; the API's ownnummeans "number of periods" and is left at its default of 1.getJpaConfig()util reading the newwindow.jpaConfigboot config, plusgetStatsApiPath()building the proxy base path from the runtime site ID.Config_DataPHP class — emitswindow.jpaConfig = { siteId, apiRoot, nonce }(a much smaller take on stats-admin'sOdyssey_Config_Data). It attaches as abeforeinline script on the generated*-prerequisitesscript handle via the*_boot_dependenciesfilters, which fire right after the handle is registered in both generated page variants (the full-page interceptor never firesadmin_print_scripts).WidgetLoadingOverlayfrom widgets-toolkit, includewidgets/**intsconfig.json, stub node_modules CSS imports in the jest config, and add@testing-library/reactas a devDependency.Notes for reviewers:
widget-modules.php, the widget dashboard stage) is landing separately; this PR follows itswidgets/<name>/{widget.json,widget.ts,render.tsx}conventions so the widget is discovered once that work merges.Related product discussion/links
Does this pull request change what data or activity we track or use?
No. It reads existing Jetpack Stats data through the existing
jetpack-stats-adminREST proxy.Testing instructions
Automated:
cd projects/packages/premium-analytics && pnpm test— fetcher URL-composition tests and widget smoke tests (render, post-type filtering, empty state).pnpm typecheckin the same directory.Manual (requires the widget dashboard branch for full rendering; until then the pieces can be verified in isolation):
window.jpaConfig = { siteId, apiRoot, nonce }appears before the boot module import script.fetchthe proxy path from the config (<apiRoot>jetpack/v4/stats-app/sites/<siteId>/stats/top-posts?period=day&date=<today>&max=10with theX-WP-Nonceheader) and confirm it returns adayspayload.