Skip to content

Premium Analytics: route stats/* proxy endpoints to the v1.1 Stats API#49576

Draft
louwie17 wants to merge 1 commit into
trunkfrom
fix/pa-proxy-stats-routing
Draft

Premium Analytics: route stats/* proxy endpoints to the v1.1 Stats API#49576
louwie17 wants to merge 1 commit into
trunkfrom
fix/pa-proxy-stats-routing

Conversation

@louwie17

Copy link
Copy Markdown
Contributor

Proposed changes

The Api_Proxy_Controller (jetpack-premium-analytics/v1/proxy/<endpoint>) always forwarded to /sites/{id}/analytics/<endpoint> on the v2 analytics API. Jetpack Stats endpoints such as stats/top-posts live on the v1.1 Stats REST API (/sites/{id}/stats/top-posts, rest base), so proxying them returned a rest_no_route 404 from WPCOM.

This routes stats/* endpoints to /sites/{id}/stats/... on v1.1 (rest base); all other endpoints continue to target the v2 analytics namespace. The endpoint-validation guard is unchanged (still rejects traversal/absolute/scheme).

Why

The Premium Analytics dashboard's "Top posts & pages" widget consumes the v1.1 Stats top-posts payload and needs to reach it through the proxy controller (which injects the blog ID + auth server-side). Without this, the widget's request 404s.

Testing instructions

  • cd projects/packages/premium-analytics && composer phpunit -- --filter 'Api_Proxy_Controller' — 17 passing (includes new resolve_upstream routing tests).
  • On a Jetpack-connected site, an authenticated GET to /wp-json/jetpack-premium-analytics/v1/proxy/stats/top-posts?period=day&date=YYYY-MM-DD&max=10&summarize=1 returns HTTP 200 with the {summary:{postviews:[…]}} payload (was 404 before).

🤖 Generated with Claude Code

…ts API

Api_Proxy_Controller forwarded every proxied request to
/sites/{id}/analytics/<endpoint> on the v2 analytics API, so Jetpack Stats
endpoints such as 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>
@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 🤖


🔴 Action required: We would recommend that you add a section to the PR description to specify whether this PR includes any changes to data or privacy, like so:

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

My PR adds *x* and *y*.

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!

@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
@jp-launch-control

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/premium-analytics/src/REST/class-api-proxy-controller.php 72/127 (56.69%) 7.97% -5 💚

Full summary · PHP report

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

Labels

[Package] Premium Analytics [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant