Skip to content

feat: add form analytics to performance report - #547

Open
sajclarke wants to merge 1 commit into
mainfrom
feat/report-form-analytics
Open

sajclarke wants to merge 1 commit into
mainfrom
feat/report-form-analytics

Conversation

@sajclarke

@sajclarke sajclarke commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

Description

Replaces the brittle Playwright timing measurements in the weekly performance report with real product analytics pulled from Umami.

The report now surfaces site-wide visits and per-form funnel health (starts, completions, abandonment, time-to-complete, per-step drop-off) with week-over-week deltas, and runs automatically every Monday so stakeholders always see fresh numbers.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Changes made

scripts/perf/umami-form-metrics.mjs (new)

  • Adds a standalone Umami Cloud client that pages through /events and /website/{id}/stats, then aggregates form-start, form-submit, and form-step-* events into per-form funnels.
  • De-duplicates on Umami sessionId so reloads and repeat fires don't inflate counts. Pulls duration_seconds off form-submit to compute mean / median / p90 completion time, and emits a daily series for sparklines.
  • Returns null (instead of throwing) when UMAMI_API_KEY or NEXT_PUBLIC_UMAMI_SITE_ID is missing so PR forks and local runs degrade gracefully.

scripts/perf/generate-performance-report.mjs

  • Fetches the current window, the immediately preceding window, and site-wide stats in parallel with Promise.allSettled, so a single failing call never blocks the report.
  • Adds a General stats section with cards for Website visits, Form completion rate, Form abandonment rate, and Avg time to complete a form. Each card renders a week-over-week delta — percentage points for rates, relative % for counts/durations — colored green/red by whether the direction is good for that metric.
  • Adds a Form completion analytics section with a per-form summary table (starts, completions, completion %, abandonment %, avg / median / p90, inline SVG trend sparkline for starts vs completions) and a collapsible per-step drop-off table per form.
  • Removes the old Playwright timings card section; analytics now own that surface.

tests/perf/metrics.spec.ts

  • Drops the two synthetic timing tests (form page ready, search to results) and the timings field from the emitted playwright-metrics.json. The spec now only persists axe results, which is all the report still consumes from Playwright.

.github/workflows/performance-report.yml

  • Adds a weekly schedule trigger (15 12 * * 1, Mondays 12:15 UTC / 08:15 AST) — intentionally off-the-hour to dodge GitHub Actions cron contention.
  • Wires UMAMI_API_KEY, NEXT_PUBLIC_UMAMI_SITE_ID, and UMAMI_REPORT_DAYS=7 into the report step, and extends the deploy job's if so scheduled runs publish to GitHub Pages.

Notes

  • The script intentionally keeps a private copy of the 1-based NUMBER_WORDS table from src/lib/analytics.ts so it has zero coupling to the Next.js source tree and can run in any CI image with just Node.
  • MAX_EVENT_PAGES is set to 50 (50k events). When that cap is hit a row is flagged with a warning glyph in the table so readers know the numbers are a lower bound.

Testing

  1. Set UMAMI_API_KEY and NEXT_PUBLIC_UMAMI_SITE_ID in .env.local (already configured locally).
  2. Build the app and start it: npm run build && npm start.
  3. From a second terminal: BASE_URL=http://127.0.0.1:3000 PERF_EXTERNAL_SERVER=1 UMAMI_REPORT_DAYS=7 npm run perf:report.
  4. Open performance-report/index.html and verify:
    • General stats renders four cards with non-zero values and a delta badge under each.
    • Form completion analytics renders a row per active form, sparklines render, and the per-step <details> blocks expand to show drop-off.
    • The old "Playwright timings" section is gone; axe and Lighthouse sections still render.
  5. To exercise the no-credentials path, unset UMAMI_API_KEY, rerun the script, and confirm both new sections show their "Skipped" placeholder instead of erroring.
  6. Optional: trigger the workflow manually from the Actions tab (workflow_dispatch) to confirm the secrets are wired and the deploy job publishes.

Related Github Issue(s)/Trello Ticket(s)

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Tests added/updated (visual regression snapshots)
  • Documentation updated

@vercel

vercel Bot commented Apr 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
frontend-alpha Ready Ready Preview, Comment Apr 27, 2026 10:03pm

Request Review

@amazon-inspector-n-virginia

Copy link
Copy Markdown

⏳ I'm reviewing this pull request for security vulnerabilities and code quality issues. I'll provide an update when I'm done

@amazon-inspector-n-virginia

Copy link
Copy Markdown

✅ I finished the code review, and didn't find any security or code quality issues.

@Zainab980 Zainab980 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants