PostHogConfig

Properties

NameType
__add_tracing_headersboolean

PREVIEW - MAY CHANGE WITHOUT WARNING - DO NOT USE IN PRODUCTION Whether to wrap fetch and add tracing headers to the request

__preview_experimental_cookieless_modeboolean

PREVIEW - MAY CHANGE WITHOUT WARNING - DO NOT USE IN PRODUCTION Whether to send a sentinel value for distinct id, device id, and session id, which will be replaced server-side by a cookieless hash

__preview_flags_v2boolean

PREVIEW - MAY CHANGE WITHOUT WARNING - DO NOT USE IN PRODUCTION Whether to use the new /flags/ endpoint

__preview_remote_configboolean

PREVIEW - MAY CHANGE WITHOUT WARNING - DO NOT USE IN PRODUCTION Enables the new RemoteConfig approach to loading config instead of /flags?v=2&config=true

_onCapture(eventName: string, eventData: CaptureResult) => void
advanced_disable_decideboolean
advanced_disable_feature_flags_on_first_loadboolean

Stops from firing feature flag requests on first page load. Only requests feature flags when user identity or properties are updated, or you manually request for flags to be loaded. false

advanced_disable_feature_flagsboolean

Will keep /flags running, but without evaluating any feature flags. Useful for when you need to load the config data associated with the flags endpoint (e.g. /flags?v=2&config=true) without evaluating any feature flags. Most folks use this to save money on feature flag evaluation (by bootstrapping feature flags on the server side). false

advanced_disable_flagsboolean

One of the very first things the PostHog library does when init() is called is make a request to the /flags endpoint on PostHog's backend. This endpoint contains information on how to run the PostHog library so events are properly received in the backend, and it also contains feature flag evaluation information for the current user. This endpoint is required to run most features of this library. However, if you're not using any of the described features, you may wish to turn off the call completely to avoid an extra request and reduce resource usage on both the client and the server. false

advanced_disable_toolbar_metricsboolean

Determines whether PostHog should disable toolbar metrics. This is our internal instrumentation for our toolbar in your website. false

advanced_only_evaluate_survey_feature_flagsboolean

Determines whether PostHog should only evaluate feature flags for surveys. Useful for when you want to use this library to evaluate feature flags for surveys only but you have additional feature flags that you evaluate on the server side. false

api_hoststring

URL of your PostHog instance. 'https://us.i.posthog.com'

api_methodstring
api_transport'XHR' | 'fetch'

The transport method to use for API requests. 'fetch'

autocaptureboolean | AutocaptureConfig

Determines whether PostHog should autocapture events. This setting does not affect capturing pageview events (see capture_pageview). true

before_sendBeforeSendFn | BeforeSendFn[]

This function or array of functions - if provided - are called immediately before sending data to the server. It allows you to edit data before it is sent, or choose not to send it all. if provided as an array the functions are called in the order they are provided any one function returning null means the event will not be sent

bootstrapBootstrapConfig

An object containing the distinctID, isIdentifiedID, and featureFlags keys, where distinctID is a string, and featureFlags is an object of key-value pairs. Since there is a delay between initializing PostHog and fetching feature flags, feature flags are not always available immediately. This makes them unusable if you want to do something like redirecting a user to a different page based on a feature flag. You can, therefore, fetch the feature flags in your server and pre-fill them here, allowing PostHog to know the feature flag values immediately. After the SDK fetches feature flags from PostHog, it will use those flag values instead of bootstrapped ones.

capture_dead_clicksboolean | DeadClicksAutoCaptureConfig

Determines whether to capture dead clicks.

capture_exceptionsboolean | ExceptionAutoCaptureConfig

Determines whether to capture exceptions.

capture_heatmapsboolean | HeatmapConfig

Determines whether to capture heatmaps.

capture_pageleaveboolean | 'if_capture_pageview'

Determines whether PostHog should capture pageleave events. If set to true, it will capture pageleave events for all pages. If set to 'if_capture_pageview', it will only capture pageleave events if capture_pageview is also set to true or 'history_change'. 'if_capture_pageview'

capture_pageviewboolean | 'history_change'

Determines whether PostHog should capture pageview events automatically. Can be: - true: Capture regular pageviews (default) - false: Don't capture any pageviews - 'history_change': Only capture pageviews on history API changes (pushState, replaceState, popstate) true

capture_performanceboolean | PerformanceCaptureConfig

Determines whether to capture performance metrics. These include Network Timing and Web Vitals. When undefined, fallback to the remote configuration. If false, neither network timing nor web vitals will work. If an object, that will override the remote configuration.

cookie_expirationnumber

Determines the number of days to store cookies for. 365

cookie_namestring
cross_subdomain_cookieboolean

Determines if cookie should be set on the top level domain (example.com). If PostHog-js is loaded on a subdomain (test.example.com), and cross_subdomain_cookie is set to false, it'll set the cookie on the subdomain only (test.example.com). NOTE: It will be set to false if we detect that the domain is a subdomain of a platform that is excluded from cross-subdomain cookie setting. The current list of excluded platforms is herokuapp.com, vercel.app, and netlify.app.

custom_blocked_useragentsstring[]

Used to extend the list of user agents that are blocked by default.

custom_campaign_paramsstring[]

Used to extend the list of campaign parameters that are saved by default.

custom_personal_data_propertiesstring[]

Custom list of personal data properties to mask. []

debugboolean

Determines whether PostHog should be in debug mode. You can enable this to get more detailed logging. You can also enable this on your website by appending ?__posthog_debug=true at the end of your URL You can also call posthog.debug() in your code to enable debug mode false

defaultsConfigDefaults

Configuration defaults for breaking changes. When set to a specific date, enables new default behaviors that were introduced on that date.

  • 'unset': Use legacy default behaviors - '2025-05-24': Use updated default behaviors (e.g. capture_pageview defaults to 'history_change') 'unset'
disable_compressionboolean

Determines whether to disable compression when sending events to the server. WARNING: Should only be used for testing. Could negatively impact performance. false

disable_cookieboolean
disable_external_dependency_loadingboolean

Determines whether PostHog should disable any external dependency loading. This will prevent PostHog from requesting any external scripts such as those needed for Session Replay, Surveys or Site Apps. false

disable_persistenceboolean

Determines whether PostHog should disable persistence. If set to true, the library will not save any data to the browser. It will also delete any data previously saved to the browser. false

disable_scroll_propertiesboolean

Determines whether to disable scroll properties. These allow you to keep track of how far down someone scrolled in your website. false

disable_session_recordingboolean

Determines whether PostHog should disable session recording. false

disable_surveys_automatic_displayboolean

Determines whether PostHog should disable automatic display of surveys. If this is true, popup or widget surveys will not be shown when display conditions are met. false

disable_surveysboolean

Determines whether PostHog should disable all surveys functionality. false

disable_web_experimentsboolean

Determines whether PostHog should disable web experiments. Currently disabled while we're in BETA. It will be toggled to true in a future release. true

enable_heatmapsboolean
enable_recording_console_logboolean

Determines whether PostHog should enable recording console logs. When undefined, it falls back to the remote config setting. undefined

error_trackingErrorTrackingOptions

Determines the error tracking options.

feature_flag_request_timeout_msnumber

Sets timeout for fetching feature flags 3000

fetch_options{ cache?: RequestInit['cache']; next_options?: NextOptions; }

Used when sending data via fetch, use with care. This is intentionally meant to be used with NextJS fetch Incorrect cache usage may cause out-of-date data for feature flags, actions tracking, etc. See https://nextjs.org/docs/app/api-reference/functions/fetch#fetchurl-options

get_device_id(uuid: string) => string

Function to get the device ID. This doesn't usually need to be set, but can be useful if you want to use a custom device ID.

inapp_link_new_windowboolean
inapp_protocolstring
integrationsRecord<ExternalIntegrationKind, boolean>

Used to set-up external integrations with PostHog data - such as session replays, distinct id, etc.

ipboolean
loaded(posthog_instance: PostHog) => void

A function to be called once the PostHog scripts have loaded successfully.

mask_all_element_attributesboolean

Prevent autocapture from capturing any attribute names on elements. false

mask_all_textboolean

Prevent autocapture from capturing textContent on elements. false

mask_personal_data_propertiesboolean

Prevent autocapture from capturing personal data properties. These include campaign parameters, UTM parameters, and other parameters that could be considered personal data under e.g. GDPR. false

namestring

The name this instance will be identified by. You don't need to set this most of the time, but can be useful if you have several Posthog instances running at the same time. 'posthog'

on_request_error(error: RequestResponse) => void

A function that is called when a request to the PostHog API fails.

on_xhr_error(failedRequest: XMLHttpRequest) => void
opt_in_site_appsboolean

Determines if users should be opted in to site apps. false

opt_out_capturing_by_defaultboolean

Determines if users should be opted out of PostHog tracking by default, requiring additional logic to opt them into capturing by calling posthog.opt_in_capturing(). false

opt_out_capturing_cookie_prefixstring | null

Determines the prefix for the cookie used to store the information about whether users are opted out of capturing. When null, it falls back to the default prefix found in consent.ts. null

opt_out_capturing_persistence_type'localStorage' | 'cookie'

Determines where we'll save the information about whether users are opted out of capturing. 'localStorage'

opt_out_persistence_by_defaultboolean

Determines if users should be opted out of browser data storage by this PostHog instance by default, requiring additional logic to opt them into capturing by calling posthog.opt_in_capturing(). false

opt_out_useragent_filterboolean

Determines if users should be opted out of user agent filtering such as googlebot or other bots. If this is set to true, PostHog will set $browser_type to either bot or browser for all events, but will process all events as if they were from a browser. false

persistence_namestring

The name for the super properties persistent store ''

persistence'localStorage' | 'cookie' | 'memory' | 'localStorage+cookie' | 'sessionStorage'

Determines how PostHog stores information about the user. See persistence for details. 'localStorage+cookie'

person_profiles'always' | 'never' | 'identified_only'

You can control whether events from PostHog-js have person processing enabled with the person_profiles config setting. There are three options: - person_profiles: 'always' - we will process persons data for all events - person_profiles: 'never' - we won't process persons for any event. This means that anonymous users will not be merged once they sign up or login, so you lose the ability to create funnels that track users from anonymous to identified. All events (including $identify) will be sent with $process_person_profile: False. - person_profiles: 'identified_only' (default) - we will only process persons when you call posthog.identify, posthog.alias, posthog.setPersonProperties, posthog.group, posthog.setPersonPropertiesForFlags or posthog.setGroupPropertiesForFlags Anonymous users won't get person profiles. 'identified_only'

prepare_external_dependency_script(script: HTMLScriptElement) => HTMLScriptElement | null

A function to be called when a script is being loaded. This can be used to modify the script before it is loaded. This is useful for adding a nonce to the script, for example.

prepare_external_dependency_stylesheet(stylesheet: HTMLStyleElement) => HTMLStyleElement | null

A function to be called when a stylesheet is being loaded. This can be used to modify the stylesheet before it is loaded. This is useful for adding a nonce to the stylesheet, for example.

process_person'always' | 'never' | 'identified_only'
properties_string_max_lengthnumber

Determines the maximum length of the properties string that can be sent with capture calls. 65535

property_blackliststring[]
property_denyliststring[]

A list of properties that should never be sent with capture calls. []

rageclickboolean

Determines whether PostHog should capture rage clicks. true

rate_limiting{ events_per_second?: number; events_burst_limit?: number; }

Client side rate limiting

request_batchingboolean

Determines whether PostHog should batch requests to the PostHog API. true

request_headers{ [header_name: string]: string; }

A list of headers that should be sent with requests to the PostHog API.

request_queue_configRequestQueueConfig

Used to change the behavior of the request queue. This is an advanced feature and should be used with caution.

respect_dntboolean

Determines whether PostHog should respect the Do Not Track header when computing consent in ConsentManager.

sanitize_properties((properties: Properties, event_name: string) => Properties) | null
save_campaign_paramsboolean

Determines whether PostHog should save marketing parameters. These are utm_* paramaters and friends.

save_referrerboolean

Determines whether PostHog should save referrer information. true

scroll_root_selectorstring | string[]

Let the pageview scroll stats use a custom css selector for the root element, e.g. main It will use window.document.documentElement if not specified.

secure_cookieboolean

Determines whether PostHog should use secure cookies. If this is true, PostHog cookies will be marked as secure, meaning they will only be transmitted over HTTPS. window.location.protocol === 'https:'

segmentSegmentAnalytics

The segment analytics object.

session_idle_timeout_secondsnumber

Determines the session idle timeout in seconds. Any new event that's happened after this timeout will create a new session. 30 * 60 -- 30 minutes

session_recordingSessionRecordingOptions

Determines the session recording options.

store_googleboolean
surveys_request_timeout_msnumber

Sets timeout for fetching surveys 10000

tokenstring

The token for your PostHog project. It should NOT be provided manually in the config, but rather passed as the first parameter to posthog.init().

ui_hoststring | null

If using a reverse proxy for api_host then this should be the actual PostHog app URL (e.g. https://us.posthog.com). This ensures that links to PostHog point to the correct host. null

upgradeboolean

Determines whether PostHog should upgrade old cookies. If set to true, the library will check for a cookie from our old js library and import super properties from it, then the old cookie is deleted. This option only works in the initialization, so make sure you set it when you create the library. false

verboseboolean
xhr_headers{ [header_name: string]: string; }

Community questions

Was this page useful?