Add comprehensive visitor engagement tracking and scroll-to-top on navigation

Tracks scroll depth (25/50/75/90%), time on page, UTM parameters, outbound
link clicks, search queries, audio pause/completion/listen time, and 404s.
Logged-in study users are now tied to their visitor record and surfaced in
the admin recent visits table. Scroll position resets on every route change.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
nmemmert
2026-06-17 14:06:21 -04:00
parent a6f0c39c35
commit 31426fccba
11 changed files with 498 additions and 4 deletions
+21
View File
@@ -63,6 +63,27 @@ export const state = {
episodePlays: {},
episodePlaysWritePromise: Promise.resolve(),
// analyticsEvents: aggregated engagement data from frontend events
// {
// scrollDepth: { [path]: { 25: n, 50: n, 75: n, 90: n } }
// timeOnPage: { [path]: { totalSeconds: n, count: n } }
// outboundClicks: { [url]: n }
// utmSources: { [utm_source]: n }
// searchQueries: { [query]: n }
// notFound: { [path]: n }
// audioEvents: { [title]: { pauses: n, completions: n, totalListenSeconds: n } }
// }
analyticsEvents: {
scrollDepth: {},
timeOnPage: {},
outboundClicks: {},
utmSources: {},
searchQueries: {},
notFound: {},
audioEvents: {},
},
analyticsEventsWritePromise: Promise.resolve(),
// qrCodes: Array<{ id, slug, label, destination, createdAt }>
// qrScans: Array<{ id, qrId, slug, scannedAt, ip, userAgent }>
qrCodes: [],