@posthog/react-native-plugin 2.2.3 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,9 +16,9 @@ private func hedgeLog(_ message: String) {
16
16
  }
17
17
  #endif
18
18
 
19
- // Deduplication works on Android (both architectures), iOS (old architecture only), and macOS.
20
- // On the iOS new architecture, fatal JS exception events surface as a generic SIGABRT
21
- // crash event with no JS-error text in any field, so they currently cannot be filtered.
19
+ /// Deduplication works on Android (both architectures), iOS (old architecture only), and macOS.
20
+ /// On the iOS new architecture, fatal JS exception events surface as a generic SIGABRT
21
+ /// crash event with no JS-error text in any field, so they currently cannot be filtered.
22
22
  private let fatalJsErrorMarkers = ["Unhandled JS Exception", "ExceptionsManager.reportException", "facebook::jsi::JSError"]
23
23
 
24
24
  private func containsFatalJsErrorMarker(_ text: String?) -> Bool {
@@ -46,10 +46,40 @@ private func isReactNativeFatalJsError(_ event: PostHogEvent) -> Bool {
46
46
  }
47
47
  }
48
48
 
49
+ // A nil identity token sends the request unauthenticated, which a project requiring
50
+ // identity verification rejects server-side. Log the reason so that failure is greppable
51
+ // and distinct from a host that deliberately returned nil.
52
+ private func declinePushIdentity(_ completion: (String?) -> Void, _ reason: String) {
53
+ hedgeLog("Push subscription will be sent unauthenticated: \(reason)")
54
+ completion(nil)
55
+ }
56
+
49
57
  @objc(PosthogReactNativePlugin)
50
- class PosthogReactNativePlugin: NSObject {
58
+ class PosthogReactNativePlugin: RCTEventEmitter {
51
59
  private var config: PostHogConfig?
52
60
 
61
+ private static let pushIdentityEvent = "PostHogPushIdentityRequest"
62
+
63
+ // This module dies on every bridge reload, so the provider closure resolves the live
64
+ // module through this static weak reference at call time, not a captured setup-time one.
65
+ private static weak var pushInstance: PosthogReactNativePlugin?
66
+
67
+ // Main-thread confined, like the rest of the identity-request bookkeeping below.
68
+ private var hasPushListeners = false
69
+ private var pushIdentityCompletions: [String: (String?) -> Void] = [:]
70
+
71
+ override func supportedEvents() -> [String]! {
72
+ [PosthogReactNativePlugin.pushIdentityEvent]
73
+ }
74
+
75
+ override func startObserving() {
76
+ DispatchQueue.main.async { self.hasPushListeners = true }
77
+ }
78
+
79
+ override func stopObserving() {
80
+ DispatchQueue.main.async { self.hasPushListeners = false }
81
+ }
82
+
53
83
  @objc(setup:withSdkOptions:withPluginConfig:withResolver:withRejecter:)
54
84
  func setup(
55
85
  sessionId: String, sdkOptions: [String: Any], pluginConfig: [String: Any],
@@ -68,6 +98,7 @@ class PosthogReactNativePlugin: NSObject {
68
98
  decideReplayConfig: sessionReplayConfig["decideReplayConfig"] as? [String: Any] ?? [:],
69
99
  nativeErrorTrackingAutocapture: errorTrackingConfig["nativeAutocapture"] as? Bool ?? false,
70
100
  exceptionStepsConfig: exceptionStepsConfig,
101
+ pushConfig: pluginConfig["push"] as? [String: Any] ?? [:],
71
102
  resolve: resolve
72
103
  )
73
104
  }
@@ -87,6 +118,7 @@ class PosthogReactNativePlugin: NSObject {
87
118
  decideReplayConfig: decideReplayConfig,
88
119
  nativeErrorTrackingAutocapture: false,
89
120
  exceptionStepsConfig: [:],
121
+ pushConfig: [:],
90
122
  resolve: resolve
91
123
  )
92
124
  }
@@ -100,6 +132,7 @@ class PosthogReactNativePlugin: NSObject {
100
132
  decideReplayConfig: [String: Any],
101
133
  nativeErrorTrackingAutocapture: Bool,
102
134
  exceptionStepsConfig: [String: Any],
135
+ pushConfig: [String: Any],
103
136
  resolve: RCTPromiseResolveBlock
104
137
  ) {
105
138
  if sessionId.isEmpty {
@@ -193,6 +226,11 @@ class PosthogReactNativePlugin: NSObject {
193
226
  let flushAt = sdkOptions["flushAt"] as? Int ?? 20
194
227
  config.flushAt = flushAt
195
228
 
229
+ config.optOut = sdkOptions["optOut"] as? Bool ?? false
230
+ // JS owns flags; it tells us when the native preload would be a duplicate. posthog-ios
231
+ // has no remoteConfig switch to mirror — it deprecated the option and always loads.
232
+ config.preloadFeatureFlags = sdkOptions["preloadFeatureFlags"] as? Bool ?? true
233
+
196
234
  // Forward custom headers (e.g. Authorization for a reverse proxy) so the native SDK
197
235
  // attaches them to the requests it sends directly (session replay, crash uploads).
198
236
  // Keep only string values so a stray non-string doesn't drop every header (matches Android).
@@ -205,6 +243,40 @@ class PosthogReactNativePlugin: NSObject {
205
243
  postHogVersion = sdkVersion
206
244
  }
207
245
 
246
+ // Only set when present: the legacy start() path predates push, and there the
247
+ // native defaults (both true) must win, matching posthog-ios on its own.
248
+ if let capturePushSubscriptions = pushConfig["capturePushNotificationSubscriptions"] as? Bool {
249
+ config.capturePushNotificationSubscriptions = capturePushSubscriptions
250
+ }
251
+ if let capturePushOpened = pushConfig["capturePushNotificationOpened"] as? Bool {
252
+ config.capturePushNotificationOpened = capturePushOpened
253
+ }
254
+
255
+ // Installed only when JS asked for it: an uninvited bridging provider would change
256
+ // how the native SDK handles a 401 on the subscription call.
257
+ if pushConfig["pushIdentityProviderEnabled"] as? Bool == true {
258
+ PosthogReactNativePlugin.pushInstance = self
259
+ config.pushIdentityProvider = { distinctId, appId, completion in
260
+ DispatchQueue.main.async {
261
+ guard let instance = PosthogReactNativePlugin.pushInstance, instance.hasPushListeners else {
262
+ declinePushIdentity(completion, "no JS listener attached")
263
+ return
264
+ }
265
+ let requestId = UUID().uuidString
266
+ instance.pushIdentityCompletions[requestId] = completion
267
+ instance.sendEvent(
268
+ withName: PosthogReactNativePlugin.pushIdentityEvent,
269
+ body: ["requestId": requestId, "distinctId": distinctId, "appId": appId]
270
+ )
271
+ // The native SDK's own 10s mint watchdog handles the fallback; this only
272
+ // drops the entry so a late JS reply is ignored and the closure doesn't leak.
273
+ DispatchQueue.main.asyncAfter(deadline: .now() + 15) { [weak instance] in
274
+ instance?.pushIdentityCompletions.removeValue(forKey: requestId)
275
+ }
276
+ }
277
+ }
278
+ }
279
+
208
280
  PostHogSDK.shared.setup(config)
209
281
 
210
282
  self.config = config
@@ -265,6 +337,23 @@ class PosthogReactNativePlugin: NSObject {
265
337
  resolve(nil)
266
338
  }
267
339
 
340
+ // Calls the native SDK rather than writing storage like identify() does: reset() is what
341
+ // unregisters the logged-out user's push subscription and re-registers under the new identity.
342
+ @objc(reset:withAnonymousId:withResolver:withRejecter:)
343
+ func reset(
344
+ distinctId: String, anonymousId: String, resolve: RCTPromiseResolveBlock,
345
+ reject _: RCTPromiseRejectBlock
346
+ ) {
347
+ PostHogSDK.shared.reset()
348
+ // Native reset() mints its own anonymous id; overwrite it with the JS one so the two SDKs
349
+ // stay on the same identity. Must run after reset(), which needs the pre-reset distinctId
350
+ // to know which subscription to unregister.
351
+ if let storageManager = config?.storageManager {
352
+ setIdentify(storageManager, distinctId: distinctId, anonymousId: anonymousId)
353
+ }
354
+ resolve(nil)
355
+ }
356
+
268
357
  private func setIdentify(
269
358
  _ storageManager: PostHogStorageManager, distinctId: String, anonymousId: String
270
359
  ) {
@@ -276,6 +365,21 @@ class PosthogReactNativePlugin: NSObject {
276
365
  }
277
366
  }
278
367
 
368
+ // Runtime consent changes must reach native: it persists its own opt-out flag and only
369
+ // reads the JS value at setup(), so a refreshed APNs token could otherwise auto-register
370
+ // after the user opted out. optIn() also reinstalls the integrations opt-out removed.
371
+ @objc(setOptOut:withResolver:withRejecter:)
372
+ func setOptOut(
373
+ optOut: Bool, resolve: RCTPromiseResolveBlock, reject _: RCTPromiseRejectBlock
374
+ ) {
375
+ if optOut {
376
+ PostHogSDK.shared.optOut()
377
+ } else {
378
+ PostHogSDK.shared.optIn()
379
+ }
380
+ resolve(nil)
381
+ }
382
+
279
383
  @objc(startRecording:withResolver:withRejecter:)
280
384
  func startRecording(
281
385
  resumeCurrent: Bool, resolve: RCTPromiseResolveBlock, reject _: RCTPromiseRejectBlock
@@ -306,4 +410,64 @@ class PosthogReactNativePlugin: NSObject {
306
410
  PostHogSDK.shared.addExceptionStep(message, properties: properties)
307
411
  resolve(nil)
308
412
  }
413
+
414
+ @objc(registerPushNotificationToken:withAppId:withResolver:withRejecter:)
415
+ func registerPushNotificationToken(
416
+ deviceToken: String, appId: String?, resolve: RCTPromiseResolveBlock,
417
+ reject: RCTPromiseRejectBlock
418
+ ) {
419
+ #if os(iOS)
420
+ // A blank token is dropped silently by the native SDK, so surface it here
421
+ // instead of reporting false success.
422
+ if deviceToken.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
423
+ reject("PosthogReactNativePluginError", "registerPushNotificationToken: deviceToken is blank; token not registered.", nil)
424
+ return
425
+ }
426
+ PostHogSDK.shared.registerPushNotificationToken(deviceToken, appId: appId)
427
+ resolve(nil)
428
+ #else
429
+ // posthog-ios push registration is iOS-only (the backend rejects the macos platform).
430
+ _ = reject
431
+ hedgeLog("registerPushNotificationToken is not supported on macOS; token not registered.")
432
+ resolve(nil)
433
+ #endif
434
+ }
435
+
436
+ @objc(unregisterPushNotificationToken:withRejecter:)
437
+ func unregisterPushNotificationToken(resolve: RCTPromiseResolveBlock, reject _: RCTPromiseRejectBlock) {
438
+ #if os(iOS)
439
+ PostHogSDK.shared.unregisterPushNotificationToken()
440
+ #else
441
+ hedgeLog("unregisterPushNotificationToken is not supported on macOS; nothing to unregister.")
442
+ #endif
443
+ resolve(nil)
444
+ }
445
+
446
+ @objc(capturePushNotificationOpened:withResolver:withRejecter:)
447
+ func capturePushNotificationOpened(
448
+ properties: [String: Any], resolve: RCTPromiseResolveBlock, reject _: RCTPromiseRejectBlock
449
+ ) {
450
+ PostHogSDK.shared.capturePushNotificationOpened(
451
+ title: properties["title"] as? String,
452
+ subtitle: properties["subtitle"] as? String,
453
+ body: properties["body"] as? String,
454
+ payload: properties["payload"] as? [String: Any],
455
+ action: properties["action"] as? String
456
+ )
457
+ resolve(nil)
458
+ }
459
+
460
+ @objc(providePushIdentityToken:withToken:withResolver:withRejecter:)
461
+ func providePushIdentityToken(
462
+ requestId: String, token: String?, resolve: RCTPromiseResolveBlock,
463
+ reject _: RCTPromiseRejectBlock
464
+ ) {
465
+ DispatchQueue.main.async { [weak self] in
466
+ guard let completion = self?.pushIdentityCompletions.removeValue(forKey: requestId) else {
467
+ return
468
+ }
469
+ completion(token)
470
+ }
471
+ resolve(nil)
472
+ }
309
473
  }
@@ -4,15 +4,21 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.addExceptionStep = addExceptionStep;
7
+ exports.capturePushNotificationOpened = capturePushNotificationOpened;
7
8
  exports.default = void 0;
8
9
  exports.endSession = endSession;
9
10
  exports.identify = identify;
10
11
  exports.isEnabled = isEnabled;
12
+ exports.registerPushNotificationToken = registerPushNotificationToken;
13
+ exports.reset = reset;
14
+ exports.setOptOut = setOptOut;
15
+ exports.setPushIdentityProvider = setPushIdentityProvider;
11
16
  exports.setup = setup;
12
17
  exports.start = start;
13
18
  exports.startRecording = startRecording;
14
19
  exports.startSession = startSession;
15
20
  exports.stopRecording = stopRecording;
21
+ exports.unregisterPushNotificationToken = unregisterPushNotificationToken;
16
22
  var _reactNative = require("react-native");
17
23
  const LINKING_ERROR = `The package '@posthog/react-native-plugin' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
18
24
  ios: "- You have run 'pod install'\n",
@@ -41,6 +47,15 @@ function isEnabled() {
41
47
  function identify(distinctId, anonymousId) {
42
48
  return PosthogReactNativePlugin.identify(distinctId, anonymousId);
43
49
  }
50
+
51
+ /**
52
+ * Resets the native SDK's identity on logout. Unlike {@link identify}, this calls the native
53
+ * SDK's own `reset()`, which unregisters the logged-out user's push subscription and
54
+ * re-registers it under the new anonymous id.
55
+ */
56
+ function reset(distinctId, anonymousId) {
57
+ return PosthogReactNativePlugin.reset(distinctId, anonymousId);
58
+ }
44
59
  function startRecording(resumeCurrent) {
45
60
  return PosthogReactNativePlugin.startRecording(resumeCurrent);
46
61
  }
@@ -50,6 +65,63 @@ function stopRecording() {
50
65
  function addExceptionStep(message, properties) {
51
66
  return PosthogReactNativePlugin.addExceptionStep(message, properties ?? {});
52
67
  }
68
+ function registerPushNotificationToken(deviceToken, appId) {
69
+ return PosthogReactNativePlugin.registerPushNotificationToken(deviceToken, appId);
70
+ }
71
+ function unregisterPushNotificationToken() {
72
+ return PosthogReactNativePlugin.unregisterPushNotificationToken();
73
+ }
74
+
75
+ /**
76
+ * Propagates a runtime consent change to the native SDK, which otherwise only reads the JS
77
+ * opt-out flag at setup() and could auto-register a refreshed push token after optOut().
78
+ */
79
+ function setOptOut(optOut) {
80
+ return PosthogReactNativePlugin.setOptOut(optOut);
81
+ }
82
+ function capturePushNotificationOpened(properties) {
83
+ return PosthogReactNativePlugin.capturePushNotificationOpened(properties);
84
+ }
85
+
86
+ /**
87
+ * Mints a signed identity-verification token for a push subscription request.
88
+ * Return null to send the request without an identity token.
89
+ */
90
+
91
+ const PUSH_IDENTITY_EVENT = 'PostHogPushIdentityRequest';
92
+ let pushIdentitySubscription;
93
+
94
+ /**
95
+ * Installs the JS side of the push identity-provider bridge. The native SDK asks for a
96
+ * token via a `PostHogPushIdentityRequest` event; the reply is routed back with
97
+ * `providePushIdentityToken`, keyed by the request id so late replies are ignored.
98
+ *
99
+ * Install before setup() with `push.pushIdentityProviderEnabled` set, so the native
100
+ * config gets its bridging provider at SDK initialization. Any provider failure
101
+ * degrades to a null token — an unauthenticated request — never a stalled mint.
102
+ */
103
+ function setPushIdentityProvider(provider) {
104
+ pushIdentitySubscription?.remove();
105
+ // Via the proxy, not raw NativeModules: an unlinked module would build an emitter over
106
+ // undefined and throw a generic RN error inside the SDK's init try, taking replay down with it.
107
+ const emitter = new _reactNative.NativeEventEmitter(PosthogReactNativePlugin);
108
+ pushIdentitySubscription = emitter.addListener(PUSH_IDENTITY_EVENT, async request => {
109
+ let token = null;
110
+ try {
111
+ const minted = await provider(request.distinctId, request.appId);
112
+ token = typeof minted === 'string' ? minted : null;
113
+ } catch (e) {
114
+ // eslint-disable-next-line no-console
115
+ console.warn(`[PostHog] pushIdentityProvider threw: ${e}. Push subscription will be sent unauthenticated.`);
116
+ }
117
+ try {
118
+ await PosthogReactNativePlugin.providePushIdentityToken(request.requestId, token);
119
+ } catch (e) {
120
+ // eslint-disable-next-line no-console
121
+ console.warn(`[PostHog] Failed to deliver push identity token to native: ${e}`);
122
+ }
123
+ });
124
+ }
53
125
  const PostHogReactNativePlugin = {
54
126
  setup,
55
127
  start,
@@ -57,9 +129,15 @@ const PostHogReactNativePlugin = {
57
129
  endSession,
58
130
  isEnabled,
59
131
  identify,
132
+ reset,
60
133
  startRecording,
61
134
  stopRecording,
62
- addExceptionStep
135
+ addExceptionStep,
136
+ registerPushNotificationToken,
137
+ unregisterPushNotificationToken,
138
+ setOptOut,
139
+ capturePushNotificationOpened,
140
+ setPushIdentityProvider
63
141
  };
64
142
  var _default = exports.default = PostHogReactNativePlugin;
65
143
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","PosthogReactNativePlugin","NativeModules","Proxy","get","Error","setup","sessionId","sdkOptions","pluginConfig","start","sdkReplayConfig","decideReplayConfig","startSession","endSession","isEnabled","identify","distinctId","anonymousId","startRecording","resumeCurrent","stopRecording","addExceptionStep","message","properties","PostHogReactNativePlugin","_default","exports"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAMC,aAAa,GACjB,uFAAuF,GACvFC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,wBAAwB,GAAGC,0BAAa,CAACD,wBAAwB,GACnEC,0BAAa,CAACD,wBAAwB,GACtC,IAAIE,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACT,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAyBE,SAASU,KAAKA,CACnBC,SAAiB,EACjBC,UAAuC,EACvCC,YAA4C,GAAG,CAAC,CAAC,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}
1
+ {"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","PosthogReactNativePlugin","NativeModules","Proxy","get","Error","setup","sessionId","sdkOptions","pluginConfig","start","sdkReplayConfig","decideReplayConfig","startSession","endSession","isEnabled","identify","distinctId","anonymousId","reset","startRecording","resumeCurrent","stopRecording","addExceptionStep","message","properties","registerPushNotificationToken","deviceToken","appId","unregisterPushNotificationToken","setOptOut","optOut","capturePushNotificationOpened","PUSH_IDENTITY_EVENT","pushIdentitySubscription","setPushIdentityProvider","provider","remove","emitter","NativeEventEmitter","addListener","request","token","minted","e","console","warn","providePushIdentityToken","requestId","PostHogReactNativePlugin","_default","exports"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAGA,MAAMC,aAAa,GACjB,uFAAuF,GACvFC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,wBAAwB,GAAGC,0BAAa,CAACD,wBAAwB,GACnEC,0BAAa,CAACD,wBAAwB,GACtC,IAAIE,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACT,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAsCE,SAASU,KAAKA,CACnBC,SAAiB,EACjBC,UAAuC,EACvCC,YAA4C,GAAG,CAAC,CAAC,EAClC;EACf,OAAOR,wBAAwB,CAACK,KAAK,CAACC,SAAS,EAAEC,UAAU,EAAEC,YAAY,CAAC;AAC5E;AAEO,SAASC,KAAKA,CACnBH,SAAiB,EACjBC,UAAuC,EACvCG,eAA4C,EAC5CC,kBAA+C,EAChC;EACf,OAAOX,wBAAwB,CAACS,KAAK,CAACH,SAAS,EAAEC,UAAU,EAAEG,eAAe,EAAEC,kBAAkB,CAAC;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;EACTE,6BAA6B;EAC7BG;AACF,CAAC;AAAA,IAAAe,QAAA,GAAAC,OAAA,CAAAnD,OAAA,GAEciD,wBAAwB","ignoreList":[]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- import { NativeModules, Platform } from 'react-native';
3
+ import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
4
4
  const LINKING_ERROR = `The package '@posthog/react-native-plugin' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
5
5
  ios: "- You have run 'pod install'\n",
6
6
  default: ''
@@ -28,6 +28,15 @@ export function isEnabled() {
28
28
  export function identify(distinctId, anonymousId) {
29
29
  return PosthogReactNativePlugin.identify(distinctId, anonymousId);
30
30
  }
31
+
32
+ /**
33
+ * Resets the native SDK's identity on logout. Unlike {@link identify}, this calls the native
34
+ * SDK's own `reset()`, which unregisters the logged-out user's push subscription and
35
+ * re-registers it under the new anonymous id.
36
+ */
37
+ export function reset(distinctId, anonymousId) {
38
+ return PosthogReactNativePlugin.reset(distinctId, anonymousId);
39
+ }
31
40
  export function startRecording(resumeCurrent) {
32
41
  return PosthogReactNativePlugin.startRecording(resumeCurrent);
33
42
  }
@@ -37,6 +46,63 @@ export function stopRecording() {
37
46
  export function addExceptionStep(message, properties) {
38
47
  return PosthogReactNativePlugin.addExceptionStep(message, properties ?? {});
39
48
  }
49
+ export function registerPushNotificationToken(deviceToken, appId) {
50
+ return PosthogReactNativePlugin.registerPushNotificationToken(deviceToken, appId);
51
+ }
52
+ export function unregisterPushNotificationToken() {
53
+ return PosthogReactNativePlugin.unregisterPushNotificationToken();
54
+ }
55
+
56
+ /**
57
+ * Propagates a runtime consent change to the native SDK, which otherwise only reads the JS
58
+ * opt-out flag at setup() and could auto-register a refreshed push token after optOut().
59
+ */
60
+ export function setOptOut(optOut) {
61
+ return PosthogReactNativePlugin.setOptOut(optOut);
62
+ }
63
+ export function capturePushNotificationOpened(properties) {
64
+ return PosthogReactNativePlugin.capturePushNotificationOpened(properties);
65
+ }
66
+
67
+ /**
68
+ * Mints a signed identity-verification token for a push subscription request.
69
+ * Return null to send the request without an identity token.
70
+ */
71
+
72
+ const PUSH_IDENTITY_EVENT = 'PostHogPushIdentityRequest';
73
+ let pushIdentitySubscription;
74
+
75
+ /**
76
+ * Installs the JS side of the push identity-provider bridge. The native SDK asks for a
77
+ * token via a `PostHogPushIdentityRequest` event; the reply is routed back with
78
+ * `providePushIdentityToken`, keyed by the request id so late replies are ignored.
79
+ *
80
+ * Install before setup() with `push.pushIdentityProviderEnabled` set, so the native
81
+ * config gets its bridging provider at SDK initialization. Any provider failure
82
+ * degrades to a null token — an unauthenticated request — never a stalled mint.
83
+ */
84
+ export function setPushIdentityProvider(provider) {
85
+ pushIdentitySubscription?.remove();
86
+ // Via the proxy, not raw NativeModules: an unlinked module would build an emitter over
87
+ // undefined and throw a generic RN error inside the SDK's init try, taking replay down with it.
88
+ const emitter = new NativeEventEmitter(PosthogReactNativePlugin);
89
+ pushIdentitySubscription = emitter.addListener(PUSH_IDENTITY_EVENT, async request => {
90
+ let token = null;
91
+ try {
92
+ const minted = await provider(request.distinctId, request.appId);
93
+ token = typeof minted === 'string' ? minted : null;
94
+ } catch (e) {
95
+ // eslint-disable-next-line no-console
96
+ console.warn(`[PostHog] pushIdentityProvider threw: ${e}. Push subscription will be sent unauthenticated.`);
97
+ }
98
+ try {
99
+ await PosthogReactNativePlugin.providePushIdentityToken(request.requestId, token);
100
+ } catch (e) {
101
+ // eslint-disable-next-line no-console
102
+ console.warn(`[PostHog] Failed to deliver push identity token to native: ${e}`);
103
+ }
104
+ });
105
+ }
40
106
  const PostHogReactNativePlugin = {
41
107
  setup,
42
108
  start,
@@ -44,9 +110,15 @@ const PostHogReactNativePlugin = {
44
110
  endSession,
45
111
  isEnabled,
46
112
  identify,
113
+ reset,
47
114
  startRecording,
48
115
  stopRecording,
49
- addExceptionStep
116
+ addExceptionStep,
117
+ registerPushNotificationToken,
118
+ unregisterPushNotificationToken,
119
+ setOptOut,
120
+ capturePushNotificationOpened,
121
+ setPushIdentityProvider
50
122
  };
51
123
  export default PostHogReactNativePlugin;
52
124
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","PosthogReactNativePlugin","Proxy","get","Error","setup","sessionId","sdkOptions","pluginConfig","start","sdkReplayConfig","decideReplayConfig","startSession","endSession","isEnabled","identify","distinctId","anonymousId","startRecording","resumeCurrent","stopRecording","addExceptionStep","message","properties","PostHogReactNativePlugin"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtD,MAAMC,aAAa,GACjB,uFAAuF,GACvFD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,wBAAwB,GAAGN,aAAa,CAACM,wBAAwB,GACnEN,aAAa,CAACM,wBAAwB,GACtC,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACP,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAyBL,OAAO,SAASQ,KAAKA,CACnBC,SAAiB,EACjBC,UAAuC,EACvCC,YAA4C,GAAG,CAAC,CAAC,EAClC;EACf,OAAOP,wBAAwB,CAACI,KAAK,CAACC,SAAS,EAAEC,UAAU,EAAEC,YAAY,CAAC;AAC5E;AAEA,OAAO,SAASC,KAAKA,CACnBH,SAAiB,EACjBC,UAAuC,EACvCG,eAA4C,EAC5CC,kBAA+C,EAChC;EACf,OAAOV,wBAAwB,CAACQ,KAAK,CAACH,SAAS,EAAEC,UAAU,EAAEG,eAAe,EAAEC,kBAAkB,CAAC;AACnG;AAEA,OAAO,SAASC,YAAYA,CAACN,SAAiB,EAAiB;EAC7D,OAAOL,wBAAwB,CAACW,YAAY,CAACN,SAAS,CAAC;AACzD;AAEA,OAAO,SAASO,UAAUA,CAAA,EAAkB;EAC1C,OAAOZ,wBAAwB,CAACY,UAAU,CAAC,CAAC;AAC9C;AAEA,OAAO,SAASC,SAASA,CAAA,EAAqB;EAC5C,OAAOb,wBAAwB,CAACa,SAAS,CAAC,CAAC;AAC7C;AAEA,OAAO,SAASC,QAAQA,CAACC,UAAkB,EAAEC,WAAmB,EAAiB;EAC/E,OAAOhB,wBAAwB,CAACc,QAAQ,CAACC,UAAU,EAAEC,WAAW,CAAC;AACnE;AAEA,OAAO,SAASC,cAAcA,CAACC,aAAsB,EAAiB;EACpE,OAAOlB,wBAAwB,CAACiB,cAAc,CAACC,aAAa,CAAC;AAC/D;AAEA,OAAO,SAASC,aAAaA,CAAA,EAAkB;EAC7C,OAAOnB,wBAAwB,CAACmB,aAAa,CAAC,CAAC;AACjD;AAEA,OAAO,SAASC,gBAAgBA,CAACC,OAAe,EAAEC,UAAwC,EAAiB;EACzG,OAAOtB,wBAAwB,CAACoB,gBAAgB,CAACC,OAAO,EAAEC,UAAU,IAAI,CAAC,CAAC,CAAC;AAC7E;AAkCA,MAAMC,wBAAwD,GAAG;EAC/DnB,KAAK;EACLI,KAAK;EACLG,YAAY;EACZC,UAAU;EACVC,SAAS;EACTC,QAAQ;EACRG,cAAc;EACdE,aAAa;EACbC;AACF,CAAC;AAED,eAAeG,wBAAwB","ignoreList":[]}
1
+ {"version":3,"names":["NativeEventEmitter","NativeModules","Platform","LINKING_ERROR","select","ios","default","PosthogReactNativePlugin","Proxy","get","Error","setup","sessionId","sdkOptions","pluginConfig","start","sdkReplayConfig","decideReplayConfig","startSession","endSession","isEnabled","identify","distinctId","anonymousId","reset","startRecording","resumeCurrent","stopRecording","addExceptionStep","message","properties","registerPushNotificationToken","deviceToken","appId","unregisterPushNotificationToken","setOptOut","optOut","capturePushNotificationOpened","PUSH_IDENTITY_EVENT","pushIdentitySubscription","setPushIdentityProvider","provider","remove","emitter","addListener","request","token","minted","e","console","warn","providePushIdentityToken","requestId","PostHogReactNativePlugin"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,kBAAkB,EAAEC,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAG1E,MAAMC,aAAa,GACjB,uFAAuF,GACvFD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,wBAAwB,GAAGN,aAAa,CAACM,wBAAwB,GACnEN,aAAa,CAACM,wBAAwB,GACtC,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACP,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAsCL,OAAO,SAASQ,KAAKA,CACnBC,SAAiB,EACjBC,UAAuC,EACvCC,YAA4C,GAAG,CAAC,CAAC,EAClC;EACf,OAAOP,wBAAwB,CAACI,KAAK,CAACC,SAAS,EAAEC,UAAU,EAAEC,YAAY,CAAC;AAC5E;AAEA,OAAO,SAASC,KAAKA,CACnBH,SAAiB,EACjBC,UAAuC,EACvCG,eAA4C,EAC5CC,kBAA+C,EAChC;EACf,OAAOV,wBAAwB,CAACQ,KAAK,CAACH,SAAS,EAAEC,UAAU,EAAEG,eAAe,EAAEC,kBAAkB,CAAC;AACnG;AAEA,OAAO,SAASC,YAAYA,CAACN,SAAiB,EAAiB;EAC7D,OAAOL,wBAAwB,CAACW,YAAY,CAACN,SAAS,CAAC;AACzD;AAEA,OAAO,SAASO,UAAUA,CAAA,EAAkB;EAC1C,OAAOZ,wBAAwB,CAACY,UAAU,CAAC,CAAC;AAC9C;AAEA,OAAO,SAASC,SAASA,CAAA,EAAqB;EAC5C,OAAOb,wBAAwB,CAACa,SAAS,CAAC,CAAC;AAC7C;AAEA,OAAO,SAASC,QAAQA,CAACC,UAAkB,EAAEC,WAAmB,EAAiB;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AqC,EAAQ;EACnFF,wBAAwB,EAAEG,MAAM,CAAC,CAAC;EAClC;EACA;EACA,MAAMC,OAAO,GAAG,IAAI3C,kBAAkB,CAACO,wBAAwB,CAAC;EAChEgC,wBAAwB,GAAGI,OAAO,CAACC,WAAW,CAC5CN,mBAAmB,EACnB,MAAOO,OAAiE,IAAK;IAC3E,IAAIC,KAAoB,GAAG,IAAI;IAC/B,IAAI;MACF,MAAMC,MAAM,GAAG,MAAMN,QAAQ,CAACI,OAAO,CAACvB,UAAU,EAAEuB,OAAO,CAACZ,KAAK,CAAC;MAChEa,KAAK,GAAG,OAAOC,MAAM,KAAK,QAAQ,GAAGA,MAAM,GAAG,IAAI;IACpD,CAAC,CAAC,OAAOC,CAAC,EAAE;MACV;MACAC,OAAO,CAACC,IAAI,CAAC,yCAAyCF,CAAC,mDAAmD,CAAC;IAC7G;IACA,IAAI;MACF,MAAMzC,wBAAwB,CAAC4C,wBAAwB,CAACN,OAAO,CAACO,SAAS,EAAEN,KAAK,CAAC;IACnF,CAAC,CAAC,OAAOE,CAAC,EAAE;MACV;MACAC,OAAO,CAACC,IAAI,CAAC,8DAA8DF,CAAC,EAAE,CAAC;IACjF;EACF,CACF,CAAC;AACH;AA8CA,MAAMK,wBAAwD,GAAG;EAC/D1C,KAAK;EACLI,KAAK;EACLG,YAAY;EACZC,UAAU;EACVC,SAAS;EACTC,QAAQ;EACRG,KAAK;EACLC,cAAc;EACdE,aAAa;EACbC,gBAAgB;EAChBG,6BAA6B;EAC7BG,+BAA+B;EAC/BC,SAAS;EACTE,6BAA6B;EAC7BG;AACF,CAAC;AAED,eAAea,wBAAwB","ignoreList":[]}
@@ -14,9 +14,21 @@ export interface PostHogReactNativePluginErrorTrackingConfig {
14
14
  nativeAutocapture?: boolean;
15
15
  exceptionSteps?: PostHogReactNativePluginExceptionStepsConfig;
16
16
  }
17
+ export interface PostHogReactNativePluginPushConfig {
18
+ capturePushNotificationSubscriptions?: boolean;
19
+ capturePushNotificationOpened?: boolean;
20
+ /**
21
+ * A provider callback can't cross the bridge, so this only tells native whether to
22
+ * install the bridging provider at all — installing one the host didn't ask for
23
+ * would change how the native SDK handles a 401 on the subscription call.
24
+ * Pair with {@link setPushIdentityProvider} before calling setup().
25
+ */
26
+ pushIdentityProviderEnabled?: boolean;
27
+ }
17
28
  export interface PostHogReactNativePluginConfig {
18
29
  sessionReplay?: PostHogReactNativePluginSessionReplayConfig;
19
30
  errorTracking?: PostHogReactNativePluginErrorTrackingConfig;
31
+ push?: PostHogReactNativePluginPushConfig;
20
32
  }
21
33
  export declare function setup(sessionId: string, sdkOptions: PostHogReactNativePluginMap, pluginConfig?: PostHogReactNativePluginConfig): Promise<void>;
22
34
  export declare function start(sessionId: string, sdkOptions: PostHogReactNativePluginMap, sdkReplayConfig: PostHogReactNativePluginMap, decideReplayConfig: PostHogReactNativePluginMap): Promise<void>;
@@ -24,9 +36,38 @@ export declare function startSession(sessionId: string): Promise<void>;
24
36
  export declare function endSession(): Promise<void>;
25
37
  export declare function isEnabled(): Promise<boolean>;
26
38
  export declare function identify(distinctId: string, anonymousId: string): Promise<void>;
39
+ /**
40
+ * Resets the native SDK's identity on logout. Unlike {@link identify}, this calls the native
41
+ * SDK's own `reset()`, which unregisters the logged-out user's push subscription and
42
+ * re-registers it under the new anonymous id.
43
+ */
44
+ export declare function reset(distinctId: string, anonymousId: string): Promise<void>;
27
45
  export declare function startRecording(resumeCurrent: boolean): Promise<void>;
28
46
  export declare function stopRecording(): Promise<void>;
29
47
  export declare function addExceptionStep(message: string, properties?: PostHogReactNativePluginMap): Promise<void>;
48
+ export declare function registerPushNotificationToken(deviceToken: string, appId: string | null): Promise<void>;
49
+ export declare function unregisterPushNotificationToken(): Promise<void>;
50
+ /**
51
+ * Propagates a runtime consent change to the native SDK, which otherwise only reads the JS
52
+ * opt-out flag at setup() and could auto-register a refreshed push token after optOut().
53
+ */
54
+ export declare function setOptOut(optOut: boolean): Promise<void>;
55
+ export declare function capturePushNotificationOpened(properties: PostHogReactNativePluginMap): Promise<void>;
56
+ /**
57
+ * Mints a signed identity-verification token for a push subscription request.
58
+ * Return null to send the request without an identity token.
59
+ */
60
+ export type PostHogPushIdentityProvider = (distinctId: string, appId: string) => Promise<string | null>;
61
+ /**
62
+ * Installs the JS side of the push identity-provider bridge. The native SDK asks for a
63
+ * token via a `PostHogPushIdentityRequest` event; the reply is routed back with
64
+ * `providePushIdentityToken`, keyed by the request id so late replies are ignored.
65
+ *
66
+ * Install before setup() with `push.pushIdentityProviderEnabled` set, so the native
67
+ * config gets its bridging provider at SDK initialization. Any provider failure
68
+ * degrades to a null token — an unauthenticated request — never a stalled mint.
69
+ */
70
+ export declare function setPushIdentityProvider(provider: PostHogPushIdentityProvider): void;
30
71
  export interface PostHogReactNativePluginModule {
31
72
  setup: (sessionId: string, sdkOptions: PostHogReactNativePluginMap, pluginConfig?: PostHogReactNativePluginConfig) => Promise<void>;
32
73
  /**
@@ -37,9 +78,15 @@ export interface PostHogReactNativePluginModule {
37
78
  endSession: () => Promise<void>;
38
79
  isEnabled: () => Promise<boolean>;
39
80
  identify: (distinctId: string, anonymousId: string) => Promise<void>;
81
+ reset: (distinctId: string, anonymousId: string) => Promise<void>;
40
82
  startRecording: (resumeCurrent: boolean) => Promise<void>;
41
83
  stopRecording: () => Promise<void>;
42
84
  addExceptionStep: (message: string, properties?: PostHogReactNativePluginMap) => Promise<void>;
85
+ registerPushNotificationToken: (deviceToken: string, appId: string | null) => Promise<void>;
86
+ unregisterPushNotificationToken: () => Promise<void>;
87
+ setOptOut: (optOut: boolean) => Promise<void>;
88
+ capturePushNotificationOpened: (properties: PostHogReactNativePluginMap) => Promise<void>;
89
+ setPushIdentityProvider: (provider: PostHogPushIdentityProvider) => void;
43
90
  }
44
91
  declare const PostHogReactNativePlugin: PostHogReactNativePluginModule;
45
92
  export default PostHogReactNativePlugin;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":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