fix(monitor): show a project's analytics for sites deco doesn't host
Merged
PE
7d ago+136+136+012345678901234567890123456789-41-41-01234567890123456789
What is this contribution about?
A project whose site runs on another platform gets Deco Analytics through ANALYTICS_INSTALL, which stores the registration on the project (metadata.decoAnalytics), never in org_sites. #8345/#8346 taught the hosting analytics routes to read that registration, so the org Monitor counts the site's pageviews. Inside the project, two surfaces still required org_sites ownership:
- Metrics → Audience stayed on its "Coming soon" placeholder:
GET /order-monitor/traffic?site=answered 404 "Site not found in organization". - Analytics rendered the CDN Monitor (
CdnTab), whose/monitor/:site/*routes also requireorg_sites, so it showed "Couldn't load CDN analytics — Site not found in organization".
Changes:
analyticsAccessmoves fromhosting.tstoapps/api/src/analytics/access.ts, unchanged, and the traffic route uses it: an owned slug reads its control-plane registration as before; an external one uses the warehouse id its project carries. A failed project lookup answers 502, not 404.- The project's Analytics view renders the Deco Analytics tab (
AnalyticsTab) when the project carries an external registration. Such a site never reaches the deco CDN, so the CDN Monitor has nothing to show. Owned sites keep the CDN Monitor.
How did you verify your code works?
- Added
apps/api/src/analytics/access.test.ts: owned slug, external registration, project without registration, unknown slug, failed lookup.bun test apps/api/src/analytics/ apps/api/src/api/routes/hosting.test.ts: 12 pass. oxlint,biome format,knip, andtsc --noEmitforapps/apiandapps/webare clean.- Read-only prod check on the affected project: it carries
decoAnalyticsand has noorg_sitesrow, which matches both 404s. - Not run: the full
bun testsuite in this fresh worktree (it fails broadly there for environmental reasons, such as oxlint plugin tests reading empty output), and no UI run against real data. CI covers the suite.
Screenshots/Demonstration
No UI change for owned sites. For an external site, the project's Analytics view shows the existing Deco Analytics tab instead of the CDN error.
How to Test
- Open a project whose site deco doesn't host and that has Deco Analytics installed.
- Monitor → Metrics: the Audience card shows the site's visitors instead of "Coming soon".
- Monitor → Analytics: the Deco Analytics view loads instead of "Couldn't load CDN analytics".
- Open a project hosted by deco: both views behave as before.
Review Checklist
- PR title is clear and descriptive
- Changes are tested and working
- Documentation is updated (if needed)
- No breaking changes
Summary by cubic
The project Monitor now shows audience and analytics data for sites deco doesn't host, instead of the "Coming soon" and "Couldn't load CDN analytics" fallbacks.
- The traffic route now resolves registrations through a shared
analyticsAccesshelper: owned sites read their control-plane registration as before, external sites use the registration their project carries, and a failed project lookup answers 502 instead of 404. - The project's Analytics view renders the existing Deco Analytics tab for externally hosted sites, which never reach the deco CDN; owned sites keep the CDN Monitor.