Link session replay
Contents
Connecting your backend LLM events to frontend session replays provides complete visibility into the user journey, helping you understand the full context around AI interactions in your application.
Why link to session replay?
By including session IDs in your LLM events, you can:
- See the full user journey: Navigate from an LLM trace directly to the session replay to see user actions before, during, and after AI interactions
- Debug issues faster: Quickly find and watch the exact session where problems occurred
- Understand user behavior: See how users interact with AI features and what prompts they use
- Correlate performance: Match slow AI responses with actual user experience impact
Implementation
There are two ways to pass session IDs from your frontend to your backend:
- Automatic header injection - posthog-js automatically adds headers to your API requests
- Manual approach - explicitly pass the session ID in your request body
Option 1: Automatic header injection (recommended)
Configure posthog-js to automatically inject session headers into requests to your backend:
This automatically adds X-POSTHOG-SESSION-ID (and X-POSTHOG-DISTINCT-ID) headers to all fetch and XMLHttpRequest calls to the specified hostnames.
On your backend, read the header and include it in your LLM tracking:
Option 2: Manual approach
If you prefer explicit control, retrieve the session ID and pass it in your request body:
Viewing linked replays
Once you've set up session linking, you can navigate from LLM generations to their corresponding session replays:
- In the LLM analytics dashboard, find the generation or trace you're interested in
- Click the session replay button to jump directly to the replay
- Watch the user's interaction with your AI features in context
This linking helps you understand not just what your AI is doing, but how users are experiencing it in your application.