Quick Use
posthog.init(...)withsession_recording: { maskAllInputs: false }- Add
class="pii"to sensitive fields you want masked - PostHog dashboard → Session Replays — filter by event / user / device
Intro
PostHog Session Replay records user interactions in your app — clicks, scrolls, console logs, network requests — playable as video. When a user reports 'the AI gave wrong answer', you replay their full session, see the prompt they typed, the model's reply, and what they did next. Best for: support and product teams debugging AI feature usability. Works with: web (JS SDK), iOS, Android, React Native. Setup time: 5 minutes.
Enable session replay
import posthog from "posthog-js";
posthog.init("phc_...", {
api_host: "https://us.posthog.com",
session_recording: {
maskAllInputs: false, // record what users type (mask in PII fields)
maskTextSelector: ".pii", // anything with class="pii" is masked
recordCrossOriginIframes: true,
blockClass: "no-record", // anything with class="no-record" is blocked
},
});
posthog.identify("user_42", { plan: "pro" });Capture LLM-specific context
// Annotate the recording with LLM events for richer playback timeline
posthog.capture("llm_call_started", {
model: "claude-3-5-sonnet",
prompt_length: 1234,
});
const response = await client.chat.completions.create(...);
posthog.capture("llm_call_completed", {
model: "claude-3-5-sonnet",
latency_ms: 1830,
tokens: 450,
user_satisfied: null, // updated when user reacts
});Filter recordings by AI events
PostHog → Session Replays → Filter:
- Has event:
llm_call_completedwheremodel = claude-3-5-sonnet - And: error occurred within 30s after
- And: user did NOT click positive feedback button
→ A queue of broken-experience replays for triage.
Privacy-first defaults
- Password / credit-card / email fields auto-masked
- Custom mask via
maskTextSelector/data-privateattribute - Block entire elements via
blockClass - Cookie banner consent integration (recordings only start after consent)
What you'll catch
- Users abandoning your AI chat after 30s of typing
- Users reading the AI response then immediately searching elsewhere (signal: bad answer)
- Crashes on specific browsers/OSes
- Console errors that don't surface in your error tracker
FAQ
Q: Does session replay slow down my site? A: Negligible — recording happens in a Web Worker, payloads are gzipped and sent in batches. Typical overhead is <50ms on first paint and <2KB/min in network usage.
Q: Can users opt out?
A: Yes — call posthog.opt_out_capturing() from your settings page or after a cookie banner decline. PostHog also respects DNT headers when configured.
Q: How long are recordings kept? A: Free tier 1 month, paid plans up to 1 year. Self-hosted is configurable. For long retention without cost, export recordings periodically via the API.
Source & Thanks
Built by PostHog. Licensed under MIT.
PostHog/posthog-js — ⭐ 1,500+