How to control which sessions you record

Last updated:

|Edit this page

There are several ways to control which sessions you record:

Programmatically start and stop recordings

  1. Ensure your domain is added to the authorized domains list.
  1. Set disable_session_recording: true in your config.
Web
posthog.init('<ph_project_api_key>', {
api_host: 'https://us.i.posthog.com',
disable_session_recording: true,
// ... other options
})
  1. Manually start recording by calling posthog.startSessionRecording(). Similarly, you can stop the recording at any point by calling posthog.stopSessionRecording().

With URL trigger conditions

You can opt to only start recordings once your user visits a certain page. After the URL matches, the recording continues even after they leave the matching page.
The client keeps a short buffer in-memory, so you'll still be able to see how they have arrived at the page.

Adding URL trigger to control session recordings

With Event trigger conditions

Since posthog-js version 1.186.0, you can opt to only start recordings once your user emits a particular event. After the event is captured, the recording continues even after they leave the matching page.
The client keeps a short buffer in-memory, so you'll still be able to see how they have arrived at the event.

Adding event trigger to control session recordings

With feature flags

You can select a feature flag to control whether to record sessions or not. Recordings will only be collected for users when the flag is enabled for them.

  1. Create a boolean flag that determines whether to record sessions or not.
  2. Go to the replay ingestion settings page.
  3. Link your newly created flag in the Enable recordings using feature flag.
Selecting a feature flag to control session recordings

Sampling

Sampling enables you to record a percentage of all sessions. To set a sampling rate, go to the replay ingestion settings page.

Sampling config shown set to 100% i.e. no sampling

Our recommendation is to start with capturing 100% of sessions and decrease it as needed. This helps you get a sense of how many sessions you’re recording and how much data you’re collecting.

Note: Sampling reduces the number of sessions you record, but it doesn’t let you control which sessions are recorded.

Overriding sampling

You can begin a recording regardless of sampling by calling posthog.startSessionRecording({sampling: true})

Minimum duration

In your replay ingestion settings, you can set a minimum duration for sessions to be recorded.

Minimum duration config shown set to 2 seconds

This is useful if you want to exclude sessions that are too short to be useful. For example, you might want to exclude sessions that are less than 2 seconds long to avoid recording sessions where users quickly bounce off your site.

Limitations

The minimum duration is set in seconds. Whenever a new session starts, the browser records the start time. If the minimum duration has passed since the start time, the session data is sent. If it hasn't, the session continues to be buffered in-memory.

This means that if you set a high minimum duration and your user visits multiple pages each for a short time, the browser risks dropping the buffered data. The result is that the session is still recorded, but you miss the beginning.

If you find you are missing the beginning of sessions, reduce the minimum duration to fix this.

Billing Limits

You can set a billing limit. We'll stop ingesting recordings when you reach your limit.

Questions?

Was this page useful?

Next article

Mobile session replay

🚧 NOTE: Mobile session replay is currently available on Android, iOS, React Native and Flutter and is considered beta (and is free while in beta). We are keen to gather as much feedback as possible so if you try this out please let us know. You can send feedback via the in-app support panel or one of our other support options . Mobile session replay enables you to record user sessions in mobile apps. This includes screen recordings, network requests, logs, and touches. This data can…

Read next article