Premium Analytics: add Top posts & pages stats widget#49568
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
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. |
Private, source-consumed copy of @wordpress/grid until core publishes it.
Private, source-consumed copy of @wordpress/widget-primitives until core publishes it.
Private, source-consumed dashboard engine; depends on jetpack-widget-primitives and jetpack-grid.
Renders the WidgetDashboard engine via wp-build, bundling the grid/primitives/dashboard packages.
useWidgetTypes drives discovery via /wp/v2/widget-modules; hello-world builds as a lazy-loaded script module.
Hook the page boot-dependencies filter so widget modules reach the import map; move the endpoint to the jetpack/v4 namespace.
@wordpress/grid and widget-primitives references in widget-dashboard JSDoc/comments/README, per the faithful-source sync policy.
909996e to
d060b2d
Compare
Add the jpa/stats-top-posts dashboard widget (WOOA7S-1489), porting the Jetpack Stats "Top posts & pages" card: - widgets/top-posts: framed list widget rendering the leaderboard chart with post-title links; period/date/num hardcoded 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 - Link internal packages/* into node_modules so the wp-build widget phase can resolve @jetpack-premium-analytics/* imports (top-posts is the first widget to consume them; hello-world does not) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Align with the co-located __tests__ convention used by the package's internal packages/* instead of the one-off tests/ dir. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…troller Point the top-posts data layer at the jetpack-premium-analytics/v1/proxy controller (stats/top-posts) instead of building the jetpack/v4/stats-app URL with a client-side site ID. The proxy injects the connected blog ID and authenticates the upstream WPCOM request. Remove the now-unused site-id machinery: getStatsApiPath, the getJpaConfig helper / window.jpaConfig type, and the Config_Data PHP emitter (and its wiring in class-analytics.php). Also folds in this session's widget refinements: 7-day summarized range, overlay-label bar styling, and the "Top pages by views" title. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
f1a7fee to
2899350
Compare
…ts API
The Api_Proxy_Controller always forwarded to /sites/{id}/analytics/<endpoint>
on the v2 analytics API, so stats/top-posts 404'd upstream (Stats lives on the
v1.1 REST API). Route stats/* endpoints to /sites/{id}/stats/... on v1.1 (rest
base); all other endpoints keep targeting the v2 analytics namespace.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
d060b2d to
5bb6dd9
Compare
Fixes WOOA7S-1489
Proposed changes
Adds the
jpa/stats-top-postsdashboard widget to Premium Analytics, porting the Jetpack Stats "Top posts & pages" card. This is the kickoff Stats card port and establishes the pattern for the rest.widgets/top-posts/— new widget (framedpresentation): renders the top-viewed posts/pages as aLeaderboardChart(no comparison period), 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 and don't fit stats).packages/data):useReportTopPostshook — usesuseQuerydirectly (stats has no comparison concept in v1), client-side post-type filtering via thenameparam, 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, no new composer dependency. The hook'snum(post count) maps to the WPCOM API'smax; the API's ownnum(period count) is left at its default.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), attached as abeforeinline script on the generated*-prerequisiteshandle via the*_boot_dependenciesfilters so it lands before the boot module import in both generated page variants.packages/*intonode_modules(link:deps) so the wp-build widget phase can resolve@jetpack-premium-analytics/*imports.top-postsis the first widget to consume internal packages (hello-world does not), so this path wasn't exercised before. Also exportsWidgetLoadingOverlayfrom widgets-toolkit and includeswidgets/**intsconfig.json/ stubs node_modules CSS in the jest config.Notes for reviewers:
pnpm typecheckcurrently reports errors in the vendoredwidget-primitives/widget-dashboardjs-packages on this base branch — these are pre-existing (reproducible onupdate/pa-introduce-customize-dashboardwithout this PR) and unrelated to the widget; none of the errors are in the widget or data-package files.Related product discussion/links
update/pa-introduce-customize-dashboardafter the required packages landed there).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 build— confirmstop-postsbuilds and registers asjpa/stats-top-postsinbuild/widgets/registry.php.Manual:
window.jpaConfig = { siteId, apiRoot, nonce }appears before the boot module import script.