Premium Analytics: route stats/* proxy endpoints to the v1.1 Stats API#49576
Draft
louwie17 wants to merge 1 commit into
Draft
Premium Analytics: route stats/* proxy endpoints to the v1.1 Stats API#49576louwie17 wants to merge 1 commit into
louwie17 wants to merge 1 commit into
Conversation
…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>
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 🤖 🔴 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: Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 1 file.
|
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.
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 asstats/top-postslive on the v1.1 Stats REST API (/sites/{id}/stats/top-posts,restbase), so proxying them returned arest_no_route404 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-postspayload 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 newresolve_upstreamrouting tests)./wp-json/jetpack-premium-analytics/v1/proxy/stats/top-posts?period=day&date=YYYY-MM-DD&max=10&summarize=1returns HTTP 200 with the{summary:{postviews:[…]}}payload (was 404 before).🤖 Generated with Claude Code