Skip to main content
Glama
module.d.ts115 kB
import { eventWithTime, blockClass, maskTextClass, hooksParam, PackFn, SamplingStrategy, RecordPlugin, KeepIframeSrcFn } from '@rrweb/types'; declare class RageClick { clicks: { x: number; y: number; timestamp: number; }[]; constructor(); isRageClick(x: number, y: number, timestamp: number): boolean; } type MaskInputOptions = Partial<{ color: boolean; date: boolean; 'datetime-local': boolean; email: boolean; month: boolean; number: boolean; range: boolean; search: boolean; tel: boolean; text: boolean; time: boolean; url: boolean; week: boolean; textarea: boolean; select: boolean; password: boolean; }>; type MaskInputFn = (text: string, element: HTMLElement) => string; type MaskTextFn = (text: string, element: HTMLElement | null) => string; type SlimDOMOptions = Partial<{ script: boolean; comment: boolean; headFavicon: boolean; headWhitespace: boolean; headMetaDescKeywords: boolean; headMetaSocial: boolean; headMetaRobots: boolean; headMetaHttpEquiv: boolean; headMetaAuthorship: boolean; headMetaVerification: boolean; headTitleMutations: boolean; }>; type DataURLOptions = Partial<{ type: string; quality: number; }>; type ErrorHandler = (error: unknown) => void | boolean; type recordOptions = { emit?: (e: eventWithTime, isCheckout?: boolean) => void; checkoutEveryNth?: number; checkoutEveryNms?: number; blockClass?: blockClass; blockSelector?: string; ignoreClass?: string; ignoreSelector?: string; maskTextClass?: maskTextClass; maskTextSelector?: string; maskAllInputs?: boolean; maskInputOptions?: MaskInputOptions; maskInputFn?: MaskInputFn; maskTextFn?: MaskTextFn; slimDOMOptions?: SlimDOMOptions | 'all' | true; ignoreCSSAttributes?: Set<string>; inlineStylesheet?: boolean; hooks?: hooksParam; packFn?: PackFn; sampling?: SamplingStrategy; dataURLOptions?: DataURLOptions; recordDOM?: boolean; recordCanvas?: boolean; recordCrossOriginIframes?: boolean; recordAfter?: 'DOMContentLoaded' | 'load'; userTriggeredOnInput?: boolean; collectFonts?: boolean; inlineImages?: boolean; plugins?: RecordPlugin[]; mousemoveWait?: number; keepIframeSrcFn?: KeepIframeSrcFn; errorHandler?: ErrorHandler; }; /** * Extend Segment with extra PostHog JS functionality. Required for things like Recordings and feature flags to work correctly. * * ### Usage * * ```js * // After your standard segment anyalytics install * analytics.load("GOEDfA21zZTtR7clsBuDvmBKAtAdZ6Np"); * * analytics.ready(() => { * posthog.init('<posthog-api-key>', { * capture_pageview: false, * segment: window.analytics, // NOTE: Be sure to use window.analytics here! * }); * window.analytics.page(); * }) * ``` */ type SegmentUser = { anonymousId(): string | undefined; id(): string | undefined; }; type SegmentAnalytics = { user: () => SegmentUser | Promise<SegmentUser>; register: (integration: SegmentPlugin) => Promise<void>; }; interface SegmentContext { event: { event: string; userId?: string; anonymousId?: string; properties: any; }; } type SegmentFunction = (ctx: SegmentContext) => Promise<SegmentContext> | SegmentContext; interface SegmentPlugin { name: string; version: string; type: 'enrichment'; isLoaded: () => boolean; load: (ctx: SegmentContext, instance: any, config?: any) => Promise<unknown>; unload?: (ctx: SegmentContext, instance: any) => Promise<unknown> | unknown; ready?: () => Promise<unknown>; track?: SegmentFunction; identify?: SegmentFunction; page?: SegmentFunction; group?: SegmentFunction; alias?: SegmentFunction; screen?: SegmentFunction; } type Property = any; type Properties = Record<string, Property>; declare const COPY_AUTOCAPTURE_EVENT = "$copy_autocapture"; declare const knownUnsafeEditableEvent: readonly ["$snapshot", "$pageview", "$pageleave", "$set", "survey dismissed", "survey sent", "survey shown", "$identify", "$groupidentify", "$create_alias", "$$client_ingestion_warning", "$web_experiment_applied", "$feature_enrollment_update", "$feature_flag_called"]; /** * These events can be processed by the `beforeCapture` function * but can cause unexpected confusion in data. * * Some features of PostHog rely on receiving 100% of these events */ type KnownUnsafeEditableEvent = (typeof knownUnsafeEditableEvent)[number]; /** * These are known events PostHog events that can be processed by the `beforeCapture` function * That means PostHog functionality does not rely on receiving 100% of these for calculations * So, it is safe to sample them to reduce the volume of events sent to PostHog */ type KnownEventName = '$heatmaps_data' | '$opt_in' | '$exception' | '$$heatmap' | '$web_vitals' | '$dead_click' | '$autocapture' | typeof COPY_AUTOCAPTURE_EVENT | '$rageclick'; type EventName = KnownUnsafeEditableEvent | KnownEventName | (string & {}); interface CaptureResult { uuid: string; event: EventName; properties: Properties; $set?: Properties; $set_once?: Properties; timestamp?: Date; } type AutocaptureCompatibleElement = 'a' | 'button' | 'form' | 'input' | 'select' | 'textarea' | 'label'; type DomAutocaptureEvents = 'click' | 'change' | 'submit'; /** * If an array is passed for an allowlist, autocapture events will only be sent for elements matching * at least one of the elements in the array. Multiple allowlists can be used */ interface AutocaptureConfig { /** * List of URLs to allow autocapture on, can be strings to match * or regexes e.g. ['https://example.com', 'test.com/.*'] * this is useful when you want to autocapture on specific pages only * * if you set both url_allowlist and url_ignorelist, * we check the allowlist first and then the ignorelist. * the ignorelist can override the allowlist */ url_allowlist?: (string | RegExp)[]; /** * List of URLs to not allow autocapture on, can be strings to match * or regexes e.g. ['https://example.com', 'test.com/.*'] * this is useful when you want to autocapture on most pages but not some specific ones * * if you set both url_allowlist and url_ignorelist, * we check the allowlist first and then the ignorelist. * the ignorelist can override the allowlist */ url_ignorelist?: (string | RegExp)[]; /** * List of DOM events to allow autocapture on e.g. ['click', 'change', 'submit'] */ dom_event_allowlist?: DomAutocaptureEvents[]; /** * List of DOM elements to allow autocapture on * e.g. ['a', 'button', 'form', 'input', 'select', 'textarea', 'label'] * * We consider the tree of elements from the root to the target element of the click event * so for the tree `div > div > button > svg` * if the allowlist has `button` then we allow the capture when the `button` or the `svg` is the click target * but not if either of the `div`s are detected as the click target */ element_allowlist?: AutocaptureCompatibleElement[]; /** * List of CSS selectors to allow autocapture on * e.g. ['[ph-capture]'] * we consider the tree of elements from the root to the target element of the click event * so for the tree div > div > button > svg * and allow list config `['[id]']` * we will capture the click if the click-target or its parents has any id * * Everything is allowed when there's no allowlist */ css_selector_allowlist?: string[]; /** * Exclude certain element attributes from autocapture * E.g. ['aria-label'] or [data-attr-pii] */ element_attribute_ignorelist?: string[]; /** * When set to true, autocapture will capture the text of any element that is cut or copied. */ capture_copied_text?: boolean; } interface BootstrapConfig { distinctID?: string; isIdentifiedID?: boolean; featureFlags?: Record<string, boolean | string>; featureFlagPayloads?: Record<string, JsonType>; /** * Optionally provide a sessionID, this is so that you can provide an existing sessionID here to continue a user's session across a domain or device. It MUST be: * - unique to this user * - a valid UUID v7 * - the timestamp part must be <= the timestamp of the first event in the session * - the timestamp of the last event in the session must be < the timestamp part + 24 hours * **/ sessionID?: string; } type SupportedWebVitalsMetrics = 'LCP' | 'CLS' | 'FCP' | 'INP'; interface PerformanceCaptureConfig { /** * Works with session replay to use the browser's native performance observer to capture performance metrics */ network_timing?: boolean; /** * Use chrome's web vitals library to wrap fetch and capture web vitals */ web_vitals?: boolean; /** * We observe very large values reported by the Chrome web vitals library * These outliers are likely not real, useful values, and we exclude them * You can set this to 0 in order to include all values, NB this is not recommended * * @default 15 * 60 * 1000 (15 minutes) */ __web_vitals_max_value?: number; /** * By default all 4 metrics are captured * You can set this config to restrict which metrics are captured * e.g. ['CLS', 'FCP'] to only capture those two metrics * NB setting this does not override whether the capture is enabled * * @default ['LCP', 'CLS', 'FCP', 'INP'] */ web_vitals_allowed_metrics?: SupportedWebVitalsMetrics[]; /** * We delay flushing web vitals metrics to reduce the number of events we send * This is the maximum time we will wait before sending the metrics * * @default 5000 */ web_vitals_delayed_flush_ms?: number; } interface DeadClickCandidate { node: Element; originalEvent: MouseEvent; timestamp: number; scrollDelayMs?: number; mutationDelayMs?: number; selectionChangedDelayMs?: number; absoluteDelayMs?: number; } type DeadClicksAutoCaptureConfig = { /** * We'll not consider a click to be a dead click, if it's followed by a scroll within `scroll_threshold_ms` milliseconds * * @default 100 */ scroll_threshold_ms?: number; /** * We'll not consider a click to be a dead click, if it's followed by a selection change within `selection_change_threshold_ms` milliseconds * * @default 100 */ selection_change_threshold_ms?: number; /** * We'll not consider a click to be a dead click, if it's followed by a mutation within `mutation_threshold_ms` milliseconds * * @default 2500 */ mutation_threshold_ms?: number; /** * Allows setting behavior for when a dead click is captured. * For e.g. to support capture to heatmaps * * If not provided the default behavior is to auto-capture dead click events * * Only intended to be provided by our own SDK */ __onCapture?: ((click: DeadClickCandidate, properties: Properties) => void) | undefined; } & Pick<AutocaptureConfig, 'element_attribute_ignorelist'>; interface HeatmapConfig { /** * How often to send batched data in `$heatmap_data` events * If set to 0 or not set, sends using the default interval of 1 second * * @default 1000 */ flush_interval_milliseconds: number; } type BeforeSendFn = (cr: CaptureResult | null) => CaptureResult | null; /** * Configuration options for the PostHog JavaScript SDK. * @see https://posthog.com/docs/libraries/js#config */ interface PostHogConfig { /** URL of your PostHog instance. * * @default 'https://us.i.posthog.com' */ api_host: string; /** * 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. * * @default null */ ui_host: string | null; /** * The transport method to use for API requests. * * @default 'fetch' */ api_transport?: 'XHR' | 'fetch'; /** * 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()`. */ token: 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. * * @default 'posthog' */ name: string; /** * Determines whether PostHog should autocapture events. * This setting does not affect capturing pageview events (see `capture_pageview`). * * @default true */ autocapture: boolean | AutocaptureConfig; /** * Determines whether PostHog should capture rage clicks. * * @default true */ rageclick: 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 `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`. * * @see `isCrossDomainCookie` * @default true */ cross_subdomain_cookie: boolean; /** * Determines how PostHog stores information about the user. See [persistence](https://posthog.com/docs/libraries/js#persistence) for details. * * @default 'localStorage+cookie' */ persistence: 'localStorage' | 'cookie' | 'memory' | 'localStorage+cookie' | 'sessionStorage'; /** * The name for the super properties persistent store * * @default '' */ persistence_name: string; /** @deprecated - Use 'persistence_name' instead */ cookie_name?: string; /** * A function to be called once the PostHog scripts have loaded successfully. * * @param posthog_instance - The PostHog instance that has been loaded. */ loaded: (posthog_instance: PostHog) => void; /** * Determines whether PostHog should save referrer information. * * @default true */ save_referrer: boolean; /** * Determines whether PostHog should save marketing parameters. * These are `utm_*` paramaters and friends. * * @see {CAMPAIGN_PARAMS} from './utils/event-utils' - Default campaign parameters like utm_source, utm_medium, etc. * @default true */ save_campaign_params: boolean; /** @deprecated - Use `save_campaign_params` instead */ store_google?: boolean; /** * Used to extend the list of campaign parameters that are saved by default. * * @see {CAMPAIGN_PARAMS} from './utils/event-utils' - Default campaign parameters like utm_source, utm_medium, etc. * @default [] */ custom_campaign_params: string[]; /** * Used to extend the list of user agents that are blocked by default. * * @see {DEFAULT_BLOCKED_UA_STRS} from './utils/blocked-uas' - Default list of blocked user agents. * @default [] */ custom_blocked_useragents: string[]; /** * 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 * * @default false */ debug: boolean; /** @deprecated Use `debug` instead */ verbose?: boolean; /** * Determines whether PostHog should capture pageview events automatically. * * @default true */ capture_pageview: boolean; /** * 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`. * * @default 'if_capture_pageview' */ capture_pageleave: boolean | 'if_capture_pageview'; /** * Determines the number of days to store cookies for. * * @default 365 */ cookie_expiration: number; /** * 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. * * @default false */ upgrade: boolean; /** * Determines whether PostHog should disable session recording. * * @default false */ disable_session_recording: boolean; /** * 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. * * @default false */ disable_persistence: boolean; /** @deprecated - use `disable_persistence` instead */ disable_cookie?: boolean; /** * Determines whether PostHog should disable surveys. * * @default false */ disable_surveys: boolean; /** * Determines whether PostHog should disable web experiments. * * Currently disabled while we're in BETA. It will be toggled to `true` in a future release. * * @default true */ disable_web_experiments: 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. * * @default false */ disable_external_dependency_loading: boolean; /** * 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. * * @param script - The script element that is being loaded. * @returns The modified script element, or null if the script should not be loaded. */ prepare_external_dependency_script?: (script: HTMLScriptElement) => HTMLScriptElement | 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. * * @param stylesheet - The stylesheet element that is being loaded. * @returns The modified stylesheet element, or null if the stylesheet should not be loaded. */ prepare_external_dependency_stylesheet?: (stylesheet: HTMLStyleElement) => HTMLStyleElement | null; /** * Determines whether PostHog should enable recording console logs. * When undefined, it falls back to the remote config setting. * * @default undefined */ enable_recording_console_log?: boolean; /** * 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. * * @default window.location.protocol === 'https:' */ secure_cookie: boolean; /** * Determines whether PostHog should capture IP addresses. * * @default true */ ip: boolean; /** * 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()`. * * @default false */ opt_out_capturing_by_default: boolean; /** * Determines where we'll save the information about whether users are opted out of capturing. * * @default 'localStorage' */ opt_out_capturing_persistence_type: 'localStorage' | 'cookie'; /** * 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()`. * * @default false */ opt_out_persistence_by_default?: boolean; /** * 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. * * @default false */ opt_out_useragent_filter: boolean; /** * 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`. * * @default null */ opt_out_capturing_cookie_prefix: string | null; /** * Determines if users should be opted in to site apps. * * @default false */ opt_in_site_apps: boolean; /** * Determines whether PostHog should respect the Do Not Track header when computing * consent in `ConsentManager`. * * @see `ConsentManager` * @default false */ respect_dnt: boolean; /** * A list of properties that should never be sent with capture calls. * * @default [] */ property_denylist: string[]; /** @deprecated - use `property_denylist` instead */ property_blacklist?: string[]; /** * A list of headers that should be sent with requests to the PostHog API. * * @default {} */ request_headers: { [header_name: string]: string; }; /** @deprecated - use `request_headers` instead */ xhr_headers?: { [header_name: string]: string; }; /** * A function that is called when a request to the PostHog API fails. * * @param error - The `RequestResponse` object that occurred. */ on_request_error?: (error: RequestResponse) => void; /** @deprecated - use `on_request_error` instead */ on_xhr_error?: (failedRequest: XMLHttpRequest) => void; /** * Determines whether PostHog should batch requests to the PostHog API. * * @default true */ request_batching: boolean; /** * Determines the maximum length of the properties string that can be sent with capture calls. * * @default 65535 */ properties_string_max_length: number; /** * Determines the session recording options. * * @see `SessionRecordingOptions` * @default {} */ session_recording: SessionRecordingOptions; /** * Determines the session idle timeout in seconds. * Any new event that's happened after this timeout will create a new session. * * @default 30 * 60 -- 30 minutes */ session_idle_timeout_seconds: number; /** * Prevent autocapture from capturing any attribute names on elements. * * @default false */ mask_all_element_attributes: boolean; /** * Prevent autocapture from capturing `textContent` on elements. * * @default false */ mask_all_text: boolean; /** * 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. * * @default false */ mask_personal_data_properties: boolean; /** * Custom list of personal data properties to mask. * * @default [] */ custom_personal_data_properties: string[]; /** * 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. * * @default false */ advanced_disable_decide: boolean; /** * Will keep /decide running, but without any feature flag requests * * @default false */ advanced_disable_feature_flags: 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. * * @default false */ advanced_disable_feature_flags_on_first_load: boolean; /** * Determines whether PostHog should disable toolbar metrics. * This is our internal instrumentation for our toolbar in your website. * * @default false */ advanced_disable_toolbar_metrics: boolean; /** * Sets timeout for fetching feature flags * * @default 3000 */ feature_flag_request_timeout_ms: number; /** * Sets timeout for fetching surveys * * @default 10000 */ surveys_request_timeout_ms: number; /** * 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. * * @param uuid - The UUID we would use for the device ID. * @returns The device ID. * * @default (uuid) => uuid */ get_device_id: (uuid: string) => string; /** * 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 */ before_send?: BeforeSendFn | BeforeSendFn[]; /** @deprecated - use `before_send` instead */ sanitize_properties: ((properties: Properties, event_name: string) => Properties) | null; /** @deprecated - use `before_send` instead */ _onCapture: (eventName: string, eventData: CaptureResult) => void; /** * 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. * * @see {PerformanceCaptureConfig} * @default undefined */ capture_performance?: boolean | PerformanceCaptureConfig; /** * Determines whether to disable compression when sending events to the server. * WARNING: Should only be used for testing. Could negatively impact performance. * * @default false */ disable_compression: boolean; /** * 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. * * @default {} */ bootstrap: BootstrapConfig; /** * The segment analytics object. * * @see https://posthog.com/docs/libraries/segment */ segment?: SegmentAnalytics; /** * Determines whether to capture heatmaps. * * @see {HeatmapConfig} * @default undefined */ capture_heatmaps?: boolean | HeatmapConfig; enable_heatmaps?: boolean; /** * Determines whether to capture dead clicks. * * @see {DeadClicksAutoCaptureConfig} * @default undefined */ capture_dead_clicks?: boolean | DeadClicksAutoCaptureConfig; /** * Determines whether to capture exceptions. * * @default undefined */ capture_exceptions?: boolean; /** * Determines whether to disable scroll properties. * These allow you to keep track of how far down someone scrolled in your website. * * @default false */ disable_scroll_properties?: boolean; /** * 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. */ scroll_root_selector?: string | string[]; /** * 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. * * @default 'identified_only' */ person_profiles?: 'always' | 'never' | 'identified_only'; /** @deprecated - use `person_profiles` instead */ process_person?: 'always' | 'never' | 'identified_only'; /** * Client side rate limiting */ rate_limiting?: { /** * The average number of events per second that should be permitted * * @default 10 */ events_per_second?: number; /** * How many events can be captured in a burst. This defaults to 10 times the events_per_second count * * @default 10 * `events_per_second` */ events_burst_limit?: number; }; /** * 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 */ fetch_options?: { cache?: RequestInit['cache']; next_options?: NextOptions; }; /** * Used to change the behavior of the request queue. * This is an advanced feature and should be used with caution. */ request_queue_config?: RequestQueueConfig; /** * PREVIEW - MAY CHANGE WITHOUT WARNING - DO NOT USE IN PRODUCTION * Whether to wrap fetch and add tracing headers to the request * */ __add_tracing_headers?: boolean; /** * PREVIEW - MAY CHANGE WITHOUT WARNING - DO NOT USE IN PRODUCTION * Enables the new RemoteConfig approach to loading config instead of decide * */ __preview_remote_config?: boolean; /** * 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_experimental_cookieless_mode?: boolean; /** @deprecated - NOT USED ANYMORE, kept here for backwards compatibility reasons */ 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; } interface SessionRecordingOptions { /** * Derived from `rrweb.record` options * @see https://github.com/rrweb-io/rrweb/blob/master/guide.md * @default 'ph-no-capture' */ blockClass?: string | RegExp; /** * Derived from `rrweb.record` options * @see https://github.com/rrweb-io/rrweb/blob/master/guide.md * @default null */ blockSelector?: string | null; /** * Derived from `rrweb.record` options * @see https://github.com/rrweb-io/rrweb/blob/master/guide.md * @default 'ph-ignore-input' */ ignoreClass?: string | RegExp; /** * Derived from `rrweb.record` options * @see https://github.com/rrweb-io/rrweb/blob/master/guide.md * @default 'ph-mask' */ maskTextClass?: string | RegExp; /** * Derived from `rrweb.record` options * @see https://github.com/rrweb-io/rrweb/blob/master/guide.md */ maskTextSelector?: string | null; /** * Derived from `rrweb.record` options * @see https://github.com/rrweb-io/rrweb/blob/master/guide.md */ maskTextFn?: ((text: string, element?: HTMLElement) => string) | null; /** * Derived from `rrweb.record` options * @see https://github.com/rrweb-io/rrweb/blob/master/guide.md */ maskAllInputs?: boolean; /** * Derived from `rrweb.record` options * @see https://github.com/rrweb-io/rrweb/blob/master/guide.md */ maskInputOptions?: recordOptions['maskInputOptions']; /** * Derived from `rrweb.record` options * @see https://github.com/rrweb-io/rrweb/blob/master/guide.md */ maskInputFn?: ((text: string, element?: HTMLElement) => string) | null; /** * Derived from `rrweb.record` options * @see https://github.com/rrweb-io/rrweb/blob/master/guide.md * @default {} */ slimDOMOptions?: recordOptions['slimDOMOptions']; /** * Derived from `rrweb.record` options * @see https://github.com/rrweb-io/rrweb/blob/master/guide.md * @default false */ collectFonts?: boolean; /** * Derived from `rrweb.record` options * @see https://github.com/rrweb-io/rrweb/blob/master/guide.md * @default true */ inlineStylesheet?: boolean; /** * Derived from `rrweb.record` options * @see https://github.com/rrweb-io/rrweb/blob/master/guide.md * @default false */ recordCrossOriginIframes?: boolean; /** * Derived from `rrweb.record` options * @see https://github.com/rrweb-io/rrweb/blob/master/guide.md * @default false */ recordHeaders?: boolean; /** * Derived from `rrweb.record` options * @see https://github.com/rrweb-io/rrweb/blob/master/guide.md * @default false */ recordBody?: boolean; /** * Allows local config to override remote canvas recording settings from the decide response */ captureCanvas?: SessionRecordingCanvasOptions; /** * Modify the network request before it is captured. Returning null or undefined stops it being captured */ maskCapturedNetworkRequestFn?: ((data: CapturedNetworkRequest) => CapturedNetworkRequest | null | undefined) | null; /** @deprecated - use maskCapturedNetworkRequestFn instead */ maskNetworkRequestFn?: ((data: NetworkRequest) => NetworkRequest | null | undefined) | null; /** * ADVANCED: while a user is active we take a full snapshot of the browser every interval. * For very few sites playback performance might be better with different interval. * Set to 0 to disable * * @default 1000 * 60 * 5 (5 minutes) */ full_snapshot_interval_millis?: number; /** * ADVANCED: whether to partially compress rrweb events before sending them to the server, * defaults to true, can be set to false to disable partial compression * NB requests are still compressed when sent to the server regardless of this setting * * @default true */ compress_events?: boolean; /** * ADVANCED: alters the threshold before a recording considers a user has become idle. * Normally only altered alongside changes to session_idle_timeout_ms. * * @default 1000 * 60 * 5 (5 minutes) */ session_idle_threshold_ms?: number; /** * ADVANCED: alters the refill rate for the token bucket mutation throttling * Normally only altered alongside posthog support guidance. * Accepts values between 0 and 100 * * @default 10 */ __mutationRateLimiterRefillRate?: number; /** * ADVANCED: alters the bucket size for the token bucket mutation throttling * Normally only altered alongside posthog support guidance. * Accepts values between 0 and 100 * * @default 100 */ __mutationRateLimiterBucketSize?: number; } type SessionIdChangedCallback = (sessionId: string, windowId: string | null | undefined, changeReason?: { noSessionId: boolean; activityTimeout: boolean; sessionPastMaximumLength: boolean; }) => void; declare enum Compression { GZipJS = "gzip-js", Base64 = "base64" } interface RequestResponse { statusCode: number; text?: string; json?: any; } type RequestCallback = (response: RequestResponse) => void; type NextOptions = { revalidate: false | 0 | number; tags: string[]; }; interface RequestWithOptions { url: string; data?: Record<string, any> | Record<string, any>[]; headers?: Record<string, any>; transport?: 'XHR' | 'fetch' | 'sendBeacon'; method?: 'POST' | 'GET'; urlQueryArgs?: { compression: Compression; }; callback?: RequestCallback; timeout?: number; noRetries?: boolean; compression?: Compression | 'best-available'; fetchOptions?: { cache?: RequestInit['cache']; next?: NextOptions; }; } interface QueuedRequestWithOptions extends RequestWithOptions { /** key of queue, e.g. 'sessionRecording' vs 'event' */ batchKey?: string; } interface RetriableRequestWithOptions extends QueuedRequestWithOptions { retriesPerformedSoFar?: number; } interface RequestQueueConfig { /** * ADVANCED - alters the frequency which PostHog sends events to the server. * generally speaking this is only set when apps have automatic page refreshes, or very short visits. * Defaults to 3 seconds when not set * Allowed values between 250 and 5000 * */ flush_interval_ms?: number; } interface CaptureOptions { /** * Used when `$identify` is called * Will set person properties overriding previous values */ $set?: Properties; /** * Used when `$identify` is called * Will set person properties but only once, it will NOT override previous values */ $set_once?: Properties; /** * Used to override the desired endpoint for the captured event */ _url?: string; /** * key of queue, e.g. 'sessionRecording' vs 'event' */ _batchKey?: string; /** * If set, overrides and disables config.properties_string_max_length */ _noTruncate?: boolean; /** * If set, skips the batched queue */ send_instantly?: boolean; /** * If set, skips the client side rate limiting */ skip_client_rate_limiting?: boolean; /** * If set, overrides the desired transport method */ transport?: RequestWithOptions['transport']; /** * If set, overrides the current timestamp */ timestamp?: Date; } type FlagVariant = { flag: string; variant: string; }; type SessionRecordingCanvasOptions = { /** * If set, records the canvas * * @default false */ recordCanvas?: boolean | null; /** * If set, records the canvas at the given FPS * Can be set in the remote configuration * Limited between 0 and 12 * When canvas recording is enabled, if this is not set locally, then remote config sets this as 4 * * @default null-ish */ canvasFps?: number | null; /** * If set, records the canvas at the given quality * Can be set in the remote configuration * Must be a string that is a valid decimal between 0 and 1 * When canvas recording is enabled, if this is not set locally, then remote config sets this as "0.4" * * @default null-ish */ canvasQuality?: string | null; }; /** * Remote configuration for the PostHog instance * * All of these settings can be configured directly in your PostHog instance * Any configuration set in the client overrides the information from the server */ interface RemoteConfig { /** * Supported compression algorithms */ supportedCompression: Compression[]; /** * If set, disables autocapture */ autocapture_opt_out?: boolean; /** * originally capturePerformance was replay only and so boolean true * is equivalent to { network_timing: true } * now capture performance can be separately enabled within replay * and as a standalone web vitals tracker * people can have them enabled separately * they work standalone but enhance each other * TODO: deprecate this so we make a new config that doesn't need this explanation */ capturePerformance?: boolean | PerformanceCaptureConfig; /** * Whether we should use a custom endpoint for analytics * * @default { endpoint: "/e" } */ analytics?: { endpoint?: string; }; /** * Whether the `$elements_chain` property should be sent as a string or as an array * * @default false */ elementsChainAsString?: boolean; /** * This is currently in development and may have breaking changes without a major version bump */ autocaptureExceptions?: boolean | { endpoint?: string; }; /** * Session recording configuration options */ sessionRecording?: SessionRecordingCanvasOptions & { endpoint?: string; consoleLogRecordingEnabled?: boolean; sampleRate?: string | null; minimumDurationMilliseconds?: number; linkedFlag?: string | FlagVariant | null; networkPayloadCapture?: Pick<NetworkRecordOptions, 'recordBody' | 'recordHeaders'>; masking?: Pick<SessionRecordingOptions, 'maskAllInputs' | 'maskTextSelector'>; urlTriggers?: SessionRecordingUrlTrigger[]; scriptConfig?: { script?: string | undefined; }; urlBlocklist?: SessionRecordingUrlTrigger[]; eventTriggers?: string[]; }; /** * Whether surveys are enabled */ surveys?: boolean; /** * Parameters for the toolbar */ toolbarParams: ToolbarParams; /** * @deprecated renamed to toolbarParams, still present on older API responses */ editorParams?: ToolbarParams; /** * @deprecated, moved to toolbarParams */ toolbarVersion: 'toolbar'; /** * Whether the user is authenticated */ isAuthenticated: boolean; /** * List of site apps with their IDs and URLs */ siteApps: { id: string; url: string; }[]; /** * Whether heatmaps are enabled */ heatmaps?: boolean; /** * Whether to only capture identified users by default */ defaultIdentifiedOnly?: boolean; /** * Whether to capture dead clicks */ captureDeadClicks?: boolean; /** * Indicates if the team has any flags enabled (if not we don't need to load them) */ hasFeatureFlags?: boolean; } /** * Decide returns everything we have on the remote config plus feature flags and their payloads */ interface DecideResponse extends RemoteConfig { featureFlags: Record<string, string | boolean>; featureFlagPayloads: Record<string, JsonType>; errorsWhileComputingFlags: boolean; requestId?: string; flags: Record<string, FeatureFlagDetail>; } type SiteAppGlobals = { event: { uuid: string; event: EventName; properties: Properties; timestamp?: Date; elements_chain?: string; distinct_id?: string; }; person: { properties: Properties; }; groups: Record<string, { id: string; type: string; properties: Properties; }>; }; type SiteAppLoader = { id: string; init: (config: { posthog: PostHog; callback: (success: boolean) => void; }) => { processEvent?: (globals: SiteAppGlobals) => void; }; }; type SiteApp = { id: string; loaded: boolean; errored: boolean; processedBuffer: boolean; processEvent?: (globals: SiteAppGlobals) => void; }; type FeatureFlagsCallback = (flags: string[], variants: Record<string, string | boolean>, context?: { errorsLoading?: boolean; }) => void; type FeatureFlagDetail = { key: string; enabled: boolean; original_enabled?: boolean | undefined; variant: string | undefined; original_variant?: string | undefined; reason: EvaluationReason | undefined; metadata: FeatureFlagMetadata | undefined; }; type FeatureFlagMetadata = { id: number; version: number | undefined; description: string | undefined; payload: JsonType | undefined; original_payload?: JsonType | undefined; }; type EvaluationReason = { code: string; condition_index: number | undefined; description: string | undefined; }; type RemoteConfigFeatureFlagCallback = (payload: JsonType) => void; interface PersistentStore { is_supported: () => boolean; error: (error: any) => void; parse: (name: string) => any; get: (name: string) => any; set: (name: string, value: any, expire_days?: number | null, cross_subdomain?: boolean, secure?: boolean, debug?: boolean) => void; remove: (name: string, cross_subdomain?: boolean) => void; } type Breaker = {}; type EventHandler = (event: Event) => boolean | void; type ToolbarUserIntent = 'add-action' | 'edit-action'; type ToolbarSource = 'url' | 'localstorage'; type ToolbarVersion = 'toolbar'; interface ToolbarParams { token?: string; /** public posthog-js token */ temporaryToken?: string; /** private temporary user token */ actionId?: number; userIntent?: ToolbarUserIntent; source?: ToolbarSource; toolbarVersion?: ToolbarVersion; instrument?: boolean; distinctId?: string; userEmail?: string; dataAttributes?: string[]; featureFlags?: Record<string, string | boolean>; } type SnippetArrayItem = [method: string, ...args: any[]]; type JsonRecord = { [key: string]: JsonType; }; type JsonType = string | number | boolean | null | undefined | JsonRecord | Array<JsonType>; /** A feature that isn't publicly available yet.*/ interface EarlyAccessFeature { name: string; description: string; stage: 'concept' | 'alpha' | 'beta'; documentationUrl: string | null; flagKey: string | null; } type EarlyAccessFeatureStage = 'concept' | 'alpha' | 'beta' | 'general-availability'; type EarlyAccessFeatureCallback = (earlyAccessFeatures: EarlyAccessFeature[]) => void; interface EarlyAccessFeatureResponse { earlyAccessFeatures: EarlyAccessFeature[]; } type Headers = Record<string, string>; type InitiatorType = 'audio' | 'beacon' | 'body' | 'css' | 'early-hint' | 'embed' | 'fetch' | 'frame' | 'iframe' | 'icon' | 'image' | 'img' | 'input' | 'link' | 'navigation' | 'object' | 'ping' | 'script' | 'track' | 'video' | 'xmlhttprequest'; type NetworkRecordOptions = { initiatorTypes?: InitiatorType[]; maskRequestFn?: (data: CapturedNetworkRequest) => CapturedNetworkRequest | undefined; recordHeaders?: boolean | { request: boolean; response: boolean; }; recordBody?: boolean | string[] | { request: boolean | string[]; response: boolean | string[]; }; recordInitialRequests?: boolean; /** * whether to record PerformanceEntry events for network requests */ recordPerformance?: boolean; /** * the PerformanceObserver will only observe these entry types */ performanceEntryTypeToObserve: string[]; /** * the maximum size of the request/response body to record * NB this will be at most 1MB even if set larger */ payloadSizeLimitBytes: number; /** * some domains we should never record the payload * for example other companies session replay ingestion payloads aren't super useful but are gigantic * if this isn't provided we use a default list * if this is provided - we add the provided list to the default list * i.e. we never record the payloads on the default deny list */ payloadHostDenyList?: string[]; }; /** @deprecated - use CapturedNetworkRequest instead */ type NetworkRequest = { url: string; }; type Writable<T> = { -readonly [P in keyof T]: T[P]; }; type CapturedNetworkRequest = Writable<Omit<PerformanceEntry, 'toJSON'>> & { method?: string; initiatorType?: InitiatorType; status?: number; timeOrigin?: number; timestamp?: number; startTime?: number; endTime?: number; requestHeaders?: Headers; requestBody?: string | null; responseHeaders?: Headers; responseBody?: string | null; isInitial?: boolean; }; type ErrorConversionArgs = { event: string | Event; error?: Error; }; type ErrorEventArgs = [ event: string | Event, source?: string | undefined, lineno?: number | undefined, colno?: number | undefined, error?: Error | undefined ]; type ErrorMetadata = { handled?: boolean; synthetic?: boolean; syntheticException?: Error; overrideExceptionType?: string; overrideExceptionMessage?: string; defaultExceptionType?: string; defaultExceptionMessage?: string; }; declare const severityLevels: readonly ["fatal", "error", "warning", "log", "info", "debug"]; declare type SeverityLevel = (typeof severityLevels)[number]; interface ErrorProperties { $exception_type: string; $exception_message: string; $exception_level: SeverityLevel; $exception_source?: string; $exception_lineno?: number; $exception_colno?: number; $exception_DOMException_code?: string; $exception_is_synthetic?: boolean; $exception_stack_trace_raw?: string; $exception_handled?: boolean; $exception_personURL?: string; } interface ErrorConversions { errorToProperties: (args: ErrorEventArgs) => ErrorProperties; unhandledRejectionToProperties: (args: [ev: PromiseRejectionEvent]) => ErrorProperties; } interface SessionRecordingUrlTrigger { url: string; matching: 'regex'; } declare class Autocapture { instance: PostHog; _initialized: boolean; _isDisabledServerSide: boolean | null; _elementSelectors: Set<string> | null; rageclicks: RageClick; _elementsChainAsString: boolean; constructor(instance: PostHog); private get config(); _addDomEventHandlers(): void; startIfEnabled(): void; onRemoteConfig(response: RemoteConfig): void; setElementSelectors(selectors: Set<string>): void; getElementSelectors(element: Element | null): string[] | null; get isEnabled(): boolean; private _captureEvent; isBrowserSupported(): boolean; } declare enum ConsentStatus { PENDING = -1, DENIED = 0, GRANTED = 1 } /** * ConsentManager provides tools for managing user consent as configured by the application. */ declare class ConsentManager { private instance; private _storage?; constructor(instance: PostHog); private get config(); get consent(): ConsentStatus; isOptedOut(): boolean; isOptedIn(): boolean; optInOut(isOptedIn: boolean): void; reset(): void; private get storageKey(); private get storedConsent(); private get storage(); private getDnt; } declare class SessionIdManager { private readonly _sessionIdGenerator; private readonly _windowIdGenerator; private config; private persistence; private _windowId; private _sessionId; private readonly _window_id_storage_key; private readonly _primary_window_exists_storage_key; private _sessionStartTimestamp; private _sessionActivityTimestamp; private _sessionIdChangedHandlers; private readonly _sessionTimeoutMs; private _enforceIdleTimeout; constructor(instance: PostHog, sessionIdGenerator?: () => string, windowIdGenerator?: () => string); get sessionTimeoutMs(): number; onSessionId(callback: SessionIdChangedCallback): () => void; private _canUseSessionStorage; private _setWindowId; private _getWindowId; private _setSessionId; private _getSessionId; resetSessionId(): void; private _listenToReloadWindow; checkAndGetSessionAndWindowId(readOnly?: boolean, _timestamp?: number | null): { sessionId: string; windowId: string; sessionStartTimestamp: number; changeReason: { noSessionId: boolean; activityTimeout: boolean; sessionPastMaximumLength: boolean; } | undefined; lastActivityTimestamp: number; }; private resetIdleTimer; } interface LazyLoadedDeadClicksAutocaptureInterface { start: (observerTarget: Node) => void; stop: () => void; } declare class DeadClicksAutocapture { readonly instance: PostHog; readonly isEnabled: (dca: DeadClicksAutocapture) => boolean; readonly onCapture?: DeadClicksAutoCaptureConfig['__onCapture']; get lazyLoadedDeadClicksAutocapture(): LazyLoadedDeadClicksAutocaptureInterface | undefined; private _lazyLoadedDeadClicksAutocapture; constructor(instance: PostHog, isEnabled: (dca: DeadClicksAutocapture) => boolean, onCapture?: DeadClicksAutoCaptureConfig['__onCapture']); onRemoteConfig(response: RemoteConfig): void; startIfEnabled(): void; private loadScript; private start; stop(): void; } declare class ExceptionObserver { instance: PostHog; remoteEnabled: boolean | undefined; private unwrapOnError; private unwrapUnhandledRejection; constructor(instance: PostHog); get isEnabled(): boolean; get hasHandlers(): boolean; startIfEnabled(): void; private loadScript; private startCapturing; private stopCapturing; onRemoteConfig(response: RemoteConfig): void; captureException(errorProperties: Properties): void; } type SessionStartReason = 'sampling_overridden' | 'recording_initialized' | 'linked_flag_matched' | 'linked_flag_overridden' | 'sampled' | 'session_id_changed' | 'url_trigger_matched' | 'event_trigger_matched'; type TriggerType = 'url' | 'event'; /** * Session recording starts in buffering mode while waiting for decide response * Once the response is received it might be disabled, active or sampled * When sampled that means a sample rate is set and the last time the session id was rotated * the sample rate determined this session should be sent to the server. */ type SessionRecordingStatus = 'disabled' | 'sampled' | 'active' | 'buffering' | 'paused'; declare class SessionRecording { private readonly instance; private _endpoint; private flushBufferTimer?; private buffer; private queuedRRWebEvents; private mutationRateLimiter?; private _captureStarted; private stopRrweb; private receivedDecide; private isIdle; private _linkedFlagSeen; private _lastActivityTimestamp; private windowId; private sessionId; private _linkedFlag; private _fullSnapshotTimer?; private _removePageViewCaptureHook; private _onSessionIdListener; private _persistDecideOnSessionListener; private _samplingSessionListener; private _lastHref?; private _urlTriggers; private _urlBlocklist; private _urlBlocked; private _eventTriggers; private _removeEventTriggerCaptureHook; _forceAllowLocalhostNetworkCapture: boolean; private get sessionIdleThresholdMilliseconds(); get started(): boolean; private get sessionManager(); private get fullSnapshotIntervalMillis(); private get isSampled(); private get sessionDuration(); private get isRecordingEnabled(); private get isConsoleLogCaptureEnabled(); private get canvasRecording(); private get networkPayloadCapture(); private get masking(); private get sampleRate(); private get minimumDuration(); /** * defaults to buffering mode until a decide response is received * once a decide response is received status can be disabled, active or sampled */ get status(): SessionRecordingStatus; private get urlTriggerStatus(); private get eventTriggerStatus(); private get triggerStatus(); constructor(instance: PostHog); private _onBeforeUnload; private _onOffline; private _onOnline; private _onVisibilityChange; startIfEnabledOrStop(startReason?: SessionStartReason): void; stopRecording(): void; private makeSamplingDecision; onRemoteConfig(response: RemoteConfig): void; /** * This might be called more than once so needs to be idempotent */ private _setupSampling; private _persistRemoteConfig; log(message: string, level?: 'log' | 'warn' | 'error'): void; private _startCapture; private get scriptName(); private isInteractiveEvent; private _updateWindowAndSessionIds; private _tryRRWebMethod; private _tryAddCustomEvent; private _tryTakeFullSnapshot; private _onScriptLoaded; private _scheduleFullSnapshot; private _gatherRRWebPlugins; onRRwebEmit(rawEvent: eventWithTime): void; private _pageViewFallBack; private _processQueuedEvents; private _maskUrl; private clearBuffer; private _flushBuffer; private _captureSnapshotBuffered; private _captureSnapshot; private _checkUrlTriggerConditions; private _activateTrigger; private _pauseRecording; private _resumeRecording; private _addEventTriggerListener; /** * this ignores the linked flag config and (if other conditions are met) causes capture to start * * It is not usual to call this directly, * instead call `posthog.startSessionRecording({linked_flag: true})` * */ overrideLinkedFlag(): void; /** * this ignores the sampling config and (if other conditions are met) causes capture to start * * It is not usual to call this directly, * instead call `posthog.startSessionRecording({sampling: true})` * */ overrideSampling(): void; /** * this ignores the URL/Event trigger config and (if other conditions are met) causes capture to start * * It is not usual to call this directly, * instead call `posthog.startSessionRecording({trigger: 'url' | 'event'})` * */ overrideTrigger(triggerType: TriggerType): void; private _reportStarted; } /** * Integrate Sentry with PostHog. This will add a direct link to the person in Sentry, and an $exception event in PostHog * * ### Usage * * Sentry.init({ * dsn: 'https://example', * integrations: [ * new posthog.SentryIntegration(posthog) * ] * }) * * @param {Object} [posthog] The posthog object * @param {string} [organization] Optional: The Sentry organization, used to send a direct link from PostHog to Sentry * @param {Number} [projectId] Optional: The Sentry project id, used to send a direct link from PostHog to Sentry * @param {string} [prefix] Optional: Url of a self-hosted sentry instance (default: https://sentry.io/organizations/) * @param {SeverityLevel[] | '*'} [severityAllowList] Optional: send events matching the provided levels. Use '*' to send all events (default: ['error']) */ type _SentryEvent = any; type _SentryEventProcessor = any; type _SentryHub = any; interface _SentryIntegration { name: string; processEvent(event: _SentryEvent): _SentryEvent; } interface _SentryIntegrationClass { name: string; setupOnce(addGlobalEventProcessor: (callback: _SentryEventProcessor) => void, getCurrentHub: () => _SentryHub): void; } type SentryIntegrationOptions = { organization?: string; projectId?: number; prefix?: string; severityAllowList?: SeverityLevel[] | '*'; }; declare function sentryIntegration(_posthog: PostHog, options?: SentryIntegrationOptions): _SentryIntegration; declare class SentryIntegration implements _SentryIntegrationClass { name: string; setupOnce: (addGlobalEventProcessor: (callback: _SentryEventProcessor) => void, getCurrentHub: () => _SentryHub) => void; constructor(_posthog: PostHog, organization?: string, projectId?: number, prefix?: string, severityAllowList?: SeverityLevel[] | '*'); } declare class Toolbar { instance: PostHog; constructor(instance: PostHog); private setToolbarState; private getToolbarState; /** * To load the toolbar, we need an access token and other state. That state comes from one of three places: * 1. In the URL hash params * 2. From session storage under the key `toolbarParams` if the toolbar was initialized on a previous page */ maybeLoadToolbar(location?: Location | undefined, localStorage?: Storage | undefined, history?: History | undefined): boolean; private _callLoadToolbar; loadToolbar(params?: ToolbarParams): boolean; /** @deprecated Use "loadToolbar" instead. */ _loadEditor(params: ToolbarParams): boolean; /** @deprecated Use "maybeLoadToolbar" instead. */ maybeLoadEditor(location?: Location | undefined, localStorage?: Storage | undefined, history?: History | undefined): boolean; } declare class WebVitalsAutocapture { private readonly instance; private _enabledServerSide; private _initialized; private buffer; private _delayedFlushTimer; constructor(instance: PostHog); get allowedMetrics(): SupportedWebVitalsMetrics[]; get flushToCaptureTimeoutMs(): number; get _maxAllowedValue(): number; get isEnabled(): boolean; startIfEnabled(): void; onRemoteConfig(response: RemoteConfig): void; private loadScript; private _currentURL; private _flushToCapture; private _addToBuffer; private _startCapturing; } type HeatmapEventBuffer = { [key: string]: Properties[]; } | undefined; declare class Heatmaps { instance: PostHog; rageclicks: RageClick; _enabledServerSide: boolean; _initialized: boolean; _mouseMoveTimeout: ReturnType<typeof setTimeout> | undefined; private buffer; private _flushInterval; private deadClicksCapture; constructor(instance: PostHog); get flushIntervalMilliseconds(): number; get isEnabled(): boolean; startIfEnabled(): void; onRemoteConfig(response: RemoteConfig): void; getAndClearBuffer(): HeatmapEventBuffer; private _onDeadClick; private _setupListeners; private _getProperties; private _onClick; private _onMouseMove; private _capture; private flush; } interface PageViewEventProperties { $pageview_id?: string; $prev_pageview_id?: string; $prev_pageview_pathname?: string; $prev_pageview_duration?: number; $prev_pageview_last_scroll?: number; $prev_pageview_last_scroll_percentage?: number; $prev_pageview_max_scroll?: number; $prev_pageview_max_scroll_percentage?: number; $prev_pageview_last_content?: number; $prev_pageview_last_content_percentage?: number; $prev_pageview_max_content?: number; $prev_pageview_max_content_percentage?: number; } declare class PageViewManager { _currentPageview?: { timestamp: Date; pageViewId: string | undefined; pathname: string | undefined; }; _instance: PostHog; constructor(instance: PostHog); doPageView(timestamp: Date, pageViewId?: string): PageViewEventProperties; doPageLeave(timestamp: Date): PageViewEventProperties; doEvent(): PageViewEventProperties; private _previousPageViewProperties; } declare class PostHogExceptions { private readonly instance; constructor(instance: PostHog); /** * :TRICKY: Make sure we batch these requests */ sendExceptionEvent(properties: Properties): void; } /** * PostHog Persistence Object * @constructor */ declare class PostHogPersistence { private config; props: Properties; storage: PersistentStore; campaign_params_saved: boolean; name: string; disabled: boolean | undefined; secure: boolean | undefined; expire_days: number | undefined; default_expiry: number | undefined; cross_subdomain: boolean | undefined; constructor(config: PostHogConfig); private buildStorage; properties(): Properties; load(): void; /** * NOTE: Saving frequently causes issues with Recordings and Consent Management Platform (CMP) tools which * observe cookie changes, and modify their UI, often causing infinite loops. * As such callers of this should ideally check that the data has changed beforehand */ save(): void; remove(): void; clear(): void; /** * @param {Object} props * @param {*=} default_value * @param {number=} days */ register_once(props: Properties, default_value: any, days?: number): boolean; /** * @param {Object} props * @param {number=} days */ register(props: Properties, days?: number): boolean; unregister(prop: string): void; update_campaign_params(): void; update_search_keyword(): void; update_referrer_info(): void; set_initial_person_info(): void; get_referrer_info(): Properties; get_initial_props(): Properties; safe_merge(props: Properties): Properties; update_config(config: PostHogConfig, oldConfig: PostHogConfig): void; set_disabled(disabled: boolean): void; set_cross_subdomain(cross_subdomain: boolean): void; get_cross_subdomain(): boolean; set_secure(secure: boolean): void; set_event_timer(event_name: string, timestamp: number): void; remove_event_timer(event_name: string): number; get_property(prop: string): any; set_property(prop: string, to: any): void; } type FeatureFlagOverrides = { [flagName: string]: string | boolean; }; type FeatureFlagPayloadOverrides = { [flagName: string]: JsonType; }; type FeatureFlagOverrideOptions = { flags?: boolean | string[] | FeatureFlagOverrides; payloads?: FeatureFlagPayloadOverrides; suppressWarning?: boolean; }; type OverrideFeatureFlagsOptions = boolean | string[] | FeatureFlagOverrides | FeatureFlagOverrideOptions; declare class PostHogFeatureFlags { private instance; _override_warning: boolean; featureFlagEventHandlers: FeatureFlagsCallback[]; $anon_distinct_id: string | undefined; private _hasLoadedFlags; private _requestInFlight; private _reloadingDisabled; private _additionalReloadRequested; private _reloadDebouncer?; private _decideCalled; private _flagsLoadedFromRemote; constructor(instance: PostHog); decide(): void; get hasLoadedFlags(): boolean; getFlags(): string[]; getFlagsWithDetails(): Record<string, FeatureFlagDetail>; getFlagVariants(): Record<string, string | boolean>; getFlagPayloads(): Record<string, JsonType>; /** * Reloads feature flags asynchronously. * * Constraints: * * 1. Avoid parallel requests * 2. Delay a few milliseconds after each reloadFeatureFlags call to batch subsequent changes together */ reloadFeatureFlags(): void; private clearDebouncer; ensureFlagsLoaded(): void; setAnonymousDistinctId(anon_distinct_id: string): void; setReloadingPaused(isPaused: boolean): void; /** * NOTE: This is used both for flags and remote config. Once the RemoteConfig is fully released this will essentially only * be for flags and can eventually be replaced with the new flags endpoint */ _callDecideEndpoint(options?: { disableFlags?: boolean; }): void; getFeatureFlag(key: string, options?: { send_event?: boolean; }): boolean | string | undefined; getFeatureFlagDetails(key: string): FeatureFlagDetail | undefined; getFeatureFlagPayload(key: string): JsonType; getRemoteConfigPayload(key: string, callback: RemoteConfigFeatureFlagCallback): void; isFeatureEnabled(key: string, options?: { send_event?: boolean; }): boolean | undefined; addFeatureFlagsHandler(handler: FeatureFlagsCallback): void; removeFeatureFlagsHandler(handler: FeatureFlagsCallback): void; receivedFeatureFlags(response: Partial<DecideResponse>, errorsLoading?: boolean): void; /** * @deprecated Use overrideFeatureFlags instead. This will be removed in a future version. */ override(flags: boolean | string[] | Record<string, string | boolean>, suppressWarning?: boolean): void; /** * Override feature flags on the client-side. Useful for setting non-persistent feature flags, * or for testing/debugging feature flags in the PostHog app. * * ### Usage: * * - posthog.featureFlags.overrideFeatureFlags(false) // clear all overrides * - posthog.featureFlags.overrideFeatureFlags(['beta-feature']) // enable flags * - posthog.featureFlags.overrideFeatureFlags({'beta-feature': 'variant'}) // set variants * - posthog.featureFlags.overrideFeatureFlags({ // set both flags and payloads * flags: {'beta-feature': 'variant'}, * payloads: { 'beta-feature': { someData: true } } * }) * - posthog.featureFlags.overrideFeatureFlags({ // only override payloads * payloads: { 'beta-feature': { someData: true } } * }) */ overrideFeatureFlags(overrideOptions: OverrideFeatureFlagsOptions): void; onFeatureFlags(callback: FeatureFlagsCallback): () => void; updateEarlyAccessFeatureEnrollment(key: string, isEnrolled: boolean): void; getEarlyAccessFeatures(callback: EarlyAccessFeatureCallback, force_reload?: boolean, stages?: EarlyAccessFeatureStage[]): void; _prepareFeatureFlagsForCallbacks(): { flags: string[]; flagVariants: Record<string, string | boolean>; }; _fireFeatureFlagsCallbacks(errorsLoading?: boolean): void; /** * Set override person properties for feature flags. * This is used when dealing with new persons / where you don't want to wait for ingestion * to update user properties. */ setPersonPropertiesForFlags(properties: Properties, reloadFeatureFlags?: boolean): void; resetPersonPropertiesForFlags(): void; /** * Set override group properties for feature flags. * This is used when dealing with new groups / where you don't want to wait for ingestion * to update properties. * Takes in an object, the key of which is the group type. * For example: * setGroupPropertiesForFlags({'organization': { name: 'CYZ', employees: '11' } }) */ setGroupPropertiesForFlags(properties: { [type: string]: Properties; }, reloadFeatureFlags?: boolean): void; resetGroupPropertiesForFlags(group_type?: string): void; } /** * Having Survey types in types.ts was confusing tsc * and generating an invalid module.d.ts * See https://github.com/PostHog/posthog-js/issues/698 */ interface SurveyAppearance { backgroundColor?: string; submitButtonColor?: string; textColor?: string; submitButtonText?: string; submitButtonTextColor?: string; descriptionTextColor?: string; ratingButtonColor?: string; ratingButtonActiveColor?: string; ratingButtonHoverColor?: string; whiteLabel?: boolean; autoDisappear?: boolean; displayThankYouMessage?: boolean; thankYouMessageHeader?: string; thankYouMessageDescription?: string; thankYouMessageDescriptionContentType?: SurveyQuestionDescriptionContentType; thankYouMessageCloseButtonText?: string; borderColor?: string; position?: 'left' | 'right' | 'center'; placeholder?: string; shuffleQuestions?: boolean; surveyPopupDelaySeconds?: number; widgetType?: 'button' | 'tab' | 'selector'; widgetSelector?: string; widgetLabel?: string; widgetColor?: string; fontFamily?: string; maxWidth?: string; zIndex?: string; disabledButtonOpacity?: string; } declare enum SurveyType { Popover = "popover", API = "api", Widget = "widget" } type SurveyQuestion = BasicSurveyQuestion | LinkSurveyQuestion | RatingSurveyQuestion | MultipleSurveyQuestion; type SurveyQuestionDescriptionContentType = 'html' | 'text'; interface SurveyQuestionBase { question: string; id?: string; description?: string | null; descriptionContentType?: SurveyQuestionDescriptionContentType; optional?: boolean; buttonText?: string; branching?: NextQuestionBranching | EndBranching | ResponseBasedBranching | SpecificQuestionBranching; } interface BasicSurveyQuestion extends SurveyQuestionBase { type: SurveyQuestionType.Open; } interface LinkSurveyQuestion extends SurveyQuestionBase { type: SurveyQuestionType.Link; link?: string | null; } interface RatingSurveyQuestion extends SurveyQuestionBase { type: SurveyQuestionType.Rating; display: 'number' | 'emoji'; scale: 3 | 5 | 7 | 10; lowerBoundLabel: string; upperBoundLabel: string; } interface MultipleSurveyQuestion extends SurveyQuestionBase { type: SurveyQuestionType.SingleChoice | SurveyQuestionType.MultipleChoice; choices: string[]; hasOpenChoice?: boolean; shuffleOptions?: boolean; } declare enum SurveyQuestionType { Open = "open", MultipleChoice = "multiple_choice", SingleChoice = "single_choice", Rating = "rating", Link = "link" } declare enum SurveyQuestionBranchingType { NextQuestion = "next_question", End = "end", ResponseBased = "response_based", SpecificQuestion = "specific_question" } interface NextQuestionBranching { type: SurveyQuestionBranchingType.NextQuestion; } interface EndBranching { type: SurveyQuestionBranchingType.End; } interface ResponseBasedBranching { type: SurveyQuestionBranchingType.ResponseBased; responseValues: Record<string, any>; } interface SpecificQuestionBranching { type: SurveyQuestionBranchingType.SpecificQuestion; index: number; } interface SurveyResponse { surveys: Survey[]; } type SurveyCallback = (surveys: Survey[]) => void; type SurveyMatchType = 'regex' | 'not_regex' | 'exact' | 'is_not' | 'icontains' | 'not_icontains'; interface SurveyElement { text?: string; $el_text?: string; tag_name?: string; href?: string; attr_id?: string; attr_class?: string[]; nth_child?: number; nth_of_type?: number; attributes?: Record<string, any>; event_id?: number; order?: number; group_id?: number; } interface SurveyRenderReason { visible: boolean; disabledReason?: string; } declare enum SurveySchedule { Once = "once", Recurring = "recurring", Always = "always" } interface Survey { id: string; name: string; description: string; type: SurveyType; feature_flag_keys: { key: string; value?: string; }[] | null; linked_flag_key: string | null; targeting_flag_key: string | null; internal_targeting_flag_key: string | null; questions: SurveyQuestion[]; appearance: SurveyAppearance | null; conditions: { url?: string; selector?: string; seenSurveyWaitPeriodInDays?: number; urlMatchType?: SurveyMatchType; events: { repeatedActivation?: boolean; values: { name: string; }[]; } | null; actions: { values: SurveyActionType[]; } | null; deviceTypes?: string[]; deviceTypesMatchType?: SurveyMatchType; } | null; start_date: string | null; end_date: string | null; current_iteration: number | null; current_iteration_start_date: string | null; schedule?: SurveySchedule | null; } interface SurveyActionType { id: number; name: string | null; steps?: ActionStepType[]; } /** Sync with plugin-server/src/types.ts */ type ActionStepStringMatching = 'contains' | 'exact' | 'regex'; interface ActionStepType { event?: string | null; selector?: string | null; /** @deprecated Only `selector` should be used now. */ tag_name?: string; text?: string | null; /** @default StringMatching.Exact */ text_matching?: ActionStepStringMatching | null; href?: string | null; /** @default ActionStepStringMatching.Exact */ href_matching?: ActionStepStringMatching | null; url?: string | null; /** @default StringMatching.Contains */ url_matching?: ActionStepStringMatching | null; } declare class ActionMatcher { private readonly actionRegistry?; private readonly instance?; private readonly actionEvents; private _debugEventEmitter; constructor(instance?: PostHog); init(): void; register(actions: SurveyActionType[]): void; on(eventName: string, eventPayload?: CaptureResult): void; _addActionHook(callback: (actionName: string, eventPayload?: any) => void): void; private checkAction; onAction(event: 'actionCaptured', cb: (...args: any[]) => void): () => void; private checkStep; private checkStepEvent; private checkStepUrl; private static matchString; private static escapeStringRegexp; private checkStepElement; private getElementsList; } declare class SurveyEventReceiver { private readonly eventToSurveys; private readonly actionToSurveys; private actionMatcher?; private readonly instance?; private static SURVEY_SHOWN_EVENT_NAME; constructor(instance: PostHog); register(surveys: Survey[]): void; private setupActionBasedSurveys; private setupEventBasedSurveys; onEvent(event: string, eventPayload?: CaptureResult): void; onAction(actionName: string): void; private _updateActivatedSurveys; getSurveys(): string[]; getEventToSurveys(): Map<string, string[]>; _getActionMatcher(): ActionMatcher | null | undefined; } declare class PostHogSurveys { private readonly instance; private _decideServerResponse?; _surveyEventReceiver: SurveyEventReceiver | null; private _surveyManager; private _isFetchingSurveys; private _isInitializingSurveys; constructor(instance: PostHog); onRemoteConfig(response: RemoteConfig): void; reset(): void; loadIfEnabled(): void; getSurveys(callback: SurveyCallback, forceReload?: boolean): void; private isSurveyFeatureFlagEnabled; getActiveMatchingSurveys(callback: SurveyCallback, forceReload?: boolean): void; checkFlags(survey: Survey): boolean; private _canActivateRepeatedly; canRenderSurvey(surveyId: string): void; renderSurvey(surveyId: string, selector: string): void; } declare class RateLimiter { instance: PostHog; serverLimits: Record<string, number>; captureEventsPerSecond: number; captureEventsBurstLimit: number; lastEventRateLimited: boolean; constructor(instance: PostHog); clientRateLimitContext(checkOnly?: boolean): { isRateLimited: boolean; remainingTokens: number; }; isServerRateLimited(batchKey: string | undefined): boolean; checkForLimiting: (httpResponse: RequestResponse) => void; } declare class RequestQueue { private isPaused; private queue; private flushTimeout?; private flushTimeoutMs; private sendRequest; constructor(sendRequest: (req: QueuedRequestWithOptions) => void, config?: RequestQueueConfig); enqueue(req: QueuedRequestWithOptions): void; unload(): void; enable(): void; private setFlushTimeout; private clearFlushTimeout; private formatQueue; } declare class RetryQueue { private instance; private isPolling; private poller; private pollIntervalMs; private queue; private areWeOnline; constructor(instance: PostHog); retriableRequest({ retriesPerformedSoFar, ...options }: RetriableRequestWithOptions): void; private enqueue; private poll; private flush; unload(): void; } interface ScrollContext { maxScrollHeight?: number; maxScrollY?: number; lastScrollY?: number; maxContentHeight?: number; maxContentY?: number; lastContentY?: number; } declare class ScrollManager { private instance; private context; constructor(instance: PostHog); getContext(): ScrollContext | undefined; resetContext(): ScrollContext | undefined; private _updateScrollData; startMeasuringScrollPosition(): void; scrollElement(): Element | undefined; scrollY(): number; scrollX(): number; } interface LegacySessionSourceProps { initialPathName: string; referringDomain: string; utm_medium?: string; utm_source?: string; utm_campaign?: string; utm_content?: string; utm_term?: string; } interface CurrentSessionSourceProps { r: string; u: string | undefined; } interface StoredSessionSourceProps { sessionId: string; props: LegacySessionSourceProps | CurrentSessionSourceProps; } declare class SessionPropsManager { private readonly instance; private readonly _sessionIdManager; private readonly _persistence; private readonly _sessionSourceParamGenerator; constructor(instance: PostHog, sessionIdManager: SessionIdManager, persistence: PostHogPersistence, sessionSourceParamGenerator?: (instance?: PostHog) => LegacySessionSourceProps | CurrentSessionSourceProps); _getStored(): StoredSessionSourceProps | undefined; _onSessionIdCallback: (sessionId: string) => void; getSetOnceProps(): Record<string, any>; getSessionProps(): Record<string, any>; } declare class SiteApps { private instance; apps: Record<string, SiteApp>; private stopBuffering?; private bufferedInvocations; constructor(instance: PostHog); get isEnabled(): boolean; private eventCollector; get siteAppLoaders(): SiteAppLoader[] | undefined; init(): void; globalsForEvent(event: CaptureResult): SiteAppGlobals; setupSiteApp(loader: SiteAppLoader): void; private setupSiteApps; private onCapturedEvent; onRemoteConfig(response: RemoteConfig): void; } /** * The request router helps simplify the logic to determine which endpoints should be called for which things * The basic idea is that for a given region (US or EU), we have a set of endpoints that we should call depending * on the type of request (events, replays, decide, etc.) and handle overrides that may come from configs or the decide endpoint */ declare enum RequestRouterRegion { US = "us", EU = "eu", CUSTOM = "custom" } type RequestRouterTarget = 'api' | 'ui' | 'assets'; declare class RequestRouter { instance: PostHog; private _regionCache; constructor(instance: PostHog); get apiHost(): string; get uiHost(): string | undefined; get region(): RequestRouterRegion; endpointFor(target: RequestRouterTarget, path?: string): string; } interface WebExperimentTransform { attributes?: { name: string; value: string; }[]; selector?: string; text?: string; html?: string; imgUrl?: string; css?: string; } type WebExperimentUrlMatchType = 'regex' | 'not_regex' | 'exact' | 'is_not' | 'icontains' | 'not_icontains'; interface WebExperimentVariant { conditions?: { url?: string; urlMatchType?: WebExperimentUrlMatchType; utm?: { utm_source?: string; utm_medium?: string; utm_campaign?: string; utm_term?: string; }; }; variant_name: string; transforms: WebExperimentTransform[]; } interface WebExperiment { id: number; name: string; feature_flag_key?: string; variants: Record<string, WebExperimentVariant>; } type WebExperimentsCallback = (webExperiments: WebExperiment[]) => void; declare class WebExperiments { private instance; private _flagToExperiments?; constructor(instance: PostHog); onFeatureFlags(flags: string[]): void; previewWebExperiment(): void; loadIfEnabled(): void; getWebExperimentsAndEvaluateDisplayLogic: (forceReload?: boolean) => void; getWebExperiments(callback: WebExperimentsCallback, forceReload: boolean, previewing?: boolean): void; private showPreviewWebExperiment; private static matchesTestVariant; private static matchUrlConditions; static getWindowLocation(): Location | undefined; private static matchUTMConditions; private static logInfo; private applyTransforms; _is_bot(): boolean | undefined; } type OnlyValidKeys<T, Shape> = T extends Shape ? (Exclude<keyof T, keyof Shape> extends never ? T : never) : never; declare class DeprecatedWebPerformanceObserver { get _forceAllowLocalhost(): boolean; set _forceAllowLocalhost(value: boolean); private __forceAllowLocalhost; } /** * PostHog Library Object * @constructor */ declare class PostHog { __loaded: boolean; config: PostHogConfig; rateLimiter: RateLimiter; scrollManager: ScrollManager; pageViewManager: PageViewManager; featureFlags: PostHogFeatureFlags; surveys: PostHogSurveys; experiments: WebExperiments; toolbar: Toolbar; exceptions: PostHogExceptions; consent: ConsentManager; persistence?: PostHogPersistence; sessionPersistence?: PostHogPersistence; sessionManager?: SessionIdManager; sessionPropsManager?: SessionPropsManager; requestRouter: RequestRouter; siteApps?: SiteApps; autocapture?: Autocapture; heatmaps?: Heatmaps; webVitalsAutocapture?: WebVitalsAutocapture; exceptionObserver?: ExceptionObserver; deadClicksAutocapture?: DeadClicksAutocapture; _requestQueue?: RequestQueue; _retryQueue?: RetryQueue; sessionRecording?: SessionRecording; webPerformance: DeprecatedWebPerformanceObserver; _initialPageviewCaptured: boolean; _personProcessingSetOncePropertiesSent: boolean; _triggered_notifs: any; compression?: Compression; __request_queue: QueuedRequestWithOptions[]; analyticsDefaultEndpoint: string; version: string; _initialPersonProfilesConfig: 'always' | 'never' | 'identified_only' | null; _cachedIdentify: string | null; SentryIntegration: typeof SentryIntegration; sentryIntegration: (options?: SentryIntegrationOptions) => ReturnType<typeof sentryIntegration>; private _internalEventEmitter; get decideEndpointWasHit(): boolean; /** DEPRECATED: We keep this to support existing usage but now one should just call .setPersonProperties */ people: { set: (prop: string | Properties, to?: string, callback?: RequestCallback) => void; set_once: (prop: string | Properties, to?: string, callback?: RequestCallback) => void; }; constructor(); /** * This function initializes a new instance of the PostHog capturing object. * All new instances are added to the main posthog object as sub properties (such as * posthog.library_name) and also returned by this function. To define a * second instance on the page, you would call: * * posthog.init('new token', { your: 'config' }, 'library_name'); * * and use it like so: * * posthog.library_name.capture(...); * * @param {String} token Your PostHog API token * @param {Object} [config] A dictionary of config options to override. <a href="https://github.com/posthog/posthog-js/blob/6e0e873/src/posthog-core.js#L57-L91">See a list of default config options</a>. * @param {String} [name] The name for the new posthog instance that you want created */ init(token: string, config?: OnlyValidKeys<Partial<PostHogConfig>, Partial<PostHogConfig>>, name?: string): PostHog; _init(token: string, config?: Partial<PostHogConfig>, name?: string): PostHog; _onRemoteConfig(config: RemoteConfig): void; _loaded(): void; _start_queue_if_opted_in(): void; _dom_loaded(): void; _handle_unload(): void; _send_request(options: QueuedRequestWithOptions): void; _send_retriable_request(options: QueuedRequestWithOptions): void; /** * _execute_array() deals with processing any posthog function * calls that were called before the PostHog library were loaded * (and are thus stored in an array so they can be called later) * * Note: we fire off all the posthog function calls && user defined * functions BEFORE we fire off posthog capturing calls. This is so * identify/register/set_config calls can properly modify early * capturing calls. * * @param {Array} array */ _execute_array(array: SnippetArrayItem[]): void; _hasBootstrappedFeatureFlags(): boolean; /** * push() keeps the standard async-array-push * behavior around after the lib is loaded. * This is only useful for external integrations that * do not wish to rely on our convenience methods * (created in the snippet). * * ### Usage: * posthog.push(['register', { a: 'b' }]); * * @param {Array} item A [function_name, args...] array to be executed */ push(item: SnippetArrayItem): void; /** * Capture an event. This is the most important and * frequently used PostHog function. * * ### Usage: * * // capture an event named 'Registered' * posthog.capture('Registered', {'Gender': 'Male', 'Age': 21}); * * // capture an event using navigator.sendBeacon * posthog.capture('Left page', {'duration_seconds': 35}, {transport: 'sendBeacon'}); * * @param {String} event_name The name of the event. This can be anything the user does - 'Button Click', 'Sign Up', 'Item Purchased', etc. * @param {Object} [properties] A set of properties to include with the event you're sending. These describe the user who did the event or details about the event itself. * @param {Object} [config] Optional configuration for this capture request. * @param {String} [config.transport] Transport method for network request ('XHR' or 'sendBeacon'). * @param {Date} [config.timestamp] Timestamp is a Date object. If not set, it'll automatically be set to the current time. */ capture(event_name: EventName, properties?: Properties | null, options?: CaptureOptions): CaptureResult | undefined; _addCaptureHook(callback: (eventName: string, eventPayload?: CaptureResult) => void): () => void; _calculate_event_properties(event_name: string, event_properties: Properties, timestamp?: Date, uuid?: string): Properties; /** * Add additional set_once properties to the event when creating a person profile. This allows us to create the * profile with mostly-accurate properties, despite earlier events not setting them. We do this by storing them in * persistence. * @param dataSetOnce */ _calculate_set_once_properties(dataSetOnce?: Properties): Properties | undefined; /** * Register a set of super properties, which are included with all * events. This will overwrite previous super property values, except * for session properties (see `register_for_session(properties)`). * * ### Usage: * * // register 'Gender' as a super property * posthog.register({'Gender': 'Female'}); * * // register several super properties when a user signs up * posthog.register({ * 'Email': 'jdoe@example.com', * 'Account Type': 'Free' * }); * * // Display the properties * console.log(posthog.persistence.properties()) * * @param {Object} properties properties to store about the user * @param {Number} [days] How many days since the user's last visit to store the super properties */ register(properties: Properties, days?: number): void; /** * Register a set of super properties only once. These will not * overwrite previous super property values, unlike register(). * * ### Usage: * * // register a super property for the first time only * posthog.register_once({ * 'First Login Date': new Date().toISOString() * }); * * // Display the properties * console.log(posthog.persistence.properties()) * * ### Notes: * * If default_value is specified, current super properties * with that value will be overwritten. * * @param {Object} properties An associative array of properties to store about the user * @param {*} [default_value] Value to override if already set in super properties (ex: 'False') Default: 'None' * @param {Number} [days] How many days since the users last visit to store the super properties */ register_once(properties: Properties, default_value?: Property, days?: number): void; /** * Register a set of super properties, which are included with all events, but only * for THIS SESSION. These will overwrite all other super property values. * * Unlike regular super properties, which last in LocalStorage for a long time, * session super properties get cleared after a session ends. * * ### Usage: * * // register on all events this session * posthog.register_for_session({'referer': customGetReferer()}); * * // register several session super properties when a user signs up * posthog.register_for_session({ * 'selectedPlan': 'pro', * 'completedSteps': 4, * }); * * // Display the properties * console.log(posthog.sessionPersistence.properties()) * * @param {Object} properties An associative array of properties to store about the user */ register_for_session(properties: Properties): void; /** * Delete a super property stored with the current user. * * @param {String} property The name of the super property to remove */ unregister(property: string): void; /** * Delete a session super property stored with the current user. * * @param {String} property The name of the session super property to remove */ unregister_for_session(property: string): void; _register_single(prop: string, value: Property): void; getFeatureFlag(key: string, options?: { send_event?: boolean; }): boolean | string | undefined; getFeatureFlagPayload(key: string): JsonType; isFeatureEnabled(key: string, options?: { send_event: boolean; }): boolean | undefined; reloadFeatureFlags(): void; /** Opt the user in or out of an early access feature. */ updateEarlyAccessFeatureEnrollment(key: string, isEnrolled: boolean): void; /** Get the list of early access features. To check enrollment status, use `isFeatureEnabled`. */ getEarlyAccessFeatures(callback: EarlyAccessFeatureCallback, force_reload?: boolean, stages?: EarlyAccessFeatureStage[]): void; /** * Exposes a set of events that PostHog will emit. * e.g. `eventCaptured` is emitted immediately before trying to send an event * * Unlike `onFeatureFlags` and `onSessionId` these are not called when the * listener is registered, the first callback will be the next event * _after_ registering a listener */ on(event: 'eventCaptured', cb: (...args: any[]) => void): () => void; onFeatureFlags(callback: FeatureFlagsCallback): () => void; onSessionId(callback: SessionIdChangedCallback): () => void; /** Get list of all surveys. */ getSurveys(callback: SurveyCallback, forceReload?: boolean): void; /** Get surveys that should be enabled for the current user. */ getActiveMatchingSurveys(callback: SurveyCallback, forceReload?: boolean): void; /** Render a survey on a specific element. */ renderSurvey(surveyId: string, selector: string): void; /** Checks the feature flags associated with this Survey to see if the survey can be rendered. */ canRenderSurvey(surveyId: string): void; /** * Identify a user with a unique ID instead of a PostHog * randomly generated distinct_id. If the method is never called, * then unique visitors will be identified by a UUID that is generated * the first time they visit the site. * * If user properties are passed, they are also sent to posthog. * * ### Usage: * * posthog.identify('[user unique id]') * posthog.identify('[user unique id]', { email: 'john@example.com' }) * posthog.identify('[user unique id]', {}, { referral_code: '12345' }) * * ### Notes: * * You can call this function to overwrite a previously set * unique ID for the current user. * * If the user has been identified ($user_state in persistence is set to 'identified'), * then capture of $identify is skipped to avoid merging users. For example, * if your system allows an admin user to impersonate another user. * * Then a single browser instance can have: * * `identify('a') -> capture(1) -> identify('b') -> capture(2)` * * and capture 1 and capture 2 will have the correct distinct_id. * but users a and b will NOT be merged in posthog. * * However, if reset is called then: * * `identify('a') -> capture(1) -> reset() -> capture(2) -> identify('b') -> capture(3)` * * users a and b are not merged. * Capture 1 is associated with user a. * A new distinct id is generated for capture 2. * which is merged with user b. * So, capture 2 and 3 are associated with user b. * * If you want to merge two identified users, you can call posthog.alias * * @param {String} [new_distinct_id] A string that uniquely identifies a user. If not provided, the distinct_id currently in the persistent store (cookie or localStorage) will be used. * @param {Object} [userPropertiesToSet] Optional: An associative array of properties to store about the user. Note: For feature flag evaluations, if the same key is present in the userPropertiesToSetOnce, * it will be overwritten by the value in userPropertiesToSet. * @param {Object} [userPropertiesToSetOnce] Optional: An associative array of properties to store about the user. If property is previously set, this does not override that value. */ identify(new_distinct_id?: string, userPropertiesToSet?: Properties, userPropertiesToSetOnce?: Properties): void; /** * Sets properties for the Person associated with the current distinct_id. If config.person_profiles is set to * identified_only, and a Person profile has not been created yet, this will create one. * * * @param {Object} [userPropertiesToSet] Optional: An associative array of properties to store about the user. Note: For feature flag evaluations, if the same key is present in the userPropertiesToSetOnce, * it will be overwritten by the value in userPropertiesToSet. * @param {Object} [userPropertiesToSetOnce] Optional: An associative array of properties to store about the user. If property is previously set, this does not override that value. */ setPersonProperties(userPropertiesToSet?: Properties, userPropertiesToSetOnce?: Properties): void; /** * Sets group analytics information for subsequent events and reloads feature flags. * * @param {String} groupType Group type (example: 'organization') * @param {String} groupKey Group key (example: 'org::5') * @param {Object} groupPropertiesToSet Optional properties to set for group */ group(groupType: string, groupKey: string, groupPropertiesToSet?: Properties): void; /** * Resets only the group properties of the user currently logged in. */ resetGroups(): void; /** * Set override person properties for feature flags. * This is used when dealing with new persons / where you don't want to wait for ingestion * to update user properties. */ setPersonPropertiesForFlags(properties: Properties, reloadFeatureFlags?: boolean): void; resetPersonPropertiesForFlags(): void; /** * Set override group properties for feature flags. * This is used when dealing with new groups / where you don't want to wait for ingestion * to update properties. * Takes in an object, the key of which is the group type. * For example: * setGroupPropertiesForFlags({'organization': { name: 'CYZ', employees: '11' } }) */ setGroupPropertiesForFlags(properties: { [type: string]: Properties; }, reloadFeatureFlags?: boolean): void; resetGroupPropertiesForFlags(group_type?: string): void; /** * NB reset is normally only called when a user logs out * calling reset at the wrong time can lead to unexpected results * like split sessions * * Resets all info. * For example: session id, super properties, sets a random distinct_id and more. */ reset(reset_device_id?: boolean): void; /** * Returns the current distinct id of the user. This is either the id automatically * generated by the library or the id that has been passed by a call to identify(). * * ### Notes: * * get_distinct_id() can only be called after the PostHog library has finished loading. * init() has a loaded function available to handle this automatically. For example: * * // set distinct_id after the posthog library has loaded * posthog.init('YOUR PROJECT TOKEN', { * loaded: function(posthog) { * distinct_id = posthog.get_distinct_id(); * } * }); */ get_distinct_id(): string; getGroups(): Record<string, any>; /** * Returns the current session_id. * * NOTE: This should only be used for informative purposes. * Any actual internal use case for the session_id should be handled by the sessionManager. */ get_session_id(): string; /** * Returns the Replay url for the current session. * * @param options Options for the url * @param options.withTimestamp Whether to include the timestamp in the url (defaults to false) * @param options.timestampLookBack How many seconds to look back for the timestamp (defaults to 10) */ get_session_replay_url(options?: { withTimestamp?: boolean; timestampLookBack?: number; }): string; /** * Create an alias, which PostHog will use to link two distinct_ids going forward (not retroactively). * Multiple aliases can map to the same original ID, but not vice-versa. Aliases can also be chained - the * following is a valid scenario: * * posthog.alias('new_id', 'existing_id'); * ... * posthog.alias('newer_id', 'new_id'); * * If the original ID is not passed in, we will use the current distinct_id - probably the auto-generated GUID. * * ### Notes: * * The best practice is to call alias() when a unique ID is first created for a user * (e.g., when a user first registers for an account and provides an email address). * alias() should never be called more than once for a given user, except to * chain a newer ID to a previously new ID, as described above. * * @param {String} alias A unique identifier that you want to use for this user in the future. * @param {String} [original] The current identifier being used for this user. */ alias(alias: string, original?: string): CaptureResult | void | number; /** * Update the configuration of a posthog library instance. * * @param {Partial<PostHogConfig>} config A dictionary of new configuration values to update */ set_config(config: Partial<PostHogConfig>): void; /** * turns session recording on, and updates the config option `disable_session_recording` to false * @param override.sampling - optional boolean to override the default sampling behavior - ensures the next session recording to start will not be skipped by sampling config. * @param override.linked_flag - optional boolean to override the default linked_flag behavior - ensures the next session recording to start will not be skipped by linked_flag config. * @param override.url_trigger - optional boolean to override the default url_trigger behavior - ensures the next session recording to start will not be skipped by url_trigger config. * @param override.event_trigger - optional boolean to override the default event_trigger behavior - ensures the next session recording to start will not be skipped by event_trigger config. * @param override - optional boolean to override the default sampling behavior - ensures the next session recording to start will not be skipped by sampling or linked_flag config. `true` is shorthand for { sampling: true, linked_flag: true } */ startSessionRecording(override?: { sampling?: boolean; linked_flag?: boolean; url_trigger?: true; event_trigger?: true; } | true): void; /** * turns session recording off, and updates the config option * disable_session_recording to true */ stopSessionRecording(): void; /** * returns a boolean indicating whether session recording * is currently running */ sessionRecordingStarted(): boolean; /** Capture a caught exception manually */ captureException(error: unknown, additionalProperties?: Properties): void; /** * returns a boolean indicating whether the toolbar loaded * @param toolbarParams */ loadToolbar(params: ToolbarParams): boolean; /** * Returns the value of the super property named property_name. If no such * property is set, get_property() will return the undefined value. * * ### Notes: * * get_property() can only be called after the PostHog library has finished loading. * init() has a loaded function available to handle this automatically. For example: * * // grab value for '$user_id' after the posthog library has loaded * posthog.init('YOUR PROJECT TOKEN', { * loaded: function(posthog) { * user_id = posthog.get_property('$user_id'); * } * }); * * @param {String} property_name The name of the super property you want to retrieve */ get_property(property_name: string): Property | undefined; /** * Returns the value of the session super property named property_name. If no such * property is set, getSessionProperty() will return the undefined value. * * ### Notes: * * This is based on browser-level `sessionStorage`, NOT the PostHog session. * getSessionProperty() can only be called after the PostHog library has finished loading. * init() has a loaded function available to handle this automatically. For example: * * // grab value for 'user_id' after the posthog library has loaded * posthog.init('YOUR PROJECT TOKEN', { * loaded: function(posthog) { * user_id = posthog.getSessionProperty('user_id'); * } * }); * * @param {String} property_name The name of the session super property you want to retrieve */ getSessionProperty(property_name: string): Property | undefined; toString(): string; _isIdentified(): boolean; _hasPersonProcessing(): boolean; _shouldCapturePageleave(): boolean; /** * Creates a person profile for the current user, if they don't already have one and config.person_profiles is set * to 'identified_only'. Produces a warning and does not create a profile if config.person_profiles is set to * 'never'. */ createPersonProfile(): void; /** * Enables person processing if possible, returns true if it does so or already enabled, false otherwise * * @param function_name */ _requirePersonProcessing(function_name: string): boolean; private _sync_opt_out_with_persistence; /** * Opt the user in to data capturing and cookies/localstorage for this PostHog instance * If the config.opt_out_persistence_by_default is set to false, the SDK persistence will be enabled. * * ### Usage * * // opt user in * posthog.opt_in_capturing(); * * // opt user in with specific event name, properties, cookie configuration * posthog.opt_in_capturing({ * capture_event_name: 'User opted in', * capture_event_properties: { * 'email': 'jdoe@example.com' * } * }); * * @param {Object} [config] A dictionary of config options to override * @param {string} [config.capture_event_name=$opt_in] Event name to be used for capturing the opt-in action. Set to `null` or `false` to skip capturing the optin event * @param {Object} [config.capture_properties] Set of properties to be captured along with the opt-in action */ opt_in_capturing(options?: { captureEventName?: EventName | null | false; /** event name to be used for capturing the opt-in action */ captureProperties?: Properties; /** set of properties to be captured along with the opt-in action */ }): void; /** * Opt the user out of data capturing and cookies/localstorage for this PostHog instance. * If the config.opt_out_persistence_by_default is set to true, the SDK persistence will be disabled. * */ opt_out_capturing(): void; /** * Check whether the user has opted in to data capturing and cookies/localstorage for this PostHog instance * * @returns {boolean} current opt-in status */ has_opted_in_capturing(): boolean; /** * Check whether the user has opted out of data capturing and cookies/localstorage for this PostHog instance * * @returns {boolean} current opt-out status */ has_opted_out_capturing(): boolean; /** * Clear the user's opt in/out status of data capturing and cookies/localstorage for this PostHog instance */ clear_opt_in_out_capturing(): void; _is_bot(): boolean | undefined; _captureInitialPageview(): void; /** * Enables or disables debug mode. * You can also enable debug mode by appending `?__posthog_debug=true` to the URL * * @param {boolean} [debug] If true, will enable debug mode. */ debug(debug?: boolean): void; private _runBeforeSend; getPageViewId(): string | undefined; /** * Capture written user feedback for a LLM trace. Numeric values are converted to strings. * @param traceId The trace ID to capture feedback for. * @param userFeedback The feedback to capture. */ captureTraceFeedback(traceId: string | number, userFeedback: string): void; /** * Capture a metric for a LLM trace. Numeric values are converted to strings. * @param traceId The trace ID to capture the metric for. * @param metricName The name of the metric to capture. * @param metricValue The value of the metric to capture. */ captureTraceMetric(traceId: string | number, metricName: string, metricValue: string | number | boolean): void; } declare const posthog: PostHog; export { type ActionStepStringMatching, type ActionStepType, type AutocaptureCompatibleElement, type AutocaptureConfig, type BasicSurveyQuestion, type BeforeSendFn, type BootstrapConfig, type Breaker, COPY_AUTOCAPTURE_EVENT, type CaptureOptions, type CaptureResult, type CapturedNetworkRequest, Compression, type DeadClickCandidate, type DeadClicksAutoCaptureConfig, type DecideResponse, type DomAutocaptureEvents, type EarlyAccessFeature, type EarlyAccessFeatureCallback, type EarlyAccessFeatureResponse, type EarlyAccessFeatureStage, type ErrorConversionArgs, type ErrorConversions, type ErrorEventArgs, type ErrorMetadata, type ErrorProperties, type EvaluationReason, type EventHandler, type EventName, type FeatureFlagDetail, type FeatureFlagMetadata, type FeatureFlagsCallback, type FlagVariant, type Headers, type HeatmapConfig, type InitiatorType, type JsonRecord, type JsonType, type KnownEventName, type KnownUnsafeEditableEvent, type LinkSurveyQuestion, type MultipleSurveyQuestion, type NetworkRecordOptions, type NetworkRequest, type PerformanceCaptureConfig, type PersistentStore, PostHog, type PostHogConfig, type Properties, type Property, type QueuedRequestWithOptions, type RatingSurveyQuestion, type RemoteConfig, type RemoteConfigFeatureFlagCallback, type RequestCallback, type RequestQueueConfig, type RequestResponse, type RequestWithOptions, type RetriableRequestWithOptions, type SessionIdChangedCallback, type SessionRecordingCanvasOptions, type SessionRecordingOptions, type SessionRecordingUrlTrigger, type SeverityLevel, type SiteApp, type SiteAppGlobals, type SiteAppLoader, type SnippetArrayItem, type SupportedWebVitalsMetrics, type Survey, type SurveyActionType, type SurveyAppearance, type SurveyCallback, type SurveyElement, type SurveyMatchType, type SurveyQuestion, SurveyQuestionBranchingType, type SurveyQuestionDescriptionContentType, SurveyQuestionType, type SurveyRenderReason, type SurveyResponse, SurveySchedule, SurveyType, type ToolbarParams, type ToolbarSource, type ToolbarUserIntent, type ToolbarVersion, posthog as default, knownUnsafeEditableEvent, posthog, severityLevels };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sadiuysal/mem0-mcp-server-ts'

If you have feedback or need assistance with the MCP directory API, please join our Discord server