Skip to content

Add Exit pages panel to project stats - #61

Merged
ralyodio merged 1 commit into
masterfrom
worktree-stats-exit-pages
Jul 4, 2026
Merged

ralyodio merged 1 commit into
masterfrom
worktree-stats-exit-pages

Conversation

@ralyodio

@ralyodio ralyodio commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

What

Adds an Exit pages breakdown next to Top pages on the project stats page, over the same durable 30-day window as the other panels.

The exit page of a session is its most recent pageview — the last page a visitor was on before leaving. Since we can't know at ingest time whether a given pageview is the last one, /api/track keeps a small per-session "current last page" record and moves the +1 exit marker forward as the session advances (decrement the previous page, increment the new one), so tracker_exit_daily_stats always reflects exactly one exit page per session.

Works for both multi-page and SPA sites — the tracker already sends sessionId on every pageview (including pushState/popstate route changes), so no /stats.js change was needed.

Changes

  • Migration 20260704120000_tracker_exit_rollups.sql
    • tracker_exit_daily_stats — daily exit-page counts, RLS mirroring the other tracker_*_daily_stats tables (owner + member select)
    • tracker_exit_sessions — service-role-only session→last-page bookkeeping; pruned 24h past the client-side 30-min session TTL so a session id can't be resurrected and double-counted
  • lib/tracker/exit.ts — bumpExit / updateExitRollup / pruneExitSessions; counts clamped at 0 so a decrement racing ahead of its increment can't go negative (extracted to a lib module so it's unit-testable, mirroring device.ts / geo.ts)
  • /api/track — calls the rollup for pageviews carrying a sessionId, best-effort so it never affects the 204
  • Stats page + TrackerAnalytics — new "Exit pages" ranked-list panel; grid re-paired to stay two-up
  • Tests — tracker-exit.test.ts: marker-moving, repeat-page no-op, multi-session independence, below-zero guard (5 passing)

Verification

  • tsc --noEmit clean
  • tracker-exit, track-cors, stats-js, tracker-device contract tests pass
  • Note: tracker-geo fails in the worktree only because the GeoLite2 .mmdb data file isn't present in the worktree's node_modules (lookupGeo returns undefined); it passes on the main checkout and this PR touches no geo code

🤖 Generated with Claude Code

Adds a durable 30-day "Exit pages" breakdown next to "Top pages" on the
project stats page. The exit page of a session is its most recent
pageview; since we can't know at ingest time whether a pageview is the
last one, /api/track keeps a per-session "current last page" record
(tracker_exit_sessions) and moves the +1 exit marker forward as the
session advances — decrement the previous page, increment the new one —
so tracker_exit_daily_stats always holds exactly one exit page per
session. Works for both multi-page and SPA sites since the tracker
already sends sessionId on every pageview.

- migration: tracker_exit_daily_stats (RLS like the other rollups) +
  tracker_exit_sessions (service-role-only bookkeeping)
- lib/tracker/exit.ts: bumpExit / updateExitRollup / pruneExitSessions,
  with counts clamped at 0 against decrement/increment races
- stats page + TrackerAnalytics: new "Exit pages" ranked-list panel
- tests: marker-moving, repeat-page, multi-session, below-zero guard

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

vu1nz Security Review

0 finding(s) in PR #?

No security issues found.

@ralyodio
ralyodio marked this pull request as ready for review July 4, 2026 01:45
@ralyodio
ralyodio merged commit 7aa8329 into master Jul 4, 2026
8 checks passed
@ralyodio
ralyodio deleted the worktree-stats-exit-pages branch July 4, 2026 01:46
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.

1 participant