Migrate the Android SDK from 3.x.x to 4.0.0
The Android SDK 4.x.x sends analytics and AI events to the capture v1 endpoints, /i/v1/analytics/events and /i/v1/ai/events.
On posthog.com, use the copy page button at the top right to work through this with your agents.
You don't need to make every change on the day you upgrade your SDK. Changes fall in these categories:
- Before you upgrade: These are changes you should make before you upgrade your SDK to 4.x.x.
- During your upgrade: These are changes that you need to make in the same PR that upgrades your SDK version.
- Follow ups: These are changes that can come in follow up PRs, because 4.x.x still accepts the old names and options.
Checklist
Read the checklist first, then the sections that apply to you.
Before you upgrade
- Your app is a React Native, Flutter, or Kotlin Multiplatform app → Upgrade wrapper packages
- You send events to a self-hosted PostHog or a reverse proxy that doesn't serve
/i/v1/analytics/events→ Prepare your proxy - You authenticate your proxy with an
Authorizationheader inrequestHeaders→ Prepare your proxy - You send events through a reverse proxy set up from PostHog's proxy guides before 29 October 2026, which strips
Authorization→ Prepare your proxy - You send events through a proxy that redirects capture requests, other than with a 307 or 308 to the same origin as
host→ Prepare your proxy - You set
projectTokento a personal API key (phx_...) → Use a project token - You read a feature flag payload that isn't valid JSON, such as plain text saved as
hello→ Fix flag payloads - A feature flag has an empty string as a variant → Rename empty variants
- You capture events with a distinct ID over 200 bytes → Shorten long IDs
During your upgrade
- You depend only on
posthog-android-surveys-compose→ Upgrade your dependencies - You use
posthog-server(2.26.0 and later needposthog-android4.0.0 in the same project) → Upgrade posthog-server - You call
PostHogStateless.with, or extendPostHogStateless→ Update PostHogStateless code - You use
apiKey,propertiesSanitizer,evaluationEnvironments,debouncerDelayMs,screenshot, ordrawableConverter→ Fix removed APIs - You pass
PostHogConfigorPostHogSessionReplayConfigconstructor arguments by position → Fix removed APIs - You call
getFeatureFlagPayload(), or pass a default value togetFeatureFlag()→ Fix flag calls - You use
remoteConfig→ Remove remoteConfig - You set
PostHogConfig.onFeatureFlagsorPostHogOnFeatureFlags, or pass a callback toreloadFeatureFlags()→ Move the flags callback - You call
capture,screen,identify,setPersonProperties,alias,group, orcaptureExceptionfrom Java, or callidentifythrough aPostHogCoreInterfacereference → Add the options argument - You implement
PostHogInterface→ Update interface implementations - You use
@PostHogInternalAPIs → Drop internal APIs - You filter insights, cohorts, or actions on the
$feature_flag_responseof$feature_flag_called, such as""orfalsefor a missing flag → Check flag events - You break down by
$localefor the language your app shows (use$app_language, and callsetAppLanguage()if you need it on Android 6 to 12) → Check locale properties - You use session replay → Check session replay
- You read
$-prefixed query parameters fromDeep Link Openedevents → Check deep links - You depend on
posthog-android-surveys-composeor setsurveysConfig.surveysDelegate, and don't setsurveys→ Check surveys - You capture events with an empty event name, or with an event name over 200 bytes → Check dropped events
- You set an empty distinct ID in
beforeSend→ Check dropped events - You set
$process_person_profile,$cookieless_mode,$ignore_sent_at, or$product_tour_idto a value PostHog can't read, such as"maybe"→ Check dropped events - You read event content or request bodies from the SDK's debug log, or match its log text → Update log checks
- You register a super property, or pass an event property, with the same key as one the SDK sets, such as
$os_nameor$is_identified, and expect the SDK's value to win → Check property precedence - You read
$session_idor$window_idfrom the raw request body, for example in a proxy → Check session IDs - You assign a new map to
event.optionsinbeforeSend→ Review beforeSend hooks - You set the event
uuidinbeforeSend→ Review beforeSend hooks - You register
$process_person_profileasfalseand expect it to keep every event personless → Check person processing - You rely on a
Retry-Afterlonger than 30 seconds → Check retries - You set
maxRetriesonPostHogConfigorPostHogAndroidConfig→ Check retries - You might go back to 3.x.x after you ship 4.x.x → Plan your rollback
Follow ups
- You set legacy option properties like
$process_person_profile→ Move to event options - You capture
$ai_events withcapture()→ Send AI events with captureAi
Before you upgrade
Upgrade wrapper packages
Don't add the Android SDK 4.x.x to a React Native, Flutter, or Kotlin Multiplatform app yourself. These apps get the Android SDK through their PostHog package (@posthog/react-native-plugin, posthog_flutter, posthog-kmp).
Upgrade to the version of that package that moves to the Android SDK 4.x.x, and follow its migration notes.
Until then, keep core posthog 7.x.x and posthog-server 2.26.0 or later out of the app's build. Either one makes Gradle upgrade posthog-android to 4.x.x (see Upgrade your dependencies), but the package's Android code is still built against 3.x.x, so it fails at runtime with errors such as NoSuchMethodError.
Prepare your proxy
posthog-android 4.x.x sends data to these endpoints:
| Data | 3.x.x | 4.x.x |
|---|---|---|
| Analytics events | /batch | /i/v1/analytics/events |
| Session replay | /s/ | /s/, unchanged |
AI events (captureAi) | None | /i/v1/ai/events (see Send AI events with captureAi) |
| Logs | /i/v1/logs | /i/v1/logs, unchanged |
| Feature flags | /flags | /flags, unchanged |
Capture v1 requests send the project token in an Authorization: Bearer <projectToken> header instead of an api_key body field.
This header replaces any Authorization header you set in PostHogConfig.requestHeaders, so authenticate your proxy with a different header, such as X-Proxy-Token. Other requests still send your Authorization header.
Analytics requests are gzipped unless you set compression to PostHogCompression.NONE, as in 3.x.x.
If you self-host PostHog, make sure your instance serves /i/v1/analytics/events, and /i/v1/ai/events if you use captureAi, before you upgrade.
If you send events through your own reverse proxy, update it before you upgrade:
- Forward both routes. Forward
/i/v1/analytics/eventsand/i/v1/ai/eventsto PostHog. - Pass the headers through unchanged. Pass
Authorization, everyPostHog-*header,Content-Type,Content-Encoding, andUser-Agent.Authorizationholds the project token, sent asBearer <token>. PostHog answers401withoutAuthorizationand400without the others, and the events are dropped. - Keep PostHog's credentials. If your proxy strips other credentials, keep
Authorizationvalues that start withBearer phc_,Bearer phs_, orBearer phx_. Keep the exactBearer <key>of an older key without a prefix too. - Accept request bodies up to 20 MB. AI requests are often larger than 1 MB, the default limit in nginx and ingress-nginx. A
413from the proxy makes the SDK halve the batch until it fits. The SDK drops an event that doesn't fit on its own. - Pass PostHog's response body through unchanged. A 2xx response whose body isn't PostHog's
{"results": {...}}drops the events instead of retrying them.
PostHog's managed reverse proxy already does this and needs no change.
A proxy set up from PostHog's proxy guides before 29 October 2026 strips Authorization, so PostHog answers 401 and the events are dropped, with one warning in the logs. Update it from the current guide.
The SDK doesn't fall back to /batch. It retries a 404, so the events stay queued until the path is served. The SDK prints one warning, even with debug off.
Any other error status that isn't retried, such as 403 or 405, drops the events.
The SDK follows a 307 or 308 redirect only to the origin of host, at most 5 times. The origin is the same scheme, host, and port. The SDK resends the same body and headers.
The SDK doesn't follow any other redirect, and the events are dropped. In 3.x.x, OkHttp followed redirects to any host.
If a proxy redirects capture requests to another host, point host at the final host.
This also applies when you set your own httpClient. For capture requests, the SDK turns off its redirect following and OkHttp's connection retries, and keeps your other settings. Other requests, such as session replay and logs, behave as in 3.x.x.
Use a project token
A personal API key (phx_...) in projectToken disables the SDK at setup, as an empty or whitespace-only token does. Both print why, even when debug is off.
In 3.x.x, the SDK started and PostHog rejected every event with a 401. Use your project token (phc_...).
To turn the SDK off in tests, use an empty token.
Fix flag payloads
In 4.x.x, a payload that isn't valid JSON reads as null from getFeatureFlagResult(key)?.payload and getAllFeatureFlags(). 3.x.x returned the raw string. With debug on, the SDK logs the flag key.
| Payload | 3.x.x | 4.x.x |
|---|---|---|
Malformed ({broken, [1, 2), empty or whitespace-only | the raw string | null |
Only valid in lenient mode (unquoted hello, single quotes, comments) | decoded leniently | null |
JSON null | the string "null" | null |
Valid JSON ("hello", "", false, 0, objects, arrays) | decoded | decoded, unchanged |
| Bootstrapped payloads | as passed | as passed, unchanged |
The flag's value, enabled state, variant, and any other flag's payload aren't affected.
You might read a payload as plain text, such as a payload saved as hello rather than "hello". Update it in PostHog to valid JSON before you upgrade, or your code gets null.
PostHog no longer saves a new payload that isn't valid JSON, so only payloads saved earlier are affected.
Apps that upgrade from 3.13.x or older didn't cache flag details. Until the app's first /flags response, a malformed payload cached by 3.x.x still reads as the raw string, as it did in 3.x.x.
Rename empty variants
In 4.x.x, a flag whose variant is an empty string reads as disabled everywhere. isFeatureEnabled() already read it as disabled in 3.x.x, with or without defaultValue.
- Flag results.
getFeatureFlagResult()andgetAllFeatureFlags()returnenabled = falsefor it. 3.x.x returnedtrue. - Loaded flags.
PostHogFeatureFlagsLoadedleaves it out offlagsandvariants. - Captured events. Captured events leave it out of
$active_feature_flags. - Variant values.
variant,getFeatureFlag(), and the event's$feature/<key>property still return"".
PostHog no longer accepts empty variants for new flags, so only flags created earlier through the API, MCP, or Terraform are affected.
/flags still returns enabled: true for them, and other PostHog SDKs can still report them as enabled, so rename the variant before you upgrade.
Shorten long IDs
PostHog drops an event whose distinct ID is over 200 UTF-8 bytes. Legacy capture shortened the ID to 200 characters and kept the event.
The distinct ID can come from identify(), the distinctId argument of capture, or beforeSend.
If you identify users with a long ID, such as a JWT or a long email address, shorten or hash it before you upgrade. Otherwise every event for that user is dropped.
During your upgrade
Upgrade your dependencies
Upgrade PostHog artifacts together:
| Artifact | Upgrade |
|---|---|
com.posthog:posthog-android | 3.x.x to 4.0.0 |
com.posthog:posthog (core) | 6.x.x to 7.0.0 |
com.posthog:posthog-android-surveys-compose | Keep your version |
com.posthog:posthog-server | 2.26.0, together with posthog-android 4.0.0 (see Upgrade posthog-server) |
With posthog-android-surveys-compose, declare com.posthog:posthog-android 4.0.0 or later in your build, so Gradle resolves 4.x.x instead of the 3.x.x version it pulls in.
Core posthog 7.x.x isn't binary compatible with SDK versions built against core 6.x.x. The exception is posthog-android-surveys-compose, which works with both.
When core 7.x.x is in a Gradle build, for example through posthog-server 2.26.0, Gradle upgrades posthog-android to 4.x.x, even over a range such as [3.75.0,4.0.0). Code that still uses removed APIs then fails to compile.
Other mismatches fail at runtime with errors such as NoSuchMethodError or NoClassDefFoundError.
The Android minimum API level (23), the Java bytecode target (Java 8), the Kotlin language and API compatibility (2.0), and posthog-android-gradle-plugin are unchanged. You don't need to change your build for them.
The changelog lists every 4.0.0 change.
Upgrade posthog-server
posthog-server has no major release, and its API is unchanged. It keeps its own apiKey, getFeatureFlagPayload, and remoteConfig, and com.posthog.PostHogOnFeatureFlags ships in posthog-server itself.
It still sends events to /batch, not to capture v1. The API, endpoint, proxy, retry, and event option changes in this guide don't apply to it.
posthog-server 2.26.0 depends on core posthog 7.0.0, so upgrade it and posthog-android together:
- With
posthog-android4.x.x or core 7.x.x. Useposthog-server2.26.0 or later. Olderposthog-serverversions aren't compatible with core 7.x.x at runtime, so Gradle upgrades them to 2.26.0. - With
posthog-android3.x.x. Stay onposthog-server2.25.x or older.posthog-server2.26.0 brings in core 7.0.0, and Gradle then upgradesposthog-androidto 4.x.x.
These changes apply to posthog-server too:
- Personal API keys. A personal API key (
phx_...) inprojectTokendisables the client at setup, as an empty token does. Both print why, even whendebugis off. - Empty names. The client drops events with an empty name before sending.
- Merged maps.
userProperties,userPropertiesSetOnce, andgroupsmerge key by key over a$set,$set_once, or$groupsmap inproperties. nullelements. Anullelement in a list or array in the properties is sent as JSONnullat its position instead of being removed.beforeSendcopies.beforeSendgets its own copy of the event's nested maps, lists, and arrays, so its changes no longer reach the objects you passed tocapture.- Event options.
PostHogEvent, whichbeforeSendgets, keeps its 3.x.x constructor andcopy, and gains anoptionsproperty./batchdoesn't use it, so a value set inbeforeSendis sent but has no effect.
Update PostHogStateless code
Core posthog 7.x.x is only supported through posthog-android 4.x.x and posthog-server. PostHogStateless.with isn't a supported entry point in core 7.x.x, and is deprecated.
PostHogStateless has no queue of its own, so it gets Android's capture v1 behavior, including the persisted-queue retries, which isn't a server-side contract. Use posthog-server for server-side JVM apps.
A class that extends PostHogStateless also needs an update. The protected buildEvent() gained options and uuid parameters, and captureFeatureFlagCalledEvent() is no longer protected.
Fix removed APIs
posthog-android 4.x.x removes these APIs. Each one is a compile error. A call from an already-compiled library that you haven't updated fails at runtime.
| Removed | Use instead |
|---|---|
PostHogConfig.apiKey, PostHogConfig(apiKey = …), PostHogAndroidConfig(apiKey = …) | projectToken |
PostHogConfig.propertiesSanitizer, PostHogPropertiesSanitizer | addBeforeSend |
PostHogConfig.evaluationEnvironments | evaluationContexts |
getFeatureFlagPayload(), on the instance and on PostHog | getFeatureFlagResult() (see Fix flag calls) |
defaultValue on getFeatureFlag() | getFeatureFlag(key) ?: default (see Fix flag calls) |
PostHogSessionReplayConfig.debouncerDelayMs | throttleDelayMs |
PostHogSessionReplayConfig.screenshot, drawableConverter, PostHogDrawableConverter | Nothing |
PostHogConfig.remoteConfig | Nothing |
PostHogConfig.onFeatureFlags | PostHog.onFeatureFlags() before setup() (see Move the flags callback) |
PostHogOnFeatureFlags | PostHogFeatureFlagsCallback |
PostHogConfig.maxRetries | pushNotificationSubscriptionMaxRetries (see Check retries) |
Replay always records screenshots (see Check session replay). Remote config always loads (see Remove remoteConfig).
The constructor parameters of PostHogConfig and PostHogSessionReplayConfig move up where these were removed. If you pass arguments by position, check them, or switch to named arguments.
Replace apiKey with projectToken:
PostHogAndroidConfig("phc_your_project_token"), with no parameter name, still works. From Java, replace getApiKey() with getProjectToken().
Replace propertiesSanitizer with addBeforeSend:
addBeforeSend gets the whole PostHogEvent. Return null to drop the event. If the hook throws, the event is dropped.
Replace evaluationEnvironments with evaluationContexts:
Replace debouncerDelayMs with throttleDelayMs:
Fix flag calls
getFeatureFlagPayload() never sent $feature_flag_called. getFeatureFlagResult() sends it by default, following sendFeatureFlagEvent.
Pass sendFeatureFlagEvent = false to keep your event volume and experiment exposures unchanged. If you drop that argument, nothing fails, but you'll send new events.
getFeatureFlagResult() has no defaultValue parameter, so apply your default with ?::
getFeatureFlag() has no defaultValue parameter either:
The second parameter of getFeatureFlag() is sendFeatureFlagEvent in 4.x.x, which affects code that still compiles:
- Boolean arguments.
getFeatureFlag("checkout", true)compiles, buttruemeanssendFeatureFlagEventrather than the default value. - A disabled SDK. A disabled SDK returns
null, not your default. - Fallback values.
$feature_flag_calledno longer reports a fallback as the flag's value.isFeatureEnabled("missing", true)still returnstrue, but its event leaves out$feature_flag_response(see Check flag events).
Classes that implement PostHogInterface update the signature.
Remove remoteConfig
Apps that left remoteConfig at its default of true see no behavior change. Delete the option:
If you set it to false, your app's behavior changes:
- Requests at setup. The SDK requests remote config (
/array/<projectToken>/config) at setup, even ifpreloadFeatureFlagsis alsofalse. 3.x.x sent no request at all. - Project settings. The settings in
/configapply, including the session replay, surveys, error tracking, and push settings from your project. - Flag requests. With
preloadFeatureFlags = true, the SDK requests/flagsonly if/configreports that the project has feature flags. 3.x.x always requested/flags. If the project has none, the cached flags are cleared.
Move the flags callback
PostHogConfig.onFeatureFlags is removed. Call PostHog.onFeatureFlags() before setup() instead, which also covers the first load.
An instance from PostHogAndroid.with() is set up as it's created, so call onFeatureFlags() on it right after with(). If flags have already loaded, the listener gets the current values shortly after it registers.
reloadFeatureFlags() takes a PostHogFeatureFlagsCallback. Both callbacks receive a PostHogFeatureFlagsLoaded:
| Field | Holds |
|---|---|
flags | The keys of the enabled flags |
variants | Their values, either true or the variant string |
errorsLoading | Whether the latest load failed |
When the latest load failed, the values are the last known ones, which can be empty.
Register the listener before setup():
The listener differs from the removed option in three ways:
- Thread. It runs on the main thread on Android. The option ran on a background thread.
- Bootstrapped flags. They arrive just after
setup()is called, not synchronously inside it. - Disabled SDK. A reload on a disabled SDK doesn't call listeners.
reloadFeatureFlags(callback)still getserrorsLoading = truein that case.
onFeatureFlags() is the way to listen for flag loads, for example from a screen or a library. You can remove the listener later:
You can register before setup(), and listeners stay registered across close() and setup().
From Java, the reloadFeatureFlags() lambda takes the PostHogFeatureFlagsLoaded argument:
A Kotlin trailing lambda such as PostHog.reloadFeatureFlags { refreshUi() } compiles unchanged, so it won't show up as an error. Check whether it should read errorsLoading. The callback has always also run after a failed load.
errorsLoading depends on why the load ended:
false. PostHog answers that the project is over its feature flags quota. The values are the cached flags.true. No request was made, such as when the device is offline or the distinct ID is blank. It's alsotruewhen the SDK is disabled or isn't set up, with no values in that last case.
The reloadFeatureFlags() callback still runs on a background thread, or right away on the calling thread when no load is attempted. Switch to the main thread before you touch UI.
Add the options argument
capture takes a new options argument. screen, identify, setPersonProperties, alias, group, and captureException take the same argument, as their last parameter (see Move to event options).
- Kotlin callers. Callers that use named or positional arguments for the existing parameters keep compiling.
- Java callers. Pass the new trailing
optionsargument, ornull. PostHogInterfaceimplementations. Add the parameter.identifyonPostHogCoreInterface.identify(distinctId, userProperties, userPropertiesSetOnce)moved fromPostHogCoreInterfacetoPostHogStatelessInterface. Call it throughPostHogInterfaceorPostHogStatelessInterface.
Update interface implementations
PostHogInterface lost getFeatureFlagPayload(), gained the abstract onFeatureFlags() and setAppLanguage(), and changed the callback type of reloadFeatureFlags().
Implementations also add the options parameter and captureAi() (see Add the options argument and Send AI events with captureAi).
Classes that implement it, such as hand-written fakes for tests, don't compile until you update them:
PostHogFeatureFlagsSubscription and PostHogFeatureFlagsLoaded have constructors marked @PostHogInternal, which aren't intended for app code, so create them with a mocking library.
Drop internal APIs
These helpers were public only by accident and were marked @PostHogInternal. They're no longer visible outside the SDK and have no replacement. Apps that don't use @PostHogInternal APIs aren't affected.
| No longer visible | Package |
|---|---|
CustomHeadersInterceptor | com.posthog.internal |
PostHogPrintLogger | com.posthog.internal |
PropertyGroupDeserializer | com.posthog.internal |
PropertyValueDeserializer | com.posthog.internal |
personPropertiesContext() | com.posthog.internal |
PostHogPreferences.PUSH_SUBSCRIPTION_REJECTED | com.posthog.internal |
ThrowableCoercer.fromThrowableToPostHogProperties() | com.posthog.internal.errortracking |
RRDocumentNode | com.posthog.internal.replay |
RRDomContentLoadedEvent | com.posthog.internal.replay |
RRLoadedEvent | com.posthog.internal.replay |
RRStyle | com.posthog.internal.replay |
findBestTranslationMatch() | com.posthog.internal.surveys |
Bitmap.isValid() | com.posthog.android.internal |
Bitmap.webpBase64() | com.posthog.android.internal |
LogLine | com.posthog.android.replay.internal |
LogcatParser | com.posthog.android.replay.internal |
In com.posthog.internal.replay, RRWireframe keeps only id, x, y, width, height, type, and base64.
If you call PostHogRemoteConfig.loadFeatureFlags() or loadRemoteConfig(), their callback parameters changed too. The internal callback is (errorsLoading: Boolean) -> Unit, and the other is a PostHogFeatureFlagsCallback.
Check flag events
When a flag is missing, $feature_flag_called leaves out $feature_flag_response.
3.x.x sent "" from getFeatureFlag() and false from isFeatureEnabled(), or your default value when you passed one. In 4.x.x an empty string means a flag with an empty variant, so a missing flag no longer reports one.
Insights, cohorts, and actions that filter on $feature_flag_response = "" or false to find missing flags stop matching new events without any error. Use an is not set filter on $feature_flag_response instead.
Events already stored keep their old values.
Check locale properties
In 4.x.x, $locale means the first language in the device settings, as a full language tag such as de-CH or zh-Hant-TW. It's left out when the device reports no language.
In 3.x.x it came from Locale.getDefault(). That could be a secondary language, a per-app language, or a value your app set with Locale.setDefault(), and it dropped the script (zh-TW).
On older Android versions, 3.x.x also sent the legacy codes iw, in, and ji, so Hebrew, Indonesian, and Yiddish values change, such as in-ID to id-ID. Update filters that match those.
Other values mostly stay the same, so otherwise only check filters if your users change these settings.
The new $app_language property is the language your app shows. Android has no API that reports it exactly, so what you get depends on the version:
| Android | $app_language |
|---|---|
13+ with android:localeConfig declared | The per-app language or the first device language |
13+ without localeConfig | The per-app language, if one is set |
| 6 to 12 | Not sent |
You can declare android:localeConfig by hand or with AGP generateLocaleConfig. With it, the value is the per-app language or, without one, the first device language, as you declare it.
If you don't declare that language, the value is your android:defaultLocale (Android 15+) or your language if you only declare one.
It's not sent if several of your declared languages could match, such as pt and pt-PT for a pt-MZ device, or if nothing matches and you declare several languages without a default.
On Android 13+ without localeConfig, it's not sent when no per-app language is set.
The SDK reads both languages in the background when an event is captured and uses them from the next event on. The first event after a language change carries the previous value.
A change to only the runtime override (LocaleManager.setOverrideLocaleConfig) isn't picked up until the device or per-app language changes. Call PostHog.setAppLanguage() if your app changes it.
Strings you don't translate fall back per string, so the value is the app's language, not a guarantee for every string.
Call PostHog.setAppLanguage("de") at startup and whenever the language changes to send it on every version, or if you translate some other way, such as with an in-app language setting. It's kept in memory only.
Check session replay
posthog-android 4.x.x removes wireframe session replay. Replay always records masked screenshots, which is what screenshot = true already did. Remove the screenshot option:
Apps that relied on the default now upload screenshots:
- Masking. Masking still covers text inputs, images, Compose semantics,
ph-no-captureviews, andModifier.postHogMask().WebViews are masked whole whilemaskAllTextInputsormaskAllImagesis on. - Unrecognized content. Custom-drawn views and other content the SDK doesn't recognize, such as maps or video, can now appear in recordings. Mask them, or turn replay off with
sessionReplay = false. - Jetpack Compose screens. Wireframe captured them as empty boxes. 4.x.x records them. That can count against your replay quota and may need a consent or privacy disclosure update.
- Frame cost. Each frame uses more bandwidth and CPU than a wireframe.
Compose masking also changed, including for apps that already set screenshot = true:
- Mask scope.
Modifier.postHogMask()andModifier.postHogUnmask()apply only to the element and its children, not to siblings merged into the same clickable row. - Overflowing text. Text that draws past its layout box is masked in full.
- Cleared semantics. Nodes that use
Modifier.clearAndSetSemanticsare masked while text or image masking is on. UseModifier.postHogUnmask()to show them. - Selectable text. While text masking is on, a frame is dropped when a
TextwithModifier.clearAndSetSemanticsis inside aSelectionContainer. The SDK can't measure that text to mask it, so it records no frame instead of an unmasked one.
A dialog's dim, and a dialog masked whole on Android 8.1 and lower, are sent as screenshot images instead of styled wireframe shapes.
The $sdk_debug_replay_capture_mode property is always screenshot.
Check deep links
The Deep Link Opened event leaves out query parameters whose name starts with $, such as $process_person_profile, so a link can't set PostHog's own properties.
Other parameters and the url property are sent as in 3.x.x.
Check surveys
surveys defaults to true, as in the iOS, Flutter, React Native and web SDKs. In 3.x.x it defaulted to false.
Surveys still display only when your app depends on posthog-android-surveys-compose or sets surveysConfig.surveysDelegate. Without either, nothing changes.
If you have one of them but don't want surveys to show, turn them off:
If you already set surveys = true, you can remove the line.
Check dropped events
Capture v1 checks each event on its own and drops only the invalid ones, so the rest of the batch is delivered. In 3.x.x, an empty event name or distinct ID made legacy capture reject the whole batch it was in.
- Empty names. The SDK drops an event whose name is empty before sending it, for example
capture("")or onebeforeSendrenames to"". Withdebugon, it logs this once. - Empty distinct IDs. PostHog drops an event with an empty or whitespace-only distinct ID, for example one
beforeSendsets to"". - Long names. PostHog drops an event whose name is over 200 UTF-8 bytes. Legacy capture had no limit on event name length.
- Long distinct IDs. PostHog drops an event whose distinct ID is over 200 UTF-8 bytes (see Shorten long IDs).
- Empty IDs in
identify().identify()with an empty or whitespace-only distinct ID is still ignored, as in 3.x.x. - Option values. The SDK sends option values as given. PostHog reads common forms of a value, such as
"false"or0for a boolean, and drops an event whose option value it can't read.
The SDK checks only the event name before sending. For the other checks, PostHog drops the event, and the SDK removes it from the queue.
There's no error callback, as in 3.x.x. The SDK reports dropped and failed events only in its debug log (see Update log checks).
The SDK sends these events and changes the value:
NaNand infinite numbers. ANaNor infinite number in the properties is dropped from the event, and the event is sent without it.- Map keys. A map key in the properties that isn't a string is converted to one when it's a number, a boolean, or
null. Any other key is dropped with its value, and the rest of the event is sent. Withdebugon, the SDK logs the key's type. In 3.x.x, a nested map with a non-string key lost the whole event. nullelements. Anullelement in a list or array in the properties is sent as JSONnullat its position. So is an element that can't be serialized, such asNaN. In 3.x.x, both were removed, which moved the later elements to lower indexes. A property or map entry whose value isnullis still left out.- Empty
distinctIdarguments. An empty or whitespace-onlydistinctIdargument tocaptureuses the current distinct ID, likenull. In 3.x.x, the event was dropped.
Update log checks
Update any log-based checks that match the 3.x.x text.
- Batch results. With
debugon, the SDK logs one line per batch. The line says how many events PostHog dropped, how many duplicate copies it dropped, and how many it asked to retry. It has the reasons PostHog gave, never the event names or properties. - Queued events. The SDK no longer logs a line for each queued event.
- Capture requests. Debug logs for capture requests name the event count and the response status. They no longer print the request and response bodies.
- Hook errors. When a
beforeSendhook throws, the debug log names the event and the exception type, not the exception message. The message can hold the data the hook was removing. In 3.x.x it printed the exception. - Values that can't be serialized. When a property value can't be serialized, the debug log names the key and the value's type, not the value. In 3.x.x it printed the value.
Check property precedence
An event's properties are merged in this order, and later values win:
- Properties the SDK sets itself, such as
$os_name,$app_version,$screen_name,$is_identified,$session_id, and the session replay debug properties ($recording_status,$sdk_debug_*). - Registered super properties (
register). - The properties you pass to
captureor another event-sending method.userProperties,userPropertiesSetOnce, andgroupsare placed as$set,$set_once, and$groupshere. When you also pass that key in properties, the arguments win key by key. A$groupsmap in properties adds to the groups set withgroup()instead of replacing them. beforeSend.
These changes follow from this order:
- SDK values. In 3.x.x, the SDK's own values won over super properties.
$is_identified,$process_person_profile, and the session replay debug properties also won over the properties you pass. In 4.x.x a value you register or pass wins. For example,register("\$os_name", "custom")sends every event with that value. - Session IDs. A registered
$session_idoverrides the SDK's session ID, which can detach events from their session replay. - Blank values. A caller
$screen_nameor$session_idstill replaces the SDK's value even when it's blank, as in 3.x.x, so a blank$session_idis sent as an emptysession_id. - Merged maps. In 3.x.x, a
$set,$set_once, or$groupsmap in properties replaced the per-call values and the groups set withgroup(). A$setor$set_onceyou pass, oruserProperties, still replaces a registered one whole.
$lib and $lib_version name the library that produced the event. The SDK fills them last, as a pair, only where nothing above named the library:
| You set | The SDK sends |
|---|---|
Neither, or only $lib_version | Its own $lib and $lib_version |
$lib as the SDK's own name, without a version | Your $lib, and it adds its version |
$lib as another library's name | Both as they are |
When $lib names another library, the SDK never adds its own version, so set both keys together.
In 3.x.x, a registered $lib or $lib_version was replaced by the SDK's, and a $lib you passed was sent with the SDK's $lib_version.
Check session IDs
Capture v1 sends $session_id and $window_id as top-level session_id and window_id fields, not as properties. The SDK moves them out of properties for you, by the value's type:
- A string. The SDK sends it unchanged, including an empty string.
null. It counts as unset, and the SDK removes it without a log.- Any other value. The SDK removes it and doesn't send it. With
debugon, the SDK logs the key and the value's JSON type, never the value.
In PostHog, the events still have $session_id and $window_id, so insights, filters, and session replay work as before.
Review beforeSend hooks
Review your beforeSend hooks for the new event shape. Capture v1 reads processing settings from an options object sent next to properties, and beforeSend can read and change PostHogEvent.options.
- Person processing. In 3.x.x, the SDK marked person processing with the
$process_person_profileproperty. In 4.x.x, it's theprocess_person_profileoption, and the property isn't set. To change person processing inbeforeSend, editevent.options. - Properties a hook adds. A
$process_person_profileproperty the hook adds only fills an option that is still unset. It doesn't override thefalsethe SDK set for an anonymous event. - New option maps. A hook that assigns a new map to
event.optionswithout keeping that key loses thefalsethe SDK set. That turns person processing on for anonymous users, overridingpersonProfiles. Editingevent.optionsin place keeps it. - Copies.
beforeSendgets its own copy of the event's nested maps, lists, and arrays, inpropertiesandoptions. Changes a hook makes no longer reach the objects you passed tocaptureor registered, and identity checks against them (===) no longer match. In 3.x.x, hooks edited the caller's objects. - Returned events.
optionsis a property ofPostHogEvent, not a constructor parameter, so the constructor andcopyare unchanged from 3.x.x. WhenbeforeSendreturns a different event whoseoptionsisnull, such as one made withevent.copy(…)or the constructor, it gets the options of the event the hook was given. To send an event with no options, setoptionsto an empty map. - Event uuids. The event
beforeSendreturns keeps the uuid of the capture it came from. A uuid you set inbeforeSend, for example withcopy(uuid = …), is replaced. A hook that returns an event kept from an earlier call still sends one uuid per capture. - Timing.
beforeSendstill runs when you capture the event, before it's queued, not when the batch is sent.
Check person processing
- The SDK's value. When
personProfilesturns person processing off, the SDK sets theprocess_person_profileoption tofalse. Otherwise it sends neither the option nor the property, since PostHog processes person profiles by default. In 3.x.x, every event carried a$process_person_profileproperty. - One event. To change person processing for one event, pass the
process_person_profileoption or the$process_person_profileproperty. - Every event. A registered
$process_person_profilechanges it for every event. In 3.x.x, the SDK's value replaced a registered$process_person_profile, so a registeredfalsehad no effect. - A registered
false. In 4.x.x it applies, also afteridentifyand withPersonProfiles.ALWAYS. Those events don't change the person profile, and their$setis ignored. They are still linked to the person and billed as identified events. It doesn't apply to identity events (see below). PersonProfiles.NEVER. Aprocess_person_profileoption or$process_person_profileproperty set totrue, passed or registered, turns person processing on for that event. In 3.x.x,NEVERalways won. If you rely onNEVERto keep events personless, make sure neither is set totrue, or remove it inbeforeSend.PersonProfiles.IDENTIFIED_ONLY.identify,alias,group, andsetPersonPropertiesstill turn on person processing for the user's later events, as in 3.x.x.- Duplicate checks. A
$setsent withprocess_person_profile: falsedoesn't update the person, so it no longer suppresses a latersetPersonPropertiesoridentifycall with the same properties as a duplicate.
A registered $process_person_profile, or a process_person_profile option a wrapper SDK registers, doesn't apply to identity events: $identify, $create_alias, $merge_dangerously, $groupidentify, $set, and $set_once.
With person processing off, PostHog drops $identify, $create_alias, $merge_dangerously, and $groupidentify, and keeps $set and $set_once but ignores their person update. So a registered false would stop identify, alias, group, and setPersonProperties from working. A value you pass on the call, or set in beforeSend, still applies.
If you registered false to skip person profiles for anonymous users, remove it. personProfiles = PersonProfiles.IDENTIFIED_ONLY, the default, already does that and still lets identify create the person.
To create no person profiles at all, set personProfiles = PersonProfiles.NEVER instead. The SDK then skips these calls.
Check retries
These apply to analytics and AI event requests, unless a bullet names session replay or logs. Session replay and logs keep their 3.x.x status handling: they still retry 3xx and don't retry 404.
- Statuses retried. The SDK retries network errors and 404, 408, 429, 500, 502, 503, and 504 responses. Other statuses drop the events, including 3xx. 3.x.x also retried 3xx responses, and didn't retry 404.
- Billing limits and quotas. A 402 (billing limit) drops the whole batch. A product quota, such as for exceptions or AI events, drops only those events inside a 200 response.
- Partial retries. When the response asks to retry only some events, the SDK keeps those events queued and removes the rest.
- Resent requests. A failed request is resent with the same events, request ID, and
created_at, and the next attempt number, before newer events are sent. The request ID and attempt number reset after an app restart. OkHttp doesn't retry capture requests on its own. - The
Retry-Aftercap. ARetry-Afterheader sets the minimum wait before the next send, up to 30 seconds. This also applies to session replay and logs. In 3.x.x there was no cap. Retry-Afterformats.Retry-Aftercan be a number of seconds or an HTTP date. 3.x.x read only a number of seconds.- Backoff. After a failed send, the wait before the next one doubles from 1 second up to 30 seconds, with up to 25% random jitter at millisecond precision. In 3.x.x it doubled without jitter and a
Retry-Afterreplaced it. This applies to events, session replay, and logs. - Retry limit. Event, session replay, and log retries have no limit, as in 3.x.x. Queued records stay until they're delivered or a full queue evicts them (
maxQueueSize, orlogs.maxBufferSizefor logs). maxRetries.maxRetriesis renamed topushNotificationSubscriptionMaxRetries, with no deprecated alias. It only limits push-notification subscription retries.- Request size. A request carries at most
maxBatchSizeevents and about 5 MiB. The SDK sends as soon as about 5 MiB of events is queued, even beforeflushAtis reached. In 3.x.x, batches were limited by event count only. - Event size. There's no size limit for one analytics event in the SDK, as in 3.x.x. An event larger than about 5 MiB is sent in a request of its own.
- 413 responses. A 413 still halves the batch until it fits, as in 3.x.x. An event that gets a 413 on its own is dropped.
Plan your rollback
If you ship 4.x.x and then go back to 3.x.x, 3.x.x sends the events still queued on the device. 3.x.x doesn't read capture options:
- Personless events. Events that 4.x.x marked as personless (
process_person_profile: false) are processed as person events. - Other options. Options such as
cookieless_modepassed throughoptionsare lost. - AI events. AI events queued by 4.x.x in their own queue aren't sent while the app runs 3.x.x. If you upgrade to 4.x.x again, 4.x.x sends them.
Go back to core posthog 6.x.x and posthog-server 2.25.x or older at the same time. While core 7.x.x is in the build, Gradle keeps posthog-android on 4.x.x.
Follow ups
Move to event options
Capture v1 reads processing settings from an options object sent next to properties. capture, screen, identify, setPersonProperties, alias, group, and captureException take an options argument. For identify, the options apply to the $identify or $set event the call sends.
Pass an option in options instead of its $-prefixed property:
The legacy option properties still work. They're the $-prefixed properties legacy capture reads as settings. When the event is sent, the SDK removes each one from properties and uses it for its option:
| Legacy option property | Option |
|---|---|
$process_person_profile | process_person_profile |
$cookieless_mode | cookieless_mode |
$ignore_sent_at | disable_skew_correction |
$product_tour_id | product_tour_id |
An option you pass to any of these methods or set in beforeSend wins over its legacy property. An option set to null counts as unset, so the legacy property fills it.
- Other keys. Other option keys are sent unchanged, and PostHog ignores keys it doesn't know.
- Every event. There are no global or context options. To set an option on every event, register its legacy property, for example
register("\$cookieless_mode", true). - GeoIP and migrations. To turn off GeoIP lookup, set
disableGeoIp. It sends$geoip_disableas an event property, not an option. There's no setting forhistorical_migrationon events, as in 3.x.x. - Queued events. Events still queued on disk by 3.x.x are sent to capture v1 after the update, with their legacy properties moved to options.
Send AI events with captureAi
captureAi sends AI events, such as $ai_generation, to PostHog's AI endpoint (/i/v1/ai/events) instead of the analytics endpoint. capture never sends events to the AI endpoint, even ones named $ai_*.
$ai_* events you keep sending with capture still reach PostHog through the analytics endpoint, as in 3.x.x. Moving them to captureAi gets you the AI endpoint's much larger event size limit, and a queue of their own, so large AI events don't hold up your other events.
captureAi takes the same arguments as capture, and the events go through the same beforeSend hooks:
- Return value.
captureAireturns the event's uuid, ornullwhen the event isn't queued. That happens when the SDK is disabled or opted out, the event name is empty,beforeSenddropped it, or it's over the size limit. - Queue limits. Once 100 AI events (
captureAiMaxQueueSize) or 50 MiB are queued, the oldest are dropped. The count includes events still waiting to be written to disk during a slow upload. - Event size. An AI event's properties can be up to 8 MiB. The SDK drops a serialized event over 8 MiB + 64 KiB, measured before
encryption. Withdebugon, it logs the event name and the limit, never the content. - A lower size limit. Set
captureAiMaxEventBytesto lower that limit. A larger value uses 8 MiB + 64 KiB, and withdebugon the SDK logs that it did. - Event names. PostHog drops an event sent with
captureAiwhose name doesn't start with$ai_. - Timeouts. AI requests time out after 60 seconds without network activity, or
captureAiTimeout. Other requests keep OkHttp's 10-second defaults. - Disk queue. On Android, AI events are queued on disk separately from other events (
posthog-disk-ai-queuein the app's cache directory). Up to 100 events (captureAiMaxQueueSize) and 50 MiB are kept, and the oldest are dropped first.maxQueueSizedoesn't apply. - Flushing.
flush()andclose()also send the AI queue. On Android, AI events left on disk are sent at the next launch. - Compression. AI requests are gzipped unless you set
captureAiCompressiontoPostHogCompression.NONE.compressiondoesn't apply. - Batching. AI events use
flushAt,maxBatchSize, andflushIntervalSeconds, like other events. A request carries up to about 5 MiB, as for analytics events (see Check retries). - Content. The SDK sends AI events unchanged. It doesn't redact or truncate prompts, outputs, or media, so use
beforeSendto remove anything you don't want to send.





