PostHogConfig
Properties
| Name | Type |
|---|---|
name | string |
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. | |
api_host | string |
URL of your PostHog instance. | |
flags_api_host | string |
URL to use for feature flag requests specifically.
If not set, feature flag requests will use the URL derived from | |
ui_host | string |
If using a reverse proxy for | |
api_transport | "fetch" | "XHR" |
The transport method to use for API requests. | |
token | string |
The token for your PostHog project.
It should NOT be provided manually in the config, but rather passed as the first parameter to | |
autocapture | boolean | AutocaptureConfig |
Determines whether PostHog should autocapture events.
This setting does not affect capturing pageview events (see by default autocapture is ignored on elements that match a | |
rageclick | boolean | RageclickConfig |
Determines whether PostHog should capture rage clicks. By default, rage clicks are ignored on elements that match a | |
cross_subdomain_cookie | boolean |
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 NOTE: It will be set to | |
persistence | "localStorage" | "cookie" | "memory" | "localStorage+cookie" | "sessionStorage" |
Determines how PostHog stores information about the user. See persistence for details. | |
persistence_name | string |
The name for the super properties persistent store | |
cookie_name | string |
Deprecated: - Use 'persistence_name' instead | |
cookie_persisted_properties | readonly string[] |
List of custom property names that should be stored in cookies (in addition to the default ones) when using 'localStorage+cookie' persistence mode. This allows these properties to be shared across subdomains when cross_subdomain_cookie is enabled. | |
disable_capture_url_hashes | boolean |
Determines whether PostHog should strip URL fragments (
If your SPA relies on hash-based routes for analytics, enabling this is a breaking behavior change.
If you want to capture hashes selectively, leave this disabled and use | |
save_referrer | boolean |
Determines whether PostHog should save referrer information. | |
save_campaign_params | boolean |
Determines whether PostHog should save marketing parameters.
These are | |
store_google | boolean |
Deprecated: - Use | |
custom_campaign_params | string[] |
Used to extend the list of campaign parameters that are saved by default. | |
custom_blocked_useragents | string[] |
Used to extend the list of user agents that are blocked by default. | |
debug | boolean |
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 | |
verbose | boolean |
Deprecated: Use | |
capture_pageview | boolean | "history_change" |
Determines whether PostHog should capture pageview events automatically. Can be:
| |
capture_pageleave | boolean | "if_capture_pageview" |
Determines whether PostHog should capture pageleave events.
If set to | |
cookie_expiration | number |
Determines the number of days to store cookies for. | |
upgrade | boolean |
Determines whether PostHog should upgrade old cookies.
If set to | |
disable_session_recording | boolean |
Determines whether PostHog should disable session recording. | |
disable_persistence | boolean |
Determines whether PostHog should disable persistence.
If set to | |
disable_cookie | boolean |
Deprecated: - use | |
persistence_save_debounce_ms | number |
Coalesce rapid Set to a positive number (milliseconds) to debounce writes to localStorage / cookie
by that window. The in-memory Pending writes are flushed on Defaults to | |
split_storage | boolean |
Store the feature-flag config cluster and survey config in their own
localStorage entries ( Only applies when persistence resolves to | |
detect_google_search_app | boolean |
Detect the Google Search App (GSA) as its own Off by default for backwards-compatibility: enabling it reattributes
existing GSA traffic away from Mobile Safari / Chrome, which would
otherwise look like those browsers suddenly losing share. The | |
disable_surveys | boolean |
Determines whether PostHog should disable all surveys functionality. | |
disable_surveys_automatic_display | boolean |
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. | |
disable_product_tours | boolean |
Determines whether PostHog should disable all product tours functionality. | |
surveys | SurveyConfig |
Survey-specific configuration options. | |
logs | LogsConfig |
Logs-specific configuration options. | |
metrics | MetricsConfig |
Metrics-specific configuration options for the posthog.metrics API. | |
disable_conversations | boolean |
Determines whether PostHog should disable all conversations functionality. | |
identity_distinct_id | string |
Verified distinct_id for HMAC-based identity verification.
When both Can be set at init time or later via | |
identity_hash | string |
HMAC-SHA256 of | |
disable_web_experiments | boolean |
Determines whether PostHog should disable web experiments. Currently disabled while we're in BETA. It will be toggled to | |
disable_external_dependency_loading | boolean |
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. | |
strict_script_versioning | boolean |
Determines whether PostHog should load external dependency scripts from semver-qualified asset paths such as /static/1.370.0/recorder.js instead of the legacy /static/recorder.js?v=1.370.0 form. | |
asset_host | string |
Optional host override for static assets loaded by PostHog, such as recorder.js, surveys.js, or toolbar.js. Only applies to /static/* asset paths; dynamic assets like remote config continue to use the regular asset host derived from api_host. | |
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. | |
external_scripts_inject_target | "body" | "head" |
Where to inject external dependency scripts (recorder, surveys, etc.) in the DOM.
| |
enable_recording_console_log | boolean |
Determines whether PostHog should enable recording console logs. This is related to the Session Recording feature. For more session recording
settings, see the | |
secure_cookie | boolean |
Determines whether PostHog should use secure cookies.
If this is | |
opt_out_capturing_by_default | boolean |
Determines if users should be opted out of PostHog tracking by default,
requiring additional logic to opt them into capturing by calling | |
opt_out_capturing_persistence_type | "localStorage" | "cookie" |
Determines where we'll save the information about whether users are opted out of capturing. | |
opt_out_persistence_by_default | boolean |
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 | |
opt_out_useragent_filter | boolean |
Determines if users should be opted out of user agent filtering such as googlebot or other bots.
If this is set to | |
opt_out_capturing_cookie_prefix | string |
Deprecated: Use | |
consent_persistence_name | string |
Determines the key for the cookie / local storage used to store the information about whether users are opted in/out of capturing.
When | |
opt_in_site_apps | boolean |
Determines if users should be opted in to site apps. | |
respect_dnt | boolean |
Determines whether PostHog should respect the Do Not Track header when computing
consent in | |
property_denylist | string[] |
A list of properties that should never be sent with capture calls. | |
property_blacklist | string[] |
Deprecated: - use | |
request_headers | { [header_name: string]: string; } |
A list of headers that should be sent with requests to the PostHog API. | |
xhr_headers | { [header_name: string]: string; } |
Deprecated: - use | |
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 |
Deprecated: - use | |
request_batching | boolean |
Determines whether PostHog should batch requests to the PostHog API. | |
properties_string_max_length | number |
Determines the maximum length of the properties string that can be sent with capture calls. | |
defaults | ConfigDefaults |
Configuration defaults for breaking changes. When set to a specific date, enables new default behaviors that were introduced on that date.
| |
session_recording | SessionRecordingOptions |
Determines the session recording options. For more session recording settings, see the | |
error_tracking | ErrorTrackingOptions |
Determines the error tracking options. | |
session_idle_timeout_seconds | number |
Determines the session idle timeout in seconds. If no events are captured for this many seconds, the next event starts a
new session with a new Session recording has a separate idle threshold: Must be between 60 seconds and 10 hours. Values outside this range are clamped. | |
mask_all_element_attributes | boolean |
Prevent autocapture from capturing any attribute names on elements. | |
mask_all_text | boolean |
Prevent autocapture from capturing | |
mask_personal_data_properties | boolean |
Mask personal data properties from the current URL.
This will mask personal data properties such as advertising IDs (gclid, fbclid, etc.), and you can also add
custom properties to mask with | |
custom_personal_data_properties | string[] |
Custom list of personal data properties to mask. E.g. if you added | |
advanced_disable_flags | boolean |
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. WARNING: Disabling this will also prevent remote configuration from loading, which could mean features like web vitals, surveys, and other features configured in PostHog settings are disabled unless explicitly enabled via client-side config. When setting this to true, make sure to explicitly configure any features you want to use (e.g., capture_performance, autocapture, etc.) in your SDK's init config. | |
advanced_disable_decide | boolean |
Deprecated: Use One of the very first things the PostHog library does when init() is called is make a request to the /decide endpoint on PostHog's backend. This endpoint contains information on how to run the PostHog library so events are properly received in the backend. This endpoint is required to run most features of the 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. | |
advanced_disable_feature_flags | boolean |
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). | |
advanced_disable_feature_flags_on_first_load | boolean |
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. | |
evaluation_contexts | readonly string[] |
Evaluation contexts for feature flags. When set, only feature flags that have at least one matching evaluation tag will be evaluated for this SDK instance. Feature flags with no evaluation tags will always be evaluated. Examples: ['production', 'web', 'checkout'] | |
flag_keys | readonly string[] |
List of feature flag keys to remotely evaluate for this SDK instance.
When set, only these flags are evaluated by Examples: ['checkout-redesign', 'new-onboarding'] | |
evaluation_environments | readonly string[] |
Evaluation environments for feature flags. Deprecated: Use evaluation_contexts instead. This property will be removed in a future version. | |
advanced_disable_toolbar_metrics | boolean |
Determines whether PostHog should disable toolbar metrics. This is our internal instrumentation for our toolbar in your website. | |
advanced_only_evaluate_survey_feature_flags | boolean |
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. | |
advanced_enable_surveys | boolean |
When this is enabled, surveys will always be initialized, regardless of the /flags response or remote config settings. This is useful if you want to use surveys but disable all other flag-dependent functionality. Used internally for displaying external surveys without making a /flags request. | |
feature_flag_request_timeout_ms | number |
Sets timeout for fetching feature flags | |
feature_flag_cache_ttl_ms | number |
Sets the maximum age (in milliseconds) for cached feature flag values. When the cache is older than this value:
This prevents stale feature flag values from being used when the When not set or set to | |
advanced_feature_flags_dedup_per_session | boolean |
When enabled, By default, the SDK deduplicates When this option is | |
surveys_request_timeout_ms | number |
Sets timeout for fetching surveys | |
remote_config_refresh_interval_ms | number |
Controls how often feature flags are automatically refreshed in long-running sessions after remote configuration has loaded. By default, feature flags are refreshed every 5 minutes (300000ms) to pick up server-side flag changes without requiring a page reload. This is useful for SPAs and long-running tabs. Tradeoffs:
Note: Refreshes are automatically skipped when the browser tab is hidden or no document is available. | |
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. | |
before_send | BeforeSendFn | 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 | |
get_current_url | (defaultUrl: string) => string |
Overrides the URL used for client-side URL targeting: session replay URL triggers, the session replay URL blocklist, survey URL display conditions, product tour URL conditions, web experiment URL conditions, and autocapture URL allow/ignore lists. These features match against | |
sanitize_properties | (properties: Properties, event_name: string) => Properties |
Deprecated: - use | |
_onCapture | (eventName: string, eventData: CaptureResult) => void |
Deprecated: - use | |
capture_performance | boolean | PerformanceCaptureConfig |
Determines whether to capture performance metrics. These include Network Timing for Session Replay and Web Vitals. The When | |
disable_compression | boolean |
Determines whether to disable compression when sending events to the server. WARNING: Should only be used for testing. Could negatively impact performance. | |
bootstrap | BootstrapConfig |
An object containing the 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. | |
segment | SegmentAnalytics |
The segment analytics object. | |
capture_heatmaps | boolean | HeatmapConfig |
Determines whether to capture heatmaps. | |
enable_heatmaps | boolean |
Deprecated: Use | |
capture_dead_clicks | boolean | DeadClicksAutoCaptureConfig |
Determines whether to capture dead clicks. by default dead clicks are ignored on elements that match a | |
capture_exceptions | boolean | ExceptionAutoCaptureConfig |
Determines whether to capture exceptions. | |
disable_scroll_properties | boolean |
Determines whether to disable scroll properties. These allow you to keep track of how far down someone scrolled in your website. | |
scroll_root_selector | string | string[] |
Let the pageview scroll stats use a custom css selector for the root element, e.g. | |
person_profiles | "always" | "never" | "identified_only" |
You can control whether events from PostHog-js have person processing enabled with the
| |
process_person | "always" | "never" | "identified_only" |
Deprecated: - use | |
rate_limiting | { events_per_second?: number; events_burst_limit?: number; } |
Client side rate limiting | |
fetch_options | { cache?: RequestCache; next_options?: { revalidate: false | 0 | number; tags: string[]; }; } |
Used when sending data via Incorrect | |
request_queue_config | RequestQueueConfig |
Used to change the behavior of the request queue. This is an advanced feature and should be used with caution. | |
integrations | Record<ExternalIntegrationKind, boolean> |
Used to set-up external integrations with PostHog data - such as session replays, distinct id, etc. | |
cookieless_mode | "always" | "on_reject" |
Enables cookieless mode. In this mode, PostHog will not set any cookies, or use session or local storage. User identity is handled by generating a privacy-preserving hash on PostHog's servers. Web Vitals (
Note that you MUST enable cookieless mode in your PostHog project's settings, otherwise all your cookieless events will be ignored. We plan to remove this requirement in the future. | |
internal_or_test_user_hostname | string | RegExp |
A hostname pattern to match test environments. When the current hostname matches,
Can be a string (exact match) or RegExp (pattern match).
Set to | |
override_display_language | string |
Display language override for Product Tours. Must be a valid BCP 47 language code. In the future this will be used for Surveys and other products that deliver in-app experiences to end-users. | |
tracing_headers | string[] |
A list of hostnames for which to inject PostHog tracing headers to all requests (X-POSTHOG-DISTINCT-ID, X-POSTHOG-SESSION-ID, X-POSTHOG-WINDOW-ID). Used to link frontend sessions to backend traces (see https://posthog.com/docs/llm-analytics/link-session-replay). | |
addTracingHeaders | string[] |
Deprecated: Use {@link tracing_headers} instead. Kept for backwards compatibility. | |
__add_tracing_headers | string[] |
Deprecated: Use {@link tracing_headers} instead. Kept for backwards compatibility. | |
__preview_flags_v2 | boolean |
Deprecated: This option is a no-op. The browser SDK already uses the | |
__preview_eager_load_replay | boolean |
Deprecated: This option is a no-op. Session replay is lazy-loaded by default. | |
disable_beacon | boolean |
Prevents posthog-js from using the | |
__preview_disable_beacon | boolean |
Deprecated: Use | |
__preview_disable_xhr_credentials | boolean |
Deprecated: This option is a no-op. The browser SDK no longer sets | |
__preview_external_dependency_versioned_paths | string | boolean |
Deprecated: Use {@link strict_script_versioning} and {@link asset_host} instead. When set to true, this is equivalent to strict_script_versioning: true. When set to a string, this is equivalent to strict_script_versioning: true and asset_host set to that string. | |
__preview_lazy_load_replay | boolean |
Deprecated: - does nothing was present only for PostHog testing of replay lazy loading | |
api_method | string |
Deprecated: - NOT USED ANYMORE, kept here for backwards compatibility reasons | |
inapp_protocol | string |
Deprecated: - NOT USED ANYMORE, kept here for backwards compatibility reasons | |
inapp_link_new_window | boolean |
Deprecated: - NOT USED ANYMORE, kept here for backwards compatibility reasons | |
ip | boolean |
Deprecated: - THIS OPTION HAS NO EFFECT, kept here for backwards compatibility reasons. Use a custom transformation or "Discard IP data" project setting instead: | |
loaded | (posthog: PostHogInterface) => void |
disableDeviceModel | boolean |
Disables capturing the When capturing is enabled (the default), PostHog resolves the hardware model once during init
via This opt-out is offered because | |