Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rn-android-cold-start-push-consent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@posthog/react-native-plugin': patch
---

Android: a notification tap that launched the app is no longer captured as `$push_notification_opened` while the JS client is opted out, even if an earlier launch had opted the native SDK in.
5 changes: 5 additions & 0 deletions .changeset/rn-android-main-activity-new-intent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'posthog-react-native': minor
---

Fix `$push_notification_opened` not being captured on Android when the app's process was killed but its task stayed in recents (opt out with `{ patchMainActivityNewIntent: false }`).
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class PosthogReactNativePluginModule(

setIdentify(config.cachePreferences, distinctId, anonymousId)

captureColdStartPushOpenIfNeeded(config)
captureColdStartPushOpenIfNeeded(config, jsOptedOut = theOptOut)
} catch (e: Throwable) {
logError(method, e)
} finally {
Expand Down Expand Up @@ -487,7 +487,15 @@ class PosthogReactNativePluginModule(
// cold-start tray tap it exists for is the one creation it can never observe here. Read
// the launch intent directly, then strip the marker so the integration (or a re-run)
// can't capture the same tap again from this intent object.
private fun captureColdStartPushOpenIfNeeded(config: PostHogAndroidConfig) {
//
// jsOptedOut is the consent JS passed into this setup(). The native SDK lets the opt-out it
// persisted itself win over that value, so after an earlier launch opted in, config.optOut no
// longer says what JS said and native would capture. A tap JS considers denied is consumed
// here without being captured, so a later opt-in cannot resurrect it either.
private fun captureColdStartPushOpenIfNeeded(
config: PostHogAndroidConfig,
jsOptedOut: Boolean,
) {
if (!config.capturePushNotificationOpened) {
return
}
Expand All @@ -499,6 +507,10 @@ class PosthogReactNativePluginModule(
}
try {
intent.getStringExtra(GOOGLE_MESSAGE_ID) ?: return
if (jsOptedOut) {
intent.removeExtra(GOOGLE_MESSAGE_ID)
return
}
// Unmarshalling extras throws BadParcelableException on a Parcelable class this
// classloader lacks; read before stripping the marker so a failed read leaves the
// intent as the native integration expects it.
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"expo-file-system": ">= 13.0.0",
"expo-localization": ">= 11.0.0",
"expo-updates": ">= 0.25.0",
"@posthog/react-native-plugin": ">= 2.4.3",
"@posthog/react-native-plugin": ">= 2.9.3",
"posthog-react-native-session-replay": ">= 1.6.0",
"react-native-device-info": ">= 10.0.0",
"react-native-localize": ">= 3.0.0",
Expand Down
Loading