@henrylatour/analytics

Self-hosted product analytics for all of my apps: tracking SDKs, a metric builder with funnels, retention and SQL, and an AI analyst built on Claude Code.

Nov 2026 – Present

  • TypeScript
  • Express 5
  • PostgreSQL
  • Socket.IO
  • React 19
  • Vite
  • MobX
  • TanStack Router
  • Tailwind v4
  • Claude Agent SDK
  • Zod
  • libpg-query
  • Turborepo
  • Railway
  • Tracking:
    • A /s.js script and published SDKs for the browser, React and Node (@henrylatour/analytics*).
    • Pageviews, custom events, HTTP status codes and server-side request events.
    • User-agent and geo enrichment, bot filtering, a masked client IP, and dev traffic flagged automatically.
  • Ingest: events go into an in-memory write buffer and are written to monthly-partitioned Postgres tables in batches, one transaction per batch, with the queue drained on shutdown. New events stream to a live view over Socket.IO.
  • Metrics and dashboards:
    • A metric builder for trends, top-N, funnels, retention, paths and formulas (A / B * 100).
    • Saved metrics and drag-and-drop dashboards.
    • Starter dashboards for every project.
  • SQL sandbox: queries are parsed with libpg-query and must be a single SELECT over project-scoped events, sessions and persons, using allow-listed functions only. They run in a read-only transaction as a restricted role, with a 10 s timeout and a 1,000-row cap.
  • AI analyst:
    • Claude Code runs through the Agent SDK with only in-process MCP tools, which wrap the same services as the UI.
    • Every number comes from a tool result.
    • Saving a metric or dashboard is a draft card the user applies.
    • Every run is logged.
  • App shell:
    • One global view per project (date range, segments, filters, comparison, auto-refresh), remembered per project and mirrored in the URL so links can be shared.
    • A ⌘K command palette.
    • An installable PWA.
  • Notifications:
    • Threshold, change and anomaly alerts, plus AI-written digests, scheduled under a Postgres advisory lock.
    • Delivered to an inbox, by web push, or to Slack or Discord webhooks.
    • Public dashboard share links run only the shared dashboard's tiles and never accept client-supplied queries.
  • Platform: sign-in through my own OIDC provider, config from its env-variable vault, UI from my component library. A pnpm and Turborepo monorepo deployed on Railway.