How to control which sessions you record

Last updated:

|Edit this page

If you want control over which sessions to record:

Available on all plans

With your own code

  1. Set disable_session_recording: true in your config.

  2. Manually start recording by calling posthog.startSessionRecording(). Similarly, you can stop the recording at any point by calling posthog.stopSessionRecording().

  3. Important make sure the your domain is added to the Authorized Domains list as otherwise the data will still be ignored as it is ingested by our servers.

For example:

Web
posthog.init('<ph_project_api_key>', {
api_host: https://us.i.posthog.com,
disable_session_recording: true,
// ... other options
})
// some time later based on a trigger in your system
posthog.startSessionRecording()

Billing Limits

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

Not available on all plans

Other controls are available to:

  • free and paid plans started since Jan 2024
  • any paid plans started before then

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 you can use to control whether to record sessions or not.
  2. Visit your replay ingestion settings page.
  3. Select that flag in the "Enable recordings using feature flag" dropdown menu.
Selecting a feature flag to control session recordings

Sampling

You can configure sampling to limit the number of sessions you record for each user. This is useful if you want to record a percentage of sessions for all users. Sampling helps reduce the number of sessions you record, but it doesn’t let you control which sessions are included.

Our recommendation is to start with capturing all sessions (e.g. 100% - the default) or a high sampling rate (e.g. 90% or 95%) 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.

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

Whenever a new session starts after you select a collection below 100%, the browser generates a random number between 0 and 1. If the number is less than the sampling rate (e.g. 0.9 when set to 90%), the session is recorded. If it is greater than the sampling rate, the session is not recorded.

Overriding sampling

Since posthog-js version 1.119.0 the SDK allows passing an override config when calling startSessionRecording. So, you can set a sample rate but can also manually call posthog.startSessionRecording({sampling: true}) in your code which ensures a recording starts no matter what sample rate you have set.

Minimum duration

You can also set a minimum duration for sessions to be recorded. 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.

Minimum duration config shown set to 2 seconds

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.

Limitations

This means that if you set a high minimum duration and your user visits multiple pages each for a short time, you still record the session but miss the beginning. If the user leaves the site before the minimum duration has passed, the session is not recorded.

If you find you are missing the beginning of sessions, you can reduce the minimum duration or use one of our other methods to reduce the number of sessions you record.

For more examples of controlling which sessions you record

see our tutorial on how to only record the sessions you want.

Questions?

Was this page useful?

Next article

Troubleshooting and FAQs

Having trouble with recordings? Below are some tips for getting past some common issues The most common solution is... Update posthog-js We're always making improvements to the recordings feature, so you'll want to make sure that you're running the latest version of posthog-js on your website. To check the version that you're using, you can run the following in your browser console: Recordings are not being captured There are a few common reasons that you may not see recordings appear in your…

Read next article