Skip to content

posthog-react-native@5.0.0

Latest

Choose a tag to compare

@github-actions github-actions released this 03 Dec 17:58
Immutable release. Only release title and notes can be modified.
10bb9d1

5.0.0

Major Changes

  • #5990 a393b4f Thanks @turnipdabeets! - - Breaking: session replay, native crash capture and push notification capture need the optional @posthog/react-native-plugin 3.x. posthog-react-native-session-replay is no longer loaded, and a plugin older than 3.0 is ignored with a warning to upgrade
    • Breaking: remove the PostHogProvider apiKey prop — pass projectToken instead
    • Breaking: remove evaluationEnvironments from the PostHogOptions type — pass evaluationContexts instead
    • Breaking: remove disableRemoteConfig, which had no effect, from the PostHogOptions type
    • Breaking: remove disable_capture_url_hashes, which had no effect, from the PostHogOptions type
    • Breaking: remove sessionReplayConfig.iOSdebouncerDelayMs and androidDebouncerDelayMs — pass throttleDelayMs instead
    • Breaking: remove sessionReplayConfig.screenshotModeBackgroundCapture, because posthog-ios 4.0 removed background capture — delete it, or try experimental iOSCaptureMethod: 'gpu'
    • Breaking: remove the autocapture.navigationRef option and the PostHogNavigationRef type, and drop the navigationRef argument from useNavigationTracker(options, client)
    • Breaking: onFeatureFlags callbacks receive one object, { flags, variants, errorsLoading }, like posthog-ios, posthog-android and posthog_flutter: flags lists the enabled flag keys, variants maps them to true or their variant, and errorsLoading is true when the latest load failed (the values are then the last known ones). Disabled flags and flags whose variant is an empty string are left out. Replace onFeatureFlags((flags) => …) with onFeatureFlags(({ flags, variants, errorsLoading }) => …)
    • Breaking: a callback registered after flags have loaded is also called once with the current values, right after onFeatureFlags returns
    • Breaking: a feature flag payload that isn't valid JSON, including an empty one, reads as null instead of its raw string
    • Breaking: reloadFeatureFlagsAsync() resolves with { flags, variants, errorsLoading }, the object onFeatureFlags callbacks receive, instead of a map of every loaded flag. After a failed reload it resolves with the last known flags and errorsLoading: true instead of undefined
    • Breaking: a flag whose variant is an empty string reads as disabled (enabled: false) in getFeatureFlagResult(), getAllFeatureFlags() and useFeatureFlagResult(), as it already did in isFeatureEnabled(), like posthog-ios and posthog-android 4.0
    • Breaking: leave disabled flags and flags whose variant is an empty string out of $active_feature_flags, like posthog-ios and posthog-android
    • Breaking: keep a string payload in bootstrap.featureFlagPayloads as a string instead of parsing it as JSON, like posthog-ios 4.0 — pass decoded values, such as { color: 'blue' } instead of '{"color":"blue"}'
    • Breaking: getAllFeatureFlags() returns undefined instead of an empty list before flags first load — use posthog.getAllFeatureFlags() ?? [] where you only iterate
    • Breaking: getFeatureFlag() returns undefined instead of false for a flag that isn't in the loaded flags, like posthog-ios, posthog-android and posthog_flutter — use getFeatureFlagResult(key)?.enabled === false to check that a flag is off
    • Breaking: isFeatureEnabled() without a defaultValue returns false instead of undefined when the flag has no value, such as before flags load, like posthog-ios, posthog-android and posthog_flutter — use getFeatureFlagResult(key) === undefined to check that a flag has no value yet
    • Breaking: $feature_flag_called events carry $used_bootstrap_value only for a flag set in bootstrap.featureFlags, like posthog-ios and posthog-android
    • Breaking: getFeatureFlagDetails() is internal and can change in any release — use getAllFeatureFlags()
    • Breaking: identify() requires a distinct ID in its type, like posthog-ios, posthog-android and posthog_flutter — replace identify(undefined, properties) with setPersonProperties(properties)
    • Breaking: identify() with an empty or whitespace-only distinct ID logs a warning and does nothing, like posthog-ios and posthog-android, instead of saving a blank distinct ID or sending $set for the current one
    • Breaking: PostHog extends PostHogCoreBase from @posthog/core instead of PostHogCore, which only matters to code that refers to those types
    • Breaking: rename the per-call sendEvent option of getFeatureFlag(), getFeatureFlagResult() and isFeatureEnabled() to sendFeatureFlagEvent
    • Breaking: remove getFeatureFlagPayload() — use getFeatureFlagResult(key, { sendFeatureFlagEvent: false })?.payload
    • Breaking: remove getFeatureFlags(), getFeatureFlagPayloads() and getFeatureFlagsAndPayloads() — use getAllFeatureFlags()
    • Breaking: remove onFeatureFlag() — use onFeatureFlags() and read the flag with getFeatureFlagResult()
    • Breaking: remove overrideFeatureFlag() — use updateFlags(), and set disableRemoteFeatureFlags to keep the values from being replaced by the next load. Overrides set with it in 4.x are cleared on upgrade
    • Breaking: remove the useFeatureFlagWithPayload() hook and its FeatureFlagWithPayload type — use useFeatureFlagResult()
    • Breaking: remove the useFeatureFlag() hook — use useFeatureFlagVariantKey(key) for the value or useFeatureFlagEnabled(key) for on/off. For a flag that isn't in the loaded flags, both return undefined (or the default you pass to useFeatureFlagEnabled()) where useFeatureFlag() returned false
    • Breaking: remove the useFeatureFlags() hook — use useActiveFeatureFlags() for the enabled flag keys
    • Breaking: a registered or caller $is_identified property replaces the SDK's value on that event, and a null one sends the event without it, including a fatal exception the native SDK sends. A registered or caller $process_person_profile decides whether that event processes the person, where 4.x replaced it with its own value; a null one counts as unset
    • Breaking: leave a registered $process_person_profile off $identify, $create_alias, $groupidentify, $set, $set_once and $merge_dangerously events, so registering false no longer stops identify(), alias(), group() and setPersonProperties() from working; a before_send hook can still set it
    • Breaking: send person processing as posthog-ios and posthog-android 4.0 do: an event that doesn't process the person gets the process_person_profile: false capture v1 option, and one that does gets none. Events no longer carry a $process_person_profile property unless you set one, so before_send doesn't see it, and removing or changing $process_person_profile there doesn't make a personless event process the person
    • Breaking: add $is_identified to $autocapture events, and send them with the process_person_profile: false option for anonymous users under personProfiles: 'identified_only', so anonymous autocapture follows the policy like other events
    • Breaking: leave null and undefined property values off events; $set, $set_once and $group_set keep their null values, which clear the person or group property
    • Breaking: let a registered property replace the SDK's own value of the same name, such as $os_name, $app_version, $screen_width, $feature/<key> or $active_feature_flags, like posthog-ios and posthog-android 4.0; a property passed on the call still wins over both
    • Breaking: fill $lib and $lib_version as a pair after your properties, like posthog-ios and posthog-android 4.0: a $lib you pass or register without $lib_version is sent without one, and a $lib_version without $lib is replaced by the SDK's
    • Breaking: a $groups you pass to capture(), screen() or captureException() adds to the groups set with group() for that event, the passed key winning per group type, like posthog-ios and posthog-android 4.0. It's no longer saved for later events, doesn't reload feature flags, and doesn't make an anonymous user's events process the person under personProfiles: 'identified_only' — call group() for groups that should stick. A $groups you pass to identify() is no longer saved either
    • Breaking: send a registered or caller $session_id on that event instead of the SDK's session id; a null, blank or non-string one counts as unset
    • Breaking: send $session_id and $window_id as the top-level session_id and window_id fields of the capture v1 event, like posthog-ios and posthog-android 4.0, and drop a $window_id, or a $session_id set in before_send, that isn't a string, with a console warning; the rest of the event is still sent
    • Breaking: let a registered or caller $geoip_disable win over the disableGeoip option; a per-call disableGeoip wins over the option and a registered value, and is sent as $geoip_disable: true or false; a $geoip_disable you pass on the call wins over all of them
    • Breaking: let a registered or caller $recording_status or $sdk_debug_* property win over the SDK's session replay debug value, except $sdk_debug_pending_queue_size
    • Breaking: send events to capture v1 (/i/v1/analytics/events) instead of /batch/, authenticated with Authorization: Bearer <projectToken> — serve this path on reverse proxies and self-hosted instances
    • Breaking: send $cookieless_mode, $ignore_sent_at and $product_tour_id as the capture v1 options cookieless_mode, disable_skew_correction and product_tour_id, with their values unchanged, like posthog-ios and posthog-android 4.0. PostHog drops an event whose option value it can't read, such as $cookieless_mode: 'maybe' or $product_tour_id: 1.5, and posthog.on('error') reports it, where 4.x sent it as a property — pass true or false for $cookieless_mode and $ignore_sent_at, and a string for $product_tour_id
    • Breaking: a 2xx capture response without a PostHog results body drops the batch and reports it on posthog.on('error') — reverse proxies must return PostHog's response body unchanged
    • Breaking: on react-native-web, a reverse proxy that answers CORS preflight requests with a fixed Access-Control-Allow-Headers list must allow Authorization, PostHog-Sdk-Info, PostHog-Attempt, PostHog-Request-Id and PostHog-Request-Timestamp, or the browser blocks every capture request and events stay queued
    • Breaking: Authorization, User-Agent, Content-Type, Content-Encoding and the PostHog- headers the SDK sets no longer reach capture requests from requestHeaders; other requestHeaders still do
    • Breaking: PostHog drops an event whose distinct ID or event name is over 200 UTF-8 bytes, such as one with a JWT as its distinct ID, and posthog.on('error') reports it. 4.x shortened a long distinct ID and kept the event
    • Breaking: a uuid you pass to capture() or another event method is sent in lowercase, and one that isn't a valid UUID is replaced with a new one
    • Breaking: flush() and shutdown() no longer reject when a send fails: events kept for a later send stay queued, and dropped events (for example after a 400 or 401) are reported on posthog.on('error') instead
    • Breaking: send queued events every 30 seconds instead of every 10, and at most 50 per request instead of 100, like posthog-ios and posthog-android — pass flushInterval: 10000 and maxBatchSize: 100 to keep the 4.x timing
    • Breaking: fetchRetryCount and fetchRetryDelay no longer apply to event delivery
    • Breaking: posthog.on('error') no longer fires for network errors or retryable statuses while events stay queued; it still fires for dropped events, with an error carrying drops, requestId, retryExhausted and cause instead of response
    • Breaking: a personal API key (phx_...) passed as the project token disables the client and logs an error, like posthog-node, posthog-ios and posthog-android, instead of being sent to PostHog
    • Breaking: captureTraceFeedback() and captureTraceMetric() send $ai_feedback and $ai_metric through captureAi() to the AI endpoint instead of the analytics endpoint
    • Breaking: a return from the background captures Application Opened with from_background: true instead of Application Became Active, like posthog-ios and posthog-android. The launch Application Opened carries from_background: false. Application Backgrounded is captured once per trip to the background, and a return from inactive without going to the background, such as closing Control Center on iOS, captures nothing. A launch in the background captures its Application Opened at the first foreground. Application Opened charts count more events after the upgrade: filter on from_background is not true to count launches only, and on true instead of Application Became Active
    • Breaking: keep each project token's stored state (distinct id, opt-out choice, queued events, session and cached feature flags) separately, like posthog-ios and posthog-android, so clients with different tokens no longer overwrite each other's. On upgrade, the first client to load takes over the state 4.x stored; clients with other tokens start with a new anonymous distinct id and the default opt-in state, so call optOut() on any that should stay opted out. Logs 4.x queued and hadn't sent are dropped. Going back to 4.x after upgrading resets the stored state, including the opt-out choice, and upgrading again keeps what 5.0 stored before and drops what 4.x stored since
    • Add an optional removeItem to PostHogCustomStorage, which deletes the entries 4.x shared between project tokens once 5.0 no longer needs them
    • Add the useFeatureFlagEnabled(), useFeatureFlagVariantKey(), useFeatureFlagPayload() and useActiveFeatureFlags() hooks, matching @posthog/react
    • Fix onFeatureFlags callbacks and flag reads returning the previous user's flags when reset() runs during a flag request
    • Fix the stored distinct id, queued events and opt-out choice resetting when the app is killed while the SDK saves them with Expo's file system
    • Keep events queued when a send gets no response, a 404, 408, 429, 500, 502, 503 or 504, or a retry result, and send them again after a wait of 1 second doubling to 30 seconds (longer if the server's Retry-After asks, up to 30 seconds), with no attempt limit. flush() during that wait resolves without sending, and shutdown() waits it out when it fits in its timeout
    • Drop an event that can't be serialized, such as one with a property whose toJSON() throws, on its own and report it on posthog.on('error') with details: 'unserializable event'; an invalid event name or id is reported with details: 'invalid event'
    • Cap each capture request at 5 MiB of event bytes, starting a new request before a batch would pass it
    • Add captureAi(), which sends AI observability events such as $ai_generation to PostHog's AI endpoint (/i/v1/ai/events) from their own queue, with the captureAiCompression, captureAiMaxQueueSize, captureAiRequestTimeoutMs and captureAiMaxEventBytes options — serve /i/v1/ai/events on reverse proxies and self-hosted instances. Unsent AI events are kept across app restarts in the app's cache directory, which isn't backed up, when the SDK uses Expo's file system; with persistence: 'memory', customStorage or AsyncStorage they're kept only in memory
    • Report AI events dropped before sending (invalid, unserializable, too large, or pushed out of a full queue) on posthog.on('error'), like posthog-node
    • Export CaptureError and the CaptureDroppedEvent, CaptureEndpoint and CaptureErrorParams types, like posthog-node, so a posthog.on('error') handler can check error instanceof CaptureError
    • Send a captureAi() event over captureAiMaxEventBytes without its $ai_input, $ai_output, $ai_output_choices, $ai_input_state, $ai_output_state and $ai_tools, with $ai_content_removal_reason: 'event_too_large' and $ai_event_bytes_before_removal, like posthog-node, instead of dropping it
    • Keep a stored AI event whose file fails to read and read it again on the next send, dropping it after 3 failed reads, and drop and report stored AI events over a captureAiMaxEventBytes lowered since they were queued
    • Gzip analytics, AI and log requests on iOS and Android when @posthog/react-native-plugin 3.0 or later is installed; without it they're sent uncompressed, as in 4.x, and posthog.debug(true) logs once that they are
    • Send analytics events uncompressed when the plugin's gzip takes longer than requestTimeout, and never send them after shutdown() returns, even when a gzip still running then finishes
    • Send AI events again in batches half the size after a request reaches captureAiRequestTimeoutMs, so a slow network still delivers them, and return to full-size batches as later sends get through; a single AI event that still times out is kept and sent again after the AI events queued behind it
    • Warn once, even without debug: true, when the analytics or AI endpoint returns 404 (a reverse proxy or self-hosted instance that doesn't serve /i/v1/analytics/events or /i/v1/ai/events) or 401 (a proxy that doesn't forward the Authorization header), like posthog-ios and posthog-android
    • Send analytics events as soon as 5 MiB of them is queued, without waiting for flushAt, like posthog-ios and posthog-android
    • Send analytics events again in batches half the size after a request reaches requestTimeout, so a slow network still delivers them, and return to full-size batches as later sends get through
    • Send the device time zone as timezone with /flags requests, like posthog-ios and posthog-android; set $timezone to null in customAppProperties to leave it out
    • Add captureFeatureView(flag, flagVariant?) and captureFeatureInteraction(flag, flagVariant?), like posthog-ios and posthog-android: they capture $feature_view and $feature_interaction with feature_flag and feature_flag_variant, and set the $feature_view/<flag> or $feature_interaction/<flag> person property to the variant. Without flagVariant they read the flag without capturing $feature_flag_called, and skip the event when the flag has no value
    • Add resetGroupPropertiesForFlags(groupType, reloadFeatureFlags?) to reset one group type's properties for flags and keep the others, like posthog-ios and posthog-android
    • Debug mode logs only the name and uuid of each event, the number of events in each flush, and the type of an error before_send throws, like posthog-ios, posthog-android and posthog-node, instead of the whole event
    • Take the random bits of event uuids from crypto.getRandomValues when the runtime has it, such as with react-native-get-random-values imported first, like posthog-node; otherwise Math.random, as in 4.x
    • Keep a registered $cookieless_mode, $ignore_sent_at or $product_tour_id on minimal $feature_flag_called events, like posthog-ios and posthog-node
    • Fix an event that carries its own $session_id and matches a session replay event trigger or trigger group on an expired SDK session: it now starts a new SDK session and session replay records into it
    • Warn once on the console, even without debug: true, when enableSessionReplay is on and @posthog/react-native-plugin isn't installed, so an app with only posthog-react-native-session-replay sees why replay stopped recording (2026-12-03)

Minor Changes

  • #5990 a393b4f Thanks @turnipdabeets! - Add per-event options, such as { options: { process_person_profile: false } }, to capture(), screen(), identify(), setPersonProperties(), unsetPersonProperties(), alias(), group(), groupIdentify(), captureException() and captureAi(), like posthog-ios and posthog-android 4.0
    (2026-12-03)

Patch Changes