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.
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.
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.
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.
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.
Call once at signup, immediately before or after
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.
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.
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.
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.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.
Super properties merge with event-level properties. If the same key appears in both, the event-level value wins.
Remove a super property
Removes a single super property by key. The next captured event will no longer carry that key.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.
Reading a feature flag is synchronous and always reflects the most recent push from PostHog. No scheme call is needed.
Standard auth flow
Correct call order for a standard login and logout sequence.Not bridged
Resources
NPM Package
despia-native
PostHog Dashboard
Configure feature flags, funnels, and session recordings
PostHog Docs
Feature flags, person properties, and group analytics