Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(signals): keep the replay capture query runnable and its ratio honest (#103529)

posthog[bot]9e1eb0c0de24
diff --git a/products/signals/skills/signals-scout-session-replay/SKILL.md b/products/signals/skills/signals-scout-session-replay/SKILL.md
index 79bc1a17f8f8..808e9901137a 100644
--- a/products/signals/skills/signals-scout-session-replay/SKILL.md
+++ b/products/signals/skills/signals-scout-session-replay/SKILL.md
@@ -71,29 +71,74 @@ Four cheap reads cold-start a run:
Then orient with two queries. Capture side — daily recordings against daily traffic:
```sql
-SELECT t.day AS day, coalesce(r.recorded_sessions, 0) AS recorded_sessions,
+SELECT t.traffic_day AS day,
+ coalesce(r.recorded_sessions, 0) AS recorded_sessions,
t.event_sessions AS event_sessions,
- round(coalesce(r.recorded_sessions, 0) / t.event_sessions, 4) AS capture_ratio
+ round(coalesce(r.recorded_sessions, 0) / t.event_sessions, 4) AS capture_ratio,
+ coalesce(r.recorded_sessions, 0) > t.event_sessions AS ratio_impossible
FROM (
- SELECT toStartOfDay(timestamp) AS day, uniq(properties.$session_id) AS event_sessions
+ SELECT toStartOfDay(timestamp) AS traffic_day, uniq(properties.$session_id) AS event_sessions
FROM events
WHERE timestamp >= now() - INTERVAL 14 DAY
AND timestamp <= now() + INTERVAL 1 DAY
AND properties.$session_id IS NOT NULL
AND event = '$pageview'
- GROUP BY day
+ GROUP BY traffic_day
) t
LEFT JOIN (
- SELECT toStartOfDay(min_first_timestamp) AS day, uniq(session_id) AS recorded_sessions
+ SELECT toStartOfDay(min_first_timestamp) AS recording_day, uniq(session_id) AS recorded_sessions
FROM raw_session_replay_events
WHERE min_first_timestamp >= now() - INTERVAL 14 DAY
AND min_first_timestamp <= now() + INTERVAL 1 DAY
- GROUP BY day
-) r ON r.day = t.day
+ GROUP BY recording_day
+) r ON r.recording_day = t.traffic_day
+ORDER BY t.traffic_day
+```
+
+Traffic drives the join: a zero-recording day — the exact cliff this scout exists to catch — must show `capture_ratio` 0, and an inner join would silently drop it.
+`$pageview` is the cheap denominator; if absent, substitute the project's top web event.
+Each side names its day column distinctly (`traffic_day`, `recording_day`) and the `ORDER BY` stays qualified.
+Two subqueries that both expose a column called `day` make every unqualified `day` after the join ambiguous, and the query then fails instead of returning the series.
+Keep the distinct names when you adapt the query.
+
+**Check `ratio_impossible` before you read the series: more recorded sessions than event sessions means the query is wrong, not that capture is high.**
+The two sides count different session populations.
+The numerator counts every recorded session, the denominator only sessions that fired a `$pageview`, so mobile SDK recordings and recordings of pageview-less sessions inflate the ratio.
+Read the flag, not `capture_ratio`: the displayed ratio rounds to four decimals, so a real 1.00004 prints as `1.0000` and hides the overshoot, while the flag compares the two raw counts.
+One flagged day discredits the whole series: the same mismatch distorts the days that stay under 1, and it can fake a drop as easily as a spike.
+Discard the series and rerun with the fallback below.
+
+The fallback counts both sides over one population — every session the event stream saw, marked by whether a recording exists for it — so the ratio is bounded by construction:
+
+```sql
+SELECT toStartOfDay(s.session_start) AS day,
+ uniq(s.session_id) AS event_sessions,
+ uniqIf(s.session_id, s.recorded) AS recorded_sessions,
+ round(uniqIf(s.session_id, s.recorded) / uniq(s.session_id), 4) AS capture_ratio
+FROM (
+ SELECT properties.$session_id AS session_id,
+ min(timestamp) AS session_start,
+ properties.$session_id IN (
+ SELECT session_id
+ FROM raw_session_replay_events
+ WHERE min_first_timestamp >= now() - INTERVAL 15 DAY
+ AND min_first_timestamp <= now() + INTERVAL 1 DAY
+ ) AS recorded
+ FROM events
+ WHERE timestamp >= now() - INTERVAL 14 DAY
+ AND timestamp <= now() + INTERVAL 1 DAY
+ AND properties.$session_id IS NOT NULL
+ GROUP BY session_id, recorded
+) s
+GROUP BY day
ORDER BY day
```
-Traffic drives the join: a zero-recording day — the exact cliff this scout exists to catch — must show `capture_ratio` 0, and an inner join would silently drop it. `$pageview` is the cheap denominator; if absent, substitute the project's top web event.
+The recording window runs one day wider than the traffic window, so a session that starts late in a day still matches its recording.
+This read costs more, so keep it for the fallback.
+It sees only sessions the event stream knows about, so a recording with no events falls outside it — that is the price of a bounded ratio, and the ratio's _change_ is the signal either way.
+Its level answers a different question than the primary query's, because the two differ in both session population and day attribution.
+Neither ratio is reliably the higher of the two, so baseline this one under its own `pattern:` key and never compare one query's ratio against the other's.
Friction side — where rage clicks concentrate, last day vs the prior two weeks. Group by host plus an **ID-normalized path**, never the raw URL: full `$current_url` values carry query strings, fragments, and entity IDs that shatter one hot surface into dozens of single-count rows:
@@ -273,6 +318,7 @@ Nearly everything this scout reads originates in end-user browsers: URLs, elemen
- **Replay never adopted** — zero recordings ever isn't a gap to report; teams choose their products. `not-in-use:` entry and close out.
- **Low capture ratio as a finding** — sampling is deliberate. Only an unexplained _change_ in the ratio is signal.
+- **Any capture series with a `ratio_impossible` day** — more recorded sessions than event sessions means the two are counting different session populations. Rerun with the same-population fallback; report from that or not at all.
- **Cliffs explained by Team config edits** — an operator action; context, never a finding.
- **Friction tracking traffic** — totals that rise with `event_sessions` are the product breathing. Always check the whole-stream trend before any per-URL claim.
- **Cliffs and clusters below the volume gates** (< ~100 recordings/day baseline; < ~10 sessions / < ~5 persons per cluster) — low-volume surfaces wobble.