If you want control over which sessions to record:
Available on all plans
With your own code
Set
disable_session_recording: true
in your config.Manually start recording by calling
posthog.startSessionRecording()
. Similarly, you can stop the recording at any point by callingposthog.stopSessionRecording()
.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:
posthog.init('<ph_project_api_key>', {api_host: '<ph_instance_address>',disable_session_recording: true,// ... other options})// some time later based on a trigger in your systemposthog.startSessionRecording()
Billing Limits
You can set a billing limit using these instructions. We'll stop ingesting recordings when you reach your limit.
Available on all plans started since Jan 2024
We're currently testing these new controls and will release them more widely once those tests are complete.
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.
- Create a boolean flag that you can use to control whether to record sessions or not.
- Visit your replay ingestion settings page.
- Select that flag in the "Enable recordings using feature flag" dropdown menu.
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.
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.
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.
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.