ClickHouse Product Analytics

Build product analytics on ClickHouse with TypeScript

Product analytics tables are wide, high-cardinality, and queried in many ways — DAU, funnels, retention, segmentation. hypequery gives TypeScript teams schema-generated types for event tables and a composable query layer for the analytics patterns that matter.

Key aggregations

uniq, windowFunnel, retention

Schema source

Generated from live ClickHouse

Best for

Product and SaaS analytics teams

Event tables have wide schemas that drift constantly

Product analytics tables — events, sessions, funnels — have high cardinality and many columns that grow as new event types are added. Hand-written TypeScript interfaces for them are massive, tedious, and inevitably drift from the actual schema.

Funnel and retention queries are hard to make reusable

Funnel analysis using windowFunnel and retention using cohort filters are complex ClickHouse-specific SQL patterns. Wrapping them in a type-safe, composable layer makes them reusable across product and data teams instead of reimplemented per dashboard.

Internal and customer-facing analytics need the same query logic

Serving the same product analytics to internal dashboards and customer-facing UIs typically results in two separate data layers with duplicated query logic. A shared analytics layer with route-level delivery paths solves this without code duplication.

Event queries

Schema-generated types for events and ClickHouse-native aggregations

The bottleneck in product analytics on ClickHouse is rarely query speed — it is the TypeScript layer around the queries. Generating types from the live schema ensures the types reflect reality, not a stale hand-written copy.

  • Run npx @hypequery/cli generate to introspect your events table and emit TypeScript types
  • Use uniq() for distinct user counts — ClickHouse HyperLogLog, not COUNT(DISTINCT)
  • Use windowFunnel() for ordered funnel analysis within a time window
  • Compose filters (tenant, date range, event type) using typed .where() calls
  • Reuse the same query definitions across internal and customer-facing surfaces

Event queries

Typed DAU and funnel queries using ClickHouse-native aggregations

event-queries.ts

Schema-generated types mean the select column names and their TypeScript types are verified at compile time, not discovered at runtime when a dashboard breaks.

Analytics API

Serve DAU, retention, and funnel metrics from a shared API layer

Once product analytics queries are defined as named contracts, the same definitions can serve an internal analytics dashboard, a customer-facing analytics page, and a scheduled report pipeline — without duplicating query logic.

The key insight is that context-level tenant isolation — applied once in initServe — means every analytics query is safe to expose over HTTP without re-verifying the tenant filter per endpoint.

For teams building self-serve product analytics for customers, this is the foundation: one analytics definition, tenant-isolated by default, deliverable to multiple surfaces.

Product analytics API

DAU and retention as typed, tenant-isolated endpoints

analytics-api.ts

The tenant isolation lives in the context, not in each query. Adding a new metric does not require remembering to add the tenant filter — it is structural.

Why teams search for this

Common implementation questions this page should solve

ClickHouse product analytics TypeScript

TypeScript product analytics on ClickHouse starts with schema generation. Once the event table types are accurate, DAU, funnel, and retention queries can be written with full compile-time safety.

ClickHouse event tracking queries

Event tracking in ClickHouse works well when the query layer distinguishes between ClickHouse-native aggregations (uniq, windowFunnel) and generic patterns. hypequery preserves access to both.

ClickHouse funnel analysis TypeScript

windowFunnel is a ClickHouse-native function for ordered funnel analysis within a configurable time window. Wrapping it in a typed, reusable contract prevents fragile funnel SQL from being duplicated across dashboards.

ClickHouse retention metrics

Cohort retention on ClickHouse requires a subquery for the cohort definition and date arithmetic. A typed analytics layer makes that pattern reusable with configurable cohort date and day offset.

Next step

Generate your events schema and write the first typed analytics query

Schema generation is the foundation of typed product analytics. Once your events table is reflected in TypeScript, DAU, funnel, and retention queries all follow the same composable pattern.