For the complete documentation index, see llms.txt. This page is also available as Markdown.

Funnel & retention analysis

SQL templates for n-step funnels, day-N retention, and time-to-event.

The two queries every analytics dashboard needs eventually:

  1. Funnel. Of users who did step 1, what % did step 2, then step 3, etc.?

  2. Retention. Of users who first did X on day D, what % were still doing X on day D+N?

Millimetric doesn't ship a hosted "funnel builder" UI yet — but the queries are short, the data is in ClickHouse, and you can run them directly via your ClickHouse credentials or wrap them in a route in your own app.

A funnel template

WITH steps AS (
  SELECT
    anonymous_id,
    minIf(timestamp, event_name = '$pageview')         AS s1_landed,
    minIf(timestamp, event_name = 'clicked_cta')       AS s2_clicked,
    minIf(timestamp, event_name = 'viewed_signup_form') AS s3_form,
    minIf(timestamp, event_name = 'signup')            AS s4_signup,
    minIf(timestamp, event_name = 'activated')         AS s5_activated
  FROM events
  WHERE project_id = '...'
    AND timestamp BETWEEN '2026-05-01' AND '2026-05-17'
  GROUP BY anonymous_id
)
SELECT
  countIf(s1_landed   IS NOT NULL)                                            AS landed,
  countIf(s2_clicked  IS NOT NULL AND s2_clicked  >= s1_landed)               AS clicked,
  countIf(s3_form     IS NOT NULL AND s3_form     >= s2_clicked)              AS viewed_form,
  countIf(s4_signup   IS NOT NULL AND s4_signup   >= s3_form)                 AS signed_up,
  countIf(s5_activated IS NOT NULL AND s5_activated >= s4_signup)             AS activated,

  round(100.0 * countIf(s2_clicked  IS NOT NULL AND s2_clicked  >= s1_landed) / countIf(s1_landed IS NOT NULL), 2) AS pct_to_click,
  round(100.0 * countIf(s5_activated IS NOT NULL AND s5_activated >= s4_signup) / countIf(s1_landed IS NOT NULL), 2) AS pct_landed_to_activated
FROM steps;

Key bits:

  • minIf(timestamp, event_name = …) returns the first time each step happened per user.

  • s_n >= s_{n-1} enforces ordering — a user who signed up before viewing the form doesn't count.

  • All steps within a single window (BETWEEN …) for clean cohort math.

Funnel by traffic source

Group the same logic by entry source:

Drops out as a per-channel conversion rate. Combine with marketing-attribution for revenue.

Day-N retention

For users who first did X on day D, what fraction did X on day D+N?

→ pivots to:

Day-0 is your cohort size. Each subsequent day is the % of that cohort active that day.

"Stickiness" — DAU / MAU

A DAU/MAU above 20% is good; above 50% is excellent.

Time-to-event

How long from signup to first purchase?

Distribution

Power-user definition

Users in the top-decile of activity over 30 days:

Use that cohort to drive A/B tests, surveys, or "which feature predicts retention" analyses.

Wrapping these in your app

You can hit ClickHouse directly with your CLICKHOUSE_* credentials, but most teams build a thin server route per saved query and read from the browser:

Cache aggressively — these queries get expensive at scale, and the answers don't change second-to-second.

See also

Last updated

Was this helpful?