Installation
- Bundle
- CDN
Capture an event
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.| Parameter | Required | Description |
|---|---|---|
event | Yes | 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. |
Signed Up, Checkout Completed, Article Read. Avoid PII in event properties , use person properties via identify instead.
Identify a user
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.| Parameter | Required | Description |
|---|---|---|
distinct_id | Yes | 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(...)). |
despia.postHogDistinctId and despia.postHogSessionId update in place and reflect the new identity.
Merge a pre-signup ID
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.| Parameter | Required | Description |
|---|---|---|
alias | Yes | The new ID to merge into the current distinct_id. Pass as-is, no encoding needed. |
posthog://identify. Do not call repeatedly. PostHog merges the anonymous session history permanently.
Set group context
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.| Parameter | Required | Description |
|---|---|---|
type | Yes | 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(...)). |
Track a screen view
Sends a$screen event to PostHog with $screen_name set to the provided value. Use this on every route change inside your app.
| Parameter | Required | Description |
|---|---|---|
name | Yes | Screen or view name, e.g. Settings, Checkout, Profile. Pass as-is. |
properties | No | Additional properties attached to the screen event. Wrap with encodeURIComponent(JSON.stringify(...)). |
Set person properties
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.| Parameter | Required | Description |
|---|---|---|
properties | Yes | Properties to set. Merges with existing person properties. Wrap with encodeURIComponent(JSON.stringify(...)). |
Register super properties
Registers super properties , key-value pairs automatically appended to every subsequentcapture call for the lifetime of the session. Useful for stable session-level context like locale or app_version.
| Parameter | Required | Description |
|---|---|---|
properties | Yes | Properties to register. Persisted across page loads until posthog://unregister or posthog://reset. Wrap with encodeURIComponent(JSON.stringify(...)). |
Remove a super property
Removes a single super property by key. The next captured event will no longer carry that key.| Parameter | Required | Description |
|---|---|---|
key | Yes | The super property key to remove. Pass as-is. |
Reset on logout
Resets all user data and starts a fresh session. Clears thedistinct_id, all person properties, all super properties, all group associations, and the session. Call this on logout only.
despia.postHogDistinctId, despia.postHogSessionId, and despia.postHogFlags in place. Reads of those globals immediately after the call reflect the refreshed values.
Opt out of tracking
Opts the user out of all PostHog tracking. No events are sent and no data is stored from this point forward. Persists across sessions untilposthog://opt_in is called.
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.
Opt in to tracking
Opts the user in to PostHog tracking. Call this when the user explicitly accepts analytics in your consent prompt.despia.postHogOptedOut updates to false when this fires.
Reading current state
The native layer keeps four globals live on thedespia 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.
| 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. |
Standard auth flow
Correct call order for a standard login and logout sequence.Not bridged
| Capability | Reason |
|---|---|
getFeatureFlag / isFeatureEnabled | Use despia.postHogFlags , synchronous, always current, no scheme call needed |
reloadFeatureFlags / onFeatureFlags | Flag values are cached natively and pushed into despia.postHogFlags automatically |
| Session recording controls | Configured project-side in PostHog, not a per-user runtime concern |
| Surveys | Run via PostHog’s own JS embed, not a native SDK surface |
Resources
NPM Package
despia-native
PostHog Dashboard
Configure feature flags, funnels, and session recordings
PostHog Docs
Feature flags, person properties, and group analytics