# Phase 4 - Analytics

> Phase 4 - Analytics: a note from the Obsidian vault behind https://saifsiddiqui.in.

Canonical URL: https://saifsiddiqui.in/te/brain/phase-4-analytics/ (this is its markdown representation; the same URL serves HTML to browsers)
Other languages: en: https://saifsiddiqui.in/brain/phase-4-analytics/ · hi: https://saifsiddiqui.in/hi/brain/phase-4-analytics/ · kn: https://saifsiddiqui.in/kn/brain/phase-4-analytics/ · ur: https://saifsiddiqui.in/ur/brain/phase-4-analytics/ · ar: https://saifsiddiqui.in/ar/brain/phase-4-analytics/ · hi-Latn: https://saifsiddiqui.in/hi-latn/brain/phase-4-analytics/

**Type:** phase  
**Status:** done  
**Created:** 2026-07-17  
**Tags:** phase, build-log, analytics, flagship

## ✅ Phase 4: Fully-custom analytics (built & verified locally; deployed with empty state)

The flagship engineering showcase ([D008 - Fully Custom Analytics](/brain/d008-fully-custom-analytics/)). Works end-to-end against local storage; deployed to preview with the designed empty state (prod storage wired at launch per [D017 - Defer External Service Activation](/brain/d017-defer-external-service-activation/)).

**Tracker**, 2.1KB gz (budget ~3KB), cookieless, hydrates at idle, starts after load. Captures pageview (path/locale/referrer-host/device/viewport), 25/50/75/100% scroll, per-section attention (IntersectionObserver), one delegated click listener → {section, stable selector, normalized x/y}. All 6 named events wired: theme_change, lang_change, work_card_click, cta_click (delegated), demo_used + graph_node_click (via `emitTrack()`, inert if tracker off). Flush via sendBeacon every 8s + visibilitychange/pagehide. **DNT + Global Privacy Control → fully inert.**

**Pipeline**, `/api/track`: event-type allowlist + size caps, bot-UA drop, 60 batches/min/IP, country from `x-vercel-ip-country` (IP never parsed for storage), batch insert → Postgres, bump KV live-set + daily counter. `/api/insights`: SQL aggregations behind 60s KV cache (verified: 2 fetches share one generatedAt). `/api/live`: KV only.

**Storage**, env-driven: `POSTGRES_URL` + `REDIS_URL` only. Verified against local brew Postgres 16 + Redis. Unset → writes drop, reads empty, dashboard shows empty state (= current preview). Go-live = paste Neon + Upstash URLs into Vercel env; schema auto-creates.

**Dashboard + teaser**, `/analytics` (all 7 locales): live-now / pageviews / uniques (count-up, instant under reduced-motion), 24h/7d/30d, top-sections, scroll-depth curve, click map over dimmed homepage snapshot (15KB jpg), device/OS/browser, referrers, locales, 4-step funnel, every chart has a `<details>` data-table twin + labeled SVG. Privacy panel ("What I measure, and what I don't"). §06 "This site, measured" between AI demo (05) and graph teaser (07): 4 live tiles + dashboard link.

**Two honest deviations:**
1. **Session id in `sessionStorage`** (random UUID, tab-scoped, 30-min rotation) instead of pure in-memory, the funnel needs cross-page continuity in an MPA. Still cookieless, anonymous, no PII; cleared on tab close. Privacy claims hold.
2. Uses `x-vercel-ip-country` header (never parses the IP), even cleaner than the specced "derive then discard".

**Verified (20/20):** scripted journey → all 8 event types in Postgres; funnel landed 1→work 1→demo 1→contacted 0; live counter 1→2 across contexts; teaser real numbers (avg scroll 63%); RTL /ar/analytics mirrored; raw-row audit = no IP, no UA, no PII (no columns exist for them). Lighthouse 100/100/96/100 on / and /analytics, LCP 0.5–0.6s, CLS 0, TBT 0, tracker no measurable CWV cost.

**Testing gotcha (for future E2E):** the bot filter correctly catches headless Chrome → E2E tests must spoof a real UA.

Next: [Phase 5](/brain/roadmap/), contact backend + full polish/QA.

## ఇంకా లింక్ చేయబడింది

- [Custom Analytics](/te/brain/custom-analytics/)
- [Roadmap](/te/brain/roadmap/)

అన్ని గమనికలు: [/te/brain/](/te/brain/)

---

Mohd Saif, Product Engineer. I build solutions, not dead software.
Email: saifmd238@gmail.com · GitHub: https://github.com/Saif-09 · LinkedIn: https://www.linkedin.com/in/mohd-saif-134076141/ · Résumé (PDF): https://saifsiddiqui.in/resume

More for agents:
- [/llms.txt](/llms.txt): short summary of this site
- [/llms-full.txt](/llms-full.txt): the complete text of every page in one fetch
- [/agents.md](/agents.md): when to use this site, and how to query it
- [/sitemap-index.xml](/sitemap-index.xml): every URL, in seven languages
