Repository navigation
feat(react-native): add push notification support - #4415
Conversation
|
Size Change: +11.7 kB (+0.06%) Total Size: 19 MB 📦 View Changed
ℹ️ View Unchanged
|
b0a7a12 to
a1ff6ed
Compare
2f3c16b to
8ac2292
Compare
🦔 ReviewHog reviewed this pull requestFound 0 must fix, 4 should fix, 3 consider. Published 7 findings (view the review). |
|
ReviewHog Alpha 🦔 If you find any issues helpful - please reply "valid", "invalid", etc., for evaluation purposes 🙏 |
There was a problem hiding this comment.
ReviewHog Report
Feature
Issues: 5 issues
Files (7)
packages/react-native/src/posthog-rn.tspackages/react-native/src/types.tspackages/react-native/src/optional/OptionalPlugin.tspackages/react-native-plugin/src/index.tsxpackages/react-native-plugin/package.jsonpackages/react-native/references/posthog-react-native-references-latest.json.changeset/soft-snakes-greet.md
What were the main changes
- Adds registerPushNotificationToken, unregisterPushNotificationToken and capturePushNotificationOpened to the PostHog class via a shared _callPushPlugin guard (disabled/opt-out/platform/plugin-missing checks)
- Adds capturePushNotificationSubscriptions, capturePushNotificationOpened and pushIdentityProvider PostHogOptions, all forwarded to native setup config
- reset() now calls the native plugin's reset() to unregister the old identity's push subscription and re-register under the new anonymous id; optOut() unregisters any already-registered token
- Native plugin now initializes when push alone is enabled (previously only session replay or native error tracking triggered it), with a push-only path that skips native feature-flag preload
- @posthog/react-native-plugin JS wrapper (index.tsx) gains registerPushNotificationToken/unregisterPushNotificationToken/capturePushNotificationOpened/reset plus setPushIdentityProvider, which bridges native's identity-token request event back through providePushIdentityToken
- Adds PostHogPushIdentityProvider type and extends OptionalReactNativePlugin's shape with the new push/reset methods
- Changeset documents the new push support for posthog-react-native and @posthog/react-native-plugin; API reference JSON regenerated for the new public methods/options
Feature
Issues: 2 issues
Files (2)
packages/react-native-plugin/android/build.gradlepackages/react-native-plugin/android/src/main/java/com/posthogreactnativeplugin/PosthogReactNativePluginModule.kt
What were the main changes
- Adds Kotlin implementations of registerPushNotificationToken, unregisterPushNotificationToken, capturePushNotificationOpened and reset that forward one-to-one to the native posthog-android SDK
- Adds providePushIdentityToken plus a static request map/watchdog that bridges the native pushIdentityProvider callback to JS via RCTDeviceEventEmitter, keyed by request id with a 15s TTL cleanup
- Forwards optOut, preloadFeatureFlags and the new push config (capturePushNotificationSubscriptions/capturePushNotificationOpened/pushIdentityProviderEnabled) into PostHogAndroidConfig, only installing the bridging identity provider when explicitly requested
- Resolves a Firebase project id reflectively as a fallback appId for token registration
- Bumps posthog-android dependency from 3.54.0 to 3.58.0
…ent after the wait
…load' into feat/push-notifications
posthog-js Compliance ReportDate: 2026-08-05 16:00:20 UTC ✅ All Tests Passed!26/26 tests passed Capture Tests✅ 26/26 tests passed View Details
|
…ation is persisted
|
posthog-node Compliance ReportDate: 2026-08-05 15:53:30 UTC ✅ All Tests Passed!111/111 tests passed Capture_V1 Tests✅ 94/94 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
|
@marandaneto Thanx for all the review. Addressed almost everything here. Still pending decision on this and CI is red cause PostHog/posthog-ios#745 did not work as expected |
marandaneto
left a comment
There was a problem hiding this comment.
left a few comments worth addressing/answering otherwise LGTM
lets try this PostHog/posthog-ios#747 |
Should work, verified locally at least |
… module verification fix
# Conflicts: # packages/react-native/references/posthog-react-native-references-latest.json
* feat(react-native-plugin): add native push notification bridge * feat(react-native): add push notification support * fix(react-native): stop setting remoteConfig, a no-op in both native SDKs * chore: clarify push notification changeset entry * fix(react-native): close push opt-out and init-ordering gaps * fix(react-native-plugin): retry Firebase project id lookup after a failed resolve * chore: note push unregistration on opt-out in changeset * fix(react-native-plugin): drop the react-native jest preset from unit tests * chore(react-native): regenerate public API references for push notifications * chore(ci): build the react-native-plugin CocoaPods examples on macos-26 * fix(replay): skip unloading never-visible held recordings * fix(replay): clean up preload visibility tracking * fix(replay): preserve unload behavior across version skew * fix(replay): stop recording on browser shutdown * ci: parse compatibility results without jq * fix(react-native): queue native reset() behind init and re-check consent after the wait * feat(react-native): propagate runtime opt-out and opt-in consent to the native SDK * docs(react-native-plugin): disclose the Android reset identity race like the iOS one * chore(react-native): regenerate public API references for the setOptOut bridge * fix(react-native): serialize native identity, consent and push calls through one queue * docs(react-native): trim the push notification option and method docs * chore(react-native): regenerate public API references for the trimmed push docs * fix(react-native): correct push gating, consent propagation and native init races * chore: drop replay changeset * Revert "ci: parse compatibility results without jq" This reverts commit 174d0d3. * Revert "fix(replay): stop recording on browser shutdown" This reverts commit 853442b. * Revert "fix(replay): preserve unload behavior across version skew" This reverts commit ca72df1. * Revert "fix(replay): clean up preload visibility tracking" This reverts commit 4972165. * Revert "fix(replay): skip unloading never-visible held recordings" This reverts commit ead8832. * Revert "chore(ci): build the react-native-plugin CocoaPods examples on macos-26" This reverts commit 8ac2292. * fix(react-native-plugin): require posthog-ios 3.69.1 for the CocoaPods static-lib archive fix * fix(react-native): return the native identify promise so the queue awaits settlement * fix(react-native): require @posthog/react-native-plugin 2.3.0 for the push bridge * fix(react-native): boot native for push cleanup when a manual registration is persisted * test(react-native): dedupe the relaunch storage setup in push specs * fix(react-native-plugin): capture cold-start push opens from the Android launch intent * docs(react-native): disclose the push opt-out removal limitation in the changeset * fix(react-native-plugin): restore the react-native jest preset * fix(react-native-plugin): drop the react-native jest preset, its flow-typed setup breaks jest on CI * chore(react-native): move the plugin release to its own PR * fix(react-native-plugin): require posthog-ios 3.69.2 for the Xcode 16 module verification fix * chore: restore files reformatted by the merge commit --------- Co-authored-by: Manoel Aranda Neto <marandaneto@gmail.com>
Problem
PostHog Workflows can send push notifications to iOS and Android apps but not to React Native ones. The native SDKs already do all the hard parts (subscription state, retry and backoff, dedup, persistence, the HTTP calls) and
@posthog/react-native-pluginalready wraps both of them. Push was just never bridged, so a React Native app had no way to register a device token or report an opened notification.Changes
A thin wrapper over the native SDKs. No subscription state or delivery logic moves into JS.
In
@posthog/react-native-plugin(Kotlin, Swift, ObjC++):registerPushNotificationToken(deviceToken, appId),unregisterPushNotificationToken()andcapturePushNotificationOpened(properties), each a one-line forward to the native SDK.reset(distinctId, anonymousId), so a logout unbinds the token from the old identity.setPushIdentityProvider(provider). A callback can't cross the bridge, so native asks for a token over an event and JS replies through a bridge method keyed by request id. Native already runs a 10s watchdog and sends the request unauthenticated if nothing comes back, so there's no JS-side timeout to get wrong.In
posthog-react-native:PostHog, plus thepushIdentityProvideroption.reset()propagates to native, which unregisters the logged-out user's subscription and re-registers under the new anonymous id.optOut()unregisters a subscription that was already registered. Without that last one a token registered before consent withdrawal stays live, because the native handler keeps its own persisted record and retry loop and never sees the JS opt-out.capturePushNotificationSubscriptionsandcapturePushNotificationOpenedboth default totrue, matching the native SDKs. Setting either tofalseopts out. That default is deliberate, but it does mean an app that already has the plugin installed for session replay starts registering device tokens once it upgrades. The alternative was defaulting both tofalsein React Native only, which trades the silent upgrade for a documented divergence from the native SDKs, and I'd rather keep parity. Worth a second opinion though.One known gap I've left for a follow-up: on iOS,
reset()binds the push subscription to the wrong identity.PostHogSDK.shared.reset()re-registers push synchronously before it returns (PostHogPushSubscriptionHandler.swift:399snapshots the distinct id at call time), but the plugin can only write the JSanonymousIdafterreset()has returned, so the subscription lands under the anonymous id native minted for itself. Fixing it needs a way to seed the new anonymous id intoposthog-ios'sreset(), so it belongs in a PR against that repo rather than this one.Release info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
DRI: @ioannisj
Autonomy: Human-driven (agent-assisted)