PostHogInterface
Properties
| Name | Type |
|---|---|
debug | (debug?: boolean) => void |
Enable or disable debug mode. | |
version | string |
The library version. | |
flagsEndpointWasHit | boolean |
Whether the flags endpoint has been hit. | |
capture | (event_name: string, properties?: Properties | null, options?: CaptureOptions) => CaptureResult | undefined |
Capture an event. | |
captureException | (error: unknown, additionalProperties?: Properties) => CaptureResult | undefined |
Capture an exception. | |
addExceptionStep | (message: string, properties?: Properties) => void |
Adds a breadcrumb-like step that will be attached to the next captured exception as | |
captureLog | (options: CaptureLogOptions) => void |
Capture a log entry and send it to the PostHog logs endpoint. | |
logger | Logger |
Logger with convenience methods for each severity level. | |
identify | (new_distinct_id?: string, userPropertiesToSet?: Properties, userPropertiesToSetOnce?: Properties) => void |
Identify a user with a distinct ID and optionally set person properties. | |
setIdentity | (distinctId: string, hash: string) => void |
Set HMAC-based identity verification. | |
clearIdentity | () => void |
Clear HMAC-based identity verification, reverting to anonymous mode. | |
setPersonProperties | (userPropertiesToSet?: Properties, userPropertiesToSetOnce?: Properties) => void |
Set properties on the current user. | |
unsetPersonProperties | (propertyNames: string | string[]) => void |
Remove properties from the current user. | |
alias | (alias: string, original?: string) => CaptureResult | void | number |
Create an alias for the current user. | |
get_distinct_id | () => string |
Get the current distinct ID. | |
reset | (reset_device_id?: boolean) => void |
Reset the user's identity and start a new session. | |
shutdown | (shutdownTimeoutMs?: number) => Promise<void> |
Flush any queued events and gracefully tear down the SDK. | |
createPersonProfile | () => void |
Create a person profile for the current user. | |
setInternalOrTestUser | () => void |
Marks the current user as a test user by setting the This is useful for using in a cohort your internal/test filters for your posthog org. | |
group | (groupType: string, groupKey: string, groupPropertiesToSet?: Properties) => void |
Associate the user with a group. | |
getGroups | () => Record<string, any> |
Get the current groups. | |
resetGroups | () => void |
Reset all groups for the current user. | |
featureFlags | { overrideFeatureFlags(overrideOptions: OverrideFeatureFlagsOptions): void; override(flags: boolean | string[] | Record<string, string | boolean>, suppressWarning?: boolean): void; } |
The feature flags instance. Provides access to feature flag override methods. | |
getFeatureFlag | (key: string, options?: FeatureFlagOptions) => boolean | string | undefined |
Get the value of a feature flag. | |
getFeatureFlagPayload | (key: string) => JsonType |
Get the payload of a feature flag.
Deprecated: Use | |
getFeatureFlagResult | (key: string, options?: FeatureFlagOptions) => FeatureFlagResult | undefined |
Get a feature flag evaluation result including both the flag value and payload. By default, this method emits the | |
isFeatureEnabled | { (key: string, options: IsFeatureEnabledOptions & { defaultValue: boolean; }): boolean; (key: string, options?: IsFeatureEnabledOptions): boolean | undefined; } |
Check if a feature flag is enabled. | |
reloadFeatureFlags | () => void |
Reload feature flags from the server. | |
updateFlags | (flags: Record<string, boolean | string>, payloads?: Record<string, JsonType>, options?: { merge?: boolean; }) => void |
Manually update feature flag values without making a network request. | |
onFeatureFlags | (callback: FeatureFlagsCallback) => () => void |
Register a callback to be called when feature flags are loaded. | |
setPersonPropertiesForFlags | (properties: Properties, reloadFeatureFlags?: boolean) => void |
Set person properties to be used for feature flag evaluation. | |
resetPersonPropertiesForFlags | (reloadFeatureFlags?: boolean) => void |
Reset person properties used for feature flag evaluation. | |
setGroupPropertiesForFlags | (properties: { [type: string]: Properties; }, reloadFeatureFlags?: boolean) => void |
Set group properties to be used for feature flag evaluation. | |
resetGroupPropertiesForFlags | (group_type?: string) => void |
Reset group properties used for feature flag evaluation. | |
getEarlyAccessFeatures | (callback: EarlyAccessFeatureCallback, forceReload?: boolean, stages?: EarlyAccessFeatureStage[]) => void |
Get the list of early access features. | |
updateEarlyAccessFeatureEnrollment | (key: string, isEnrolled: boolean, stage?: EarlyAccessFeatureStage) => void |
Update enrollment in an early access feature. | |
register | (properties: Properties, days?: number) => void |
Register properties to be sent with every event. | |
register_once | (properties: Properties, default_value?: any, days?: number) => void |
Register properties to be sent with every event, but only if they haven't been set before. | |
register_for_session | (properties: Properties) => void |
Register properties for the current session only. | |
unregister | (property: string) => void |
Unregister a property so it is no longer sent with events. | |
unregister_for_session | (property: string) => void |
Unregister a session property. | |
get_property | (property_name: string) => any | undefined |
Get a property value from persistence. | |
getSessionProperty | (property_name: string) => any | undefined |
Get a session property value. | |
get_session_id | () => string |
Get the current session ID. | |
onSessionId | (callback: SessionIdChangedCallback) => () => void |
Register a callback to be called when the session ID changes. | |
get_session_replay_url | (options?: { withTimestamp?: boolean; timestampLookBack?: number; }) => string |
Get the URL to view the current session recording. | |
startSessionRecording | (override?: { sampling?: boolean; linked_flag?: boolean; url_trigger?: true; event_trigger?: true; } | true) => void |
Start session recording (if not already started). | |
stopSessionRecording | () => void |
Stop session recording. | |
sessionRecordingStarted | () => boolean |
Check if session recording has started. | |
sessionRecording | { _forceAllowLocalhostNetworkCapture: boolean; } |
The session recording instance. May be undefined if session recording is not initialized. | |
sessionManager | { resetSessionId: () => void; } |
The session manager instance. May be undefined in cookieless mode. | |
opt_in_capturing | () => void |
Opt the user into capturing. | |
opt_out_capturing | () => void |
Opt the user out of capturing. | |
has_opted_in_capturing | () => boolean |
Check if the user has opted in to capturing. | |
has_opted_out_capturing | () => boolean |
Check if the user has opted out of capturing. | |
get_explicit_consent_status | () => "granted" | "denied" | "pending" |
Get the explicit consent status. | |
clear_opt_in_out_capturing | () => void |
Clear the opt-in/out status. | |
getSurveys | (callback: (surveys: any[]) => void, forceReload?: boolean) => void |
Get the list of surveys. | |
getActiveMatchingSurveys | (callback: (surveys: any[]) => void, forceReload?: boolean) => void |
Get active surveys that match the current user. | |
renderSurvey | (surveyId: string, selector: string) => void |
Render a survey in a specific container. | |
canRenderSurvey | (surveyId: string) => SurveyRenderReason | null |
Check if a survey can be rendered. | |
canRenderSurveyAsync | (surveyId: string, forceReload?: boolean) => Promise<SurveyRenderReason> |
Check if a survey can be rendered (async version). | |
on | (event: "eventCaptured" | "featureFlagsReloading", cb: (...args: any[]) => void) => () => void |
Register an event listener. | |
startExceptionAutocapture | (config?: ExceptionAutoCaptureConfig) => void |
Start automatic exception capture. | |
stopExceptionAutocapture | () => void |
Stop automatic exception capture. | |
loadToolbar | (params: ToolbarParams) => boolean |
Load the PostHog toolbar. | |
getPageViewId | () => string | undefined |
Get the current page view ID. | |
captureTraceFeedback | (traceId: string | number, userFeedback: string) => void |
Capture written user feedback for a LLM trace. | |
captureTraceMetric | (traceId: string | number, metricName: string, metricValue: string | number | boolean) => void |
Capture a metric for a LLM trace. | |
people | { set: (prop: string | Properties, to?: string, callback?: RequestCallback) => void; set_once: (prop: string | Properties, to?: string, callback?: RequestCallback) => void; } |
Deprecated: Use | |
decideEndpointWasHit | boolean |
Deprecated: Use | |
config | PostHogConfig |