Configure recording collection

Last updated:

There are some configurations that can be used to adjust how recordings are captured.

AttributeDescription
maskAllInputs

Type: Boolean
Default: true
When true, all data from user input fields will be replaced by '*'s.
maskInputOptions

Type: Object
Default: {}
Only takes effect if maskAllInputs is false. It determines which specific input field types should be masked. An example value might be { password: true }. Options are: password, textarea, select, color, date, email, month, number, range, search, tel, text, time, url, week, and datetime-local.
inlineStylesheet

Type: Boolean
Default: true
If false, stylesheets will not be included with the recording data. Rather, a URL pointing to the stylesheet will be included. Setting this to false will decrease the storage space used for recordings and improve playback buffering time, but it can also cause some flickering in the playback experience.

To configure these options, pass them to your posthog.init call along with your other posthog-js configurations. They go inside of the session_recording attribute, like so:

JavaScript
posthog.init('<ph_project_api_key>', {
api_host: '<ph_instance_address>',
session_recording: {
inlineStylesheet: false,
},
// ... other options
})

Console logs recording

PostHog can also capture console logs from your application. This is useful for debugging, providing extra context on what is happening in your users browser environment. As console logs can contain sensitive information we do not capture these logs automatically. You can enable this feature globally from your PostHog project settings page or client-side by setting enable_recording_console_log in our JavaScript library config to true.

Console logs will be recorded if either the project setting or the client-side config is set to true. If recordings overall are disabled then console logs will also not be recorded.

JavaScript
posthog.init('<ph_project_api_key>', {
api_host: '<ph_instance_address>',
// REMINDER: This is only needed if you aren't using the project settings config
enable_recording_console_log: true,
// ... other options
})

Network recording

PostHog can capture network requests that occur during the browser session so you can see the effect of slow network requests or errors on the user experience.

These network request can be modified before capture to remove sensitive information from the URL like so.

JavaScript
posthog.init('<ph_project_api_key>', {
session_recording: {
maskNetworkRequestFn: (request) => {
// For example: ignoring a request entirely
if (request.url.includes('example.com')) {
return null
}
// ... or remove the query string from the URL
request.url = request.url.split('?')[0]
return request
}
}
})

Further controls

If you want more granular controls, you can choose to enable session recording using feature flags. This enables you to control session recordings based on users with certain previous events/actions or properties (or just to capture a percentage of all sessions).

To do this set disable_session_recording in our JavaScript library config to true.

Then conditionally call the method posthog.startSessionRecording to enable it using the feature flag.

For example:

JavaScript
posthog.init('<ph_project_api_key>', {
api_host: '<ph_instance_address>',
disable_session_recording: true,
// ... other options
})
window.posthog.onFeatureFlags(function () {
if (window.posthog.isFeatureEnabled('your-feature-flag')) {
window.posthog.startSessionRecording()
}
})

Equally you can stop the recording at any point via:

posthog.stopSessionRecording()

Questions?

Was this page useful?

Next article

Replay data retention

Depending on how your app or website is built, recordings can take a lot of disk space. To manage this, we have the following retention policy options in place. PostHog Cloud Recordings are automatically deleted after 3 weeks . The deletion is not immediate meaning that they may still appear for a short time in the UI after the 3 week period or if manually deleted via the UI. Preserving recordings Pinned or Shared recordings are kept for as long as they are actively in use. Altetnatively, any…

Read next article