Fire any named event with optional properties. This is the core call. PostHog merges your properties with the device context it captures automatically , OS, app version, screen size, and more. Your keys take precedence on any conflict.
Event name. Case-sensitive. Pass as-is, no encoding needed.
properties
No
Key-value pairs attached to the event. Wrap with encodeURIComponent(JSON.stringify(...)). Values can be strings, numbers, booleans, or flat arrays. Nested objects are not supported.
Use a consistent naming convention. PastTense verbs work well, e.g. Signed Up, Checkout Completed, Article Read. Avoid PII in event properties , use person properties via identify instead.
Associates the current anonymous device ID with a known user. Call this as soon as a user logs in. All subsequent events link to this identity until reset is called.
Your internal user ID. Pass as-is, no encoding needed.
properties
No
Person properties stored on the PostHog person record, not event properties. Wrap with encodeURIComponent(JSON.stringify(...)).
Person properties on the PostHog person record have separate retention and access controls from event properties. Never send raw PII as event properties , put it on the person record where you can manage it.After identify fires, despia.postHogDistinctId and despia.postHogSessionId update in place and reflect the new identity.
Merges two distinct IDs into the same person. Use this at signup when a user has generated anonymous events before logging in and you want the pre-signup history to merge into their identified profile.
despia('posthog://alias?alias=user_123')
Parameter
Required
Description
alias
Yes
The new ID to merge into the current distinct_id. Pass as-is, no encoding needed.
Call once at signup, immediately before or after posthog://identify. Do not call repeatedly. PostHog merges the anonymous session history permanently.
Links all subsequent events in the session to a group , an organization, team, workspace, or account. Must be called again if the user switches group context.
Group type key, e.g. company, team, workspace. Must match a group type defined in your PostHog project. Pass as-is.
key
Yes
Unique identifier for the specific group. Pass as-is.
properties
No
Group-level properties stored on the group record. Wrap with encodeURIComponent(JSON.stringify(...)).
PostHog has a hard limit of 5 group types per project. Group types are created automatically on first use. Coordinate type naming with your PostHog project owner before shipping , renaming a type later requires a backfill.
Sets or updates properties on the PostHog person record without capturing an event. Use this when a user updates their profile or when you receive new attributes from your backend.
Registers super properties , key-value pairs automatically appended to every subsequent capture call for the lifetime of the session. Useful for stable session-level context like locale or app_version.
Resets all user data and starts a fresh session. Clears the distinct_id, all person properties, all super properties, all group associations, and the session. Call this on logout only.
despia('posthog://reset')
After reset fires, the native layer updates despia.postHogDistinctId, despia.postHogSessionId, and despia.postHogFlags in place. Reads of those globals immediately after the call reflect the refreshed values.
Opts the user out of all PostHog tracking. No events are sent and no data is stored from this point forward. Persists across sessions until posthog://opt_in is called.
despia('posthog://opt_out')
This is the GDPR consent cutoff. Under GDPR, analytics tracking requires explicit user consent before any data is collected. Call opt_out when the user declines your consent prompt. PostHog enforces the cutoff at the SDK level , events fired after opt_out are dropped before they reach PostHog servers.despia.postHogOptedOut updates to true when this fires.
The native layer keeps four globals live on the despia object. They update in place whenever their value changes, with no page reload required. Read them when you need the current value , do not snapshot them at boot, since the page-load push is asynchronous and may arrive after your startup code runs.
despia.postHogDistinctId // current PostHog distinct_iddespia.postHogSessionId // current session IDdespia.postHogOptedOut // true if the user has opted outdespia.postHogFlags // all evaluated feature flag values, keyed by flag name
Global
Type
Description
postHogDistinctId
string
Updates on page load, after identify, and after reset. Defaults to "" until the native layer populates it.
postHogSessionId
string
Updates on page load, after identify, after reset, and once the first captured event opens a session. Defaults to "".
postHogOptedOut
boolean
Updates on page load and after opt_in / opt_out. Defaults to false.
postHogFlags
object
Updates on page load and whenever PostHog pushes new flag values. Defaults to {}. A flag not yet loaded is absent from the object , use "flag_name" in despia.postHogFlags to check.
Reading a feature flag is synchronous and always reflects the most recent push from PostHog. No scheme call is needed.
const enabled = despia.postHogFlags["new_checkout"] // boolean flagconst variant = despia.postHogFlags["checkout_variant"] // multivariate, e.g. "control" or "test_v2"