feat(web): turn Deco Analytics on from the Monitor, with an install check (UI only)
What is this contribution about?
Stacked on #8332. This is the part of the Monitor redesign that adds Deco Analytics to a site. It was split out because every site that sends Deco Analytics costs deco, so it should only ship once deco decides to offer it. Until then, #8332 shows "Deco Analytics is coming soon" wherever this flow would appear.
This PR replaces that "coming soon" card with:
- Turn on Deco Analytics. The onboarding. Deco decides what is collected: there is no module picker, and every registration uses the default modules. Two ways in:
- The agent: creates the task that adds the script (
ANALYTICS_INSTALL) and opens a PR. - Manual: where the site runs (deco's CDN or somewhere else), then the script to paste, with CSP and purchase tracking.
- The agent: creates the task that adds the script (
- Install check on the Analytics page, after either path:
- While waiting: white, with a spinner, "Verifying your installation".
- When a visit arrives: "Your installation works".
- After 30 minutes with no visit: yellow, "We haven't seen any visits yet", with Review installation. It reopens the modal and goes straight to the script.
- It can be dismissed.
- Turn-on card at the top of Analytics for sites still on OneDollarStats.
- The agent's "Install" button in the analytics connect card, and the card listing sites that don't send analytics yet.
- Settings → Analytics: the registration form and the collection editor stop listing modules. The editor keeps the modules a site already has.
UI only: the diff touches only apps/web.
What may not make sense once it's connected
-
"On deco's CDN" path. Step 3 says to paste
<script async src="/_dq/a.js">, followingtools/analytics/instruction.ts. If the CDN injects the tag by itself for a host-registered site, that step should say "nothing to add". -
After registering. The status flips to
registered, so the page behind the dialog switches to the Deco sections before any event exists. -
Token mode. The public token is shown only in the install step. In Review installation, the tag is built from
status.key; without the key, it falls back to the same-origin tag. -
Install check. It is UI only:
- it remembers when the install started in
localStorage(monitor:analytics-verify:<site>); - it polls
analytics/data?view=liveevery 5 s; - it calls the install late after 30 minutes.
The agent path needs a PR merged and deployed first, so 30 minutes may fire too early there. A server-side "first event at" would make the check exact and work across browsers.
- it remembers when the install started in
How did you verify your code works?
tsc --noEmitinapps/web,bun run lintandbun run knipare clean.- The branch is exactly the revert of #8332's "coming soon" commit: the same code that was reviewed there before the split.
- Screens were checked in the local scenario stack before the split. They aren't re-recorded here, because the local Docker environment is down.
Screenshots/Demonstration
Not attached: the local Docker environment went down. The flow is best reviewed against a project without Deco Analytics.
How to Test
- Open a project without Deco Analytics → Analytics. Expect the empty card with Turn on.
- Choose "Add it myself" → set up → see the script. Click Done: the Analytics page shows "Verifying your installation".
- With a linked GitHub repository, choose "Let the agent add it". Expect the task to open.
- For a site reporting to OneDollarStats, expect the turn-on card at the top of Analytics.
Migration Notes
None beyond #8332's.
Review Checklist
- PR title is clear and descriptive
- Changes are tested and working
- Documentation is updated (if needed)
- No breaking changes
🤖 Generated with Claude Code
Summary by cubic
Replaces the "Deco Analytics is coming soon" placeholder in the Monitor with the real onboarding flow: sites can now turn on Deco Analytics from the Analytics page, with two install paths and a live install check. UI only — the diff touches just apps/web.
New Features
- Adds a "Turn on Deco Analytics" flow with two paths: the agent creates a
ANALYTICS_INSTALLtask and opens a PR, or the site owner pastes a script manually (with CSP and purchase tracking steps). - Adds an install check banner that polls the live view every 5 s: white with a spinner while verifying, green once the first visit counts, and yellow with a "Review installation" button after 30 minutes of no visits.
- Shows a turn-on card for sites still reporting to OneDollarStats and a card listing sites not sending analytics yet in the org view.
Refactors
- Removes the module picker from registration and from Settings → Analytics; Deco now decides what is collected, and existing sites keep the modules they already have.