@pushpilotai/react-native 2.0.0 → 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.
@@ -19,7 +19,7 @@ Pod::Spec.new do |s|
19
19
  # To build against a local pushpilot-ios checkout instead, see README -> Local development.
20
20
  spm_dependency(s,
21
21
  url: "https://github.com/pushpilotai/pushpilot-ios.git",
22
- requirement: { kind: "upToNextMajorVersion", minimumVersion: "2.0.0" },
22
+ requirement: { kind: "upToNextMajorVersion", minimumVersion: "2.3.0" },
23
23
  products: ["PushPilot"]
24
24
  )
25
25
 
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  React Native wrapper for the PushPilot SDK. It registers your app's installation with PushPilot and passes in its push address: the Firebase Cloud Messaging (FCM) identifier on Android and the Apple (APNs) device token on iOS. You can then send pushes to individual users from the PushPilot dashboard. PushPilot pushes are shown and their taps recorded natively, with no JavaScript running.
4
4
 
5
- - A thin layer over the native [Android SDK](https://github.com/pushpilotai/pushpilot-android) (`ai.pushpilot:sdk` 2.0.0) and [iOS SDK](https://github.com/pushpilotai/pushpilot-ios) (Swift package `PushPilot` 2.0.0). Every call goes straight to them; they do all syncing, retrying, storage, display and validation.
5
+ - A thin layer over the native [Android SDK](https://github.com/pushpilotai/pushpilot-android) (`ai.pushpilot:sdk` 2.3.0) and [iOS SDK](https://github.com/pushpilotai/pushpilot-ios) (Swift package `PushPilot` 2.3.0). Every call goes straight to them; they do all syncing, retrying, storage, display and validation.
6
6
  - No Firebase dependency. On Android your app keeps its own Firebase setup and passes the identifier in. iOS needs no Firebase at all: PushPilot sends to Apple directly.
7
7
  - Never asks for notification permission. It reports whatever the user chose.
8
8
  - Every call returns nothing and never throws into your app. Problems are logged.
@@ -146,6 +146,93 @@ Optional: set the notification icon and channel name with the Android SDK's meta
146
146
 
147
147
  The [iOS SDK README](https://github.com/pushpilotai/pushpilot-ios#images-and-buttons-notification-service-extension) explains what the helper does and how it fails safely. The example's `NotificationService` target is set up this way.
148
148
 
149
+ ## Live activities
150
+
151
+ From 2.1.1, PushPilot can start, update and end live activities by push, from the dashboard, a campaign or the server API: a score, a delivery or an upload that stays on screen and changes with each update. The native SDKs do all the work; your app starts none itself and needs no JavaScript beyond the two optional calls below.
152
+
153
+ ### Android
154
+
155
+ Nothing to add: the Android SDK 2.1.1 draws each live activity as one ongoing notification on a "Live updates" channel, from the same receiver that shows your other PushPilot pushes. On Android 16 an activity sent as promoted shows as a Live Update (status chip, segmented progress) when the user allows it; the SDK's manifest merges the `POST_PROMOTED_NOTIFICATIONS` permission it needs, a normal permission granted at install. Taps open the activity's link like a push's, through `setLinkHandler` when one is set. See the [Android SDK README](https://github.com/pushpilotai/pushpilot-android#live-activities).
156
+
157
+ ### iOS
158
+
159
+ Live activities started by push need iOS 17.2 or later; the app itself still runs on iOS 15.1. In Xcode (`ios/<App>.xcworkspace`):
160
+
161
+ 1. **Add a Widget Extension:** **File › New › Target… › Widget Extension**, named for example `LiveActivity`, with the template's *Include …* options unticked. Keep its bundle id under the app's, set its deployment target to iOS 16.1 or later and its signing team to the app's; choose **Cancel** when Xcode asks to activate the new scheme. Delete the generated widget files except the bundle.
162
+ 2. **Add the `PushPilotLive` library to the extension target only**, from the pushpilot-ios package: if the app's project already has it (for the Notification Service Extension), pick the extension under *General › Frameworks and Libraries › +*; otherwise **File › Add Package Dependencies…** with the pushpilot-ios repository URL. The app target needs nothing: the wrapper's pod already brings in `PushPilot`, which includes `PushPilotLive`. Like the Notification Service Extension, the Widget Extension uses no pods, so nothing goes in the `Podfile`.
163
+ 3. **Make the bundle return PushPilot's widget**, which draws every PushPilot layout on the Lock Screen and in the Dynamic Island:
164
+
165
+ ```swift
166
+ import PushPilotLive
167
+ import SwiftUI
168
+ import WidgetKit
169
+
170
+ @main
171
+ struct LiveActivityWidgets: WidgetBundle {
172
+ var body: some Widget {
173
+ PushPilotLiveActivityWidget(appGroup: "group.com.example.app")
174
+ }
175
+ }
176
+ ```
177
+
178
+ To draw activities your own way, return an `ActivityConfiguration(for: PushPilotLiveAttributes.self)` instead; see the [iOS SDK README](https://github.com/pushpilotai/pushpilot-ios#live-activities).
179
+ 4. **Add `NSSupportsLiveActivities`** (Boolean, `YES`) to the app's `Info.plist`. Without it iOS starts none, and the SDK tells PushPilot so.
180
+ 5. **Optional: an App Group** for images in layouts. Add the *App Groups* capability with the same group to the app and the extension, pass it to the widget as above and to `init`:
181
+
182
+ ```tsx
183
+ PushPilot.init('pp_sdk_...', { appGroup: 'group.com.example.app' });
184
+ ```
185
+
186
+ The SDK then downloads the layout's https images into the group for the widget. Without one, image blocks show their fallback icon.
187
+ 6. **Pass opened URLs to `handleLiveActivityURL`.** A tap on a live activity opens your app with the activity's link plus a `pushpilot_live` marker. `handleLiveActivityURL` counts the click once and resolves to your link without the marker, or `null` when the activity has none:
188
+
189
+ ```tsx
190
+ import { Linking } from 'react-native';
191
+
192
+ const opened = async (url: string | null) => {
193
+ if (!url) return;
194
+ const link = await PushPilot.handleLiveActivityURL(url);
195
+ if (link) router.open(link); // null: the tap only opens the app
196
+ };
197
+ Linking.getInitialURL().then(opened);
198
+ Linking.addEventListener('url', ({ url }) => opened(url));
199
+ ```
200
+
201
+ `Linking` needs `RCTLinkingManager` in your `AppDelegate` or `SceneDelegate`, as React Native's [Linking guide](https://reactnative.dev/docs/linking) describes. Other URLs come back unchanged, so you can pass every URL through it. On Android it resolves every URL unchanged.
202
+
203
+ The SDK watches PushPilot activities while the app runs and reports their tokens and state to PushPilot. An Expo app that regenerates its `ios/` folder can only add a Widget Extension with a config plugin, which PushPilot does not provide.
204
+
205
+ ## In-app messages
206
+
207
+ From 2.2.0, messages you publish in the dashboard's in-app section show over your app: a modal, full screen, bottom sheet, banner, card, carousel, or a coach mark pointing at one of your views. The native SDKs fetch, cache and draw them (an HTML page in a transparent web view over the current screen) and report `shown`, `clicked` and `dismissed`. See the [Android](https://github.com/pushpilotai/pushpilot-android#in-app-messages) and [iOS](https://github.com/pushpilotai/pushpilot-ios#in-app-messages) READMEs for how messages are fetched, cached and locked down.
208
+
209
+ 1. **Nothing to add for app-open messages.** With `init` called at startup, the first eligible message with the "app open" trigger shows when the app comes to the foreground. Messages are fetched after the installation's first sync, at most once a minute on foreground, and show only from what is already cached, never from the network.
210
+ 2. **Named moments.** For a message whose trigger is an in-app call, call `showInApp` with its name where it should appear:
211
+
212
+ ```tsx
213
+ const shown = await PushPilot.showInApp('checkout');
214
+ ```
215
+
216
+ It resolves to `true` when a message is now on screen, and `false` when none is cached and eligible, another message is showing, it is past its cap or outside its dates, or the SDK has not started. It never rejects. The call runs on the native main thread for you.
217
+ 3. **Coach marks.** A coach-mark message points at one of your views by the name its target uses in the dashboard. Pass the view's `ref` once it is mounted:
218
+
219
+ ```tsx
220
+ const compose = useRef<ComponentRef<typeof View>>(null);
221
+ useEffect(() => {
222
+ PushPilot.markView(compose, 'compose');
223
+ return () => PushPilot.unmarkView('compose');
224
+ }, []);
225
+
226
+ <View ref={compose} collapsable={false}>
227
+ <Button title="Compose" onPress={openComposer} />
228
+ </View>
229
+ ```
230
+
231
+ - Give a plain `<View>` `collapsable={false}`: React Native removes layout-only views from the native tree, and a view with no native counterpart cannot be marked. Native components (`Pressable`, `TextInput`, `Image`...) need nothing extra.
232
+ - `markView` also takes a view tag from `findNodeHandle`. A ref that is not mounted yet logs a warning and marks nothing; mark it again from an effect or `onLayout`.
233
+ - The native view is looked up on the UI thread (New Architecture). The SDK holds it weakly; a later view with the same name replaces it, and `unmarkView(name)` forgets it. A coach mark shows only while its view is on screen; otherwise it waits.
234
+ 4. **Links.** A button's link closes the message and goes to `setLinkHandler`, the same handler tapped pushes use ([Taps](#taps-on-android-and-ios)). Without one, the system opens it.
235
+
149
236
  ## Integrate (Expo development build)
150
237
 
151
238
  PushPilot has no Expo config plugin. What works without one:
@@ -207,11 +294,23 @@ What differs underneath:
207
294
 
208
295
  The link handler and tap data come from the native SDKs' own APIs (`setLinkHandler` and `tappedNotification` on Android, `setLinkHandler` and `userInfo["data"]` on iOS).
209
296
 
297
+ ## Custom events
298
+
299
+ ```tsx
300
+ PushPilot.track('order_placed', { sku: 'A-1', value: 49.5, gift: false });
301
+ PushPilot.track('app_opened');
302
+ ```
303
+
304
+ Names are snake_case, at most 40 characters; property values are strings, numbers or booleans (others, including `null`, are dropped), and a numeric `value` is summed in reports. The native SDKs check the name and values, keep events on the device and send them in batches with retries; each event carries its own time and idempotency key, so it is counted once. New names are registered on first use (up to 100 per app, 20 properties each) and appear in the dashboard. In the store privacy forms, declare whatever matches the events you send (for example, purchase history or in-app actions).
305
+
210
306
  ## Upgrading from 1.x
211
307
 
212
308
  - **iOS no longer uses Firebase.** `setPushToken` on iOS now takes the APNs device token as hex. An FCM token or FID passed on iOS, the 1.x path, is ignored with a warning, so a 1.x app keeps the last token the SDK stored until you switch. Switch by adding the `AppDelegate` method above (or, on Expo, passing `getDevicePushTokenAsync`), and by giving PushPilot your APNs key.
213
309
  - **Android pushes are shown for you.** If your 1.x app showed PushPilot pushes itself after `handleMessage` returned `true`, remove that code, or they appear twice.
214
310
  - **New:** `setLinkHandler` and `setTapHandler`, on both platforms ([Taps](#taps-on-android-and-ios)).
311
+ - **2.1.1:** [live activities](#live-activities), with `init`'s `appGroup` and `handleLiveActivityURL`. Nothing changes for apps that do not use them.
312
+ - **2.2.0:** [in-app messages](#in-app-messages), with `showInApp`, `markView` and `unmarkView`. App-open messages show with no code; their links reach your existing `setLinkHandler`.
313
+ - **2.3.0:** [custom events](#custom-events), with `track`.
215
314
  - Every other call is unchanged, including `init`'s `baseUrl`.
216
315
 
217
316
  ## API
@@ -226,15 +325,20 @@ import PushPilot, {
226
325
 
227
326
  | Call | What it does |
228
327
  |---|---|
229
- | `init(sdkKey, { baseUrl? })` | Starts the SDK with your public SDK key. Call once at startup; later calls are ignored (including after a JavaScript reload). `baseUrl` defaults to `https://pushpilot.ai`; set it only for a self-hosted server. The native SDKs save the values, so a process started by a push or a tap before JavaScript runs can still send its events. |
328
+ | `init(sdkKey, { baseUrl?, appGroup? })` | Starts the SDK with your public SDK key. Call once at startup; later calls are ignored (including after a JavaScript reload). `baseUrl` defaults to `https://pushpilot.ai`; set it only for a self-hosted server. The native SDKs save the values, so a process started by a push or a tap before JavaScript runs can still send its events. `appGroup` (iOS) is the App Group shared with your Widget Extension, for images in [live activities](#live-activities); Android ignores it. |
230
329
  | `setPushToken(token \| null)` | Stores the push identifier and syncs it. **Android:** the Firebase Installation ID from `register` / `onRegistered`, or the FCM token from `getToken` / `onTokenRefresh` where your Firebase library has no FID API; pass only one kind. **iOS:** the APNs device token as hex (`getDevicePushTokenAsync`, `getAPNSToken`), if you do not forward it from the `AppDelegate`; anything else is ignored with a warning. `null` clears it, and the device then stops receiving pushes. |
231
330
  | `setExternalUserId(id \| null)` | Links this installation to your own user id (1 to 255 characters). One user can have many installations. `null` clears it, like `logout()`. |
232
331
  | `setAttributes(record)` | Merges custom attributes. Values are strings, numbers or booleans; pass dates as RFC 3339 strings (`date.toISOString()`) and `null` to remove an attribute. Only attributes declared in the dashboard are stored. |
332
+ | `track(name, properties?)` | Records a custom event, such as `order_placed`. See [Custom events](#custom-events). |
233
333
  | `setTopics(list)` | Replaces the topic list (at most 100; letters, digits and `-_.~%`). Invalid names are dropped. |
234
334
  | `logout()` | Clears the external user id. The device stays registered and keeps receiving pushes. |
235
335
  | `forget()` | Deletes this installation from PushPilot and clears all local SDK state. A new installation is registered after your next PushPilot call or the next app launch. Use it in your account-deletion or privacy flow. |
236
336
  | `handleMessage(data): boolean` | `true` when a received push's data has `source` equal to `pushpilot`. Answered in JavaScript with the native SDKs' rule; makes no native or network call. Use it to skip PushPilot pushes in your own message handlers. |
237
337
  | `setLinkHandler(handler \| null)` | Receives the link (`string`) of each tapped PushPilot push instead of the system opening it, like the native SDKs' `setLinkHandler`. A new handler replaces the old one; `null` lets the system open links again. Set it before `init` to get the tap that launched the app. See [Taps](#taps-on-android-and-ios). |
338
+ | `handleLiveActivityURL(url): Promise<string \| null>` | For a URL your app was opened with: a tap on an iOS live activity is counted once and resolves to the activity's own link without PushPilot's marker, or `null` when it has none. Any other URL, and every URL on Android, resolves unchanged. Never rejects. See [Live activities](#live-activities). |
339
+ | `showInApp(name): Promise<boolean>` | Shows the first eligible cached [in-app message](#in-app-messages) whose trigger is `name`; resolves to whether one is now on screen. No network call. Never rejects. |
340
+ | `markView(ref \| viewTag, name)` | Names a mounted view (a `ref` or a `findNodeHandle` tag) for coach-mark messages whose target is `name`. A plain `<View>` needs `collapsable={false}`. A later view with the same name replaces it. |
341
+ | `unmarkView(name)` | Forgets the view marked with `name`. |
238
342
  | `setTapHandler(handler \| null)` | Receives a `TappedNotification`, `{ notificationId: string, data: Record<string, string> }`, for each tapped PushPilot push that opens the app. `data` is the push's custom data, empty when it has none. A new handler replaces the old one; `null` stops it. Set it before `init` to get the tap that launched the app. |
239
343
 
240
344
  Native, for the iOS `AppDelegate` (`import PushPilotReactNative`):
@@ -257,6 +361,8 @@ The data each sync carries, the `delivered` (Android) and `clicked` (both) event
257
361
  - Initialises PushPilot at startup and sets a tap handler and a link handler before `init`. It shows the last tapped push's id and data, or its link.
258
362
  - **Android:** forwards the Firebase Installation ID from `@react-native-firebase/messaging` (`register` and `onRegistered`, turned on in `example/firebase.json`), and has a permission button.
259
363
  - **iOS:** no Firebase (`example/react-native.config.js` keeps React Native Firebase off iOS). The `AppDelegate` asks for permission at launch and forwards the device token, and the app has the Push Notifications entitlement and a `NotificationService` extension target.
364
+ - **Live activities:** `init` passes the App Group `group.pushpilot.reactnative.example`, and every URL the app is opened with goes through `handleLiveActivityURL`; the screen shows the link that comes back. On iOS the app has `NSSupportsLiveActivities`, the App Group, and a `LiveActivity` Widget Extension target (`example/ios/LiveActivity/`) that returns `PushPilotLiveActivityWidget` and links `PushPilotLive` from the pushpilot-ios package.
365
+ - **In-app messages:** a **Show in-app** button calls `showInApp('checkout')` and shows the result; the button is marked as the coach-mark target `example-button`.
260
366
  - Buttons for set user id, set topics, logout and forget.
261
367
 
262
368
  ```bash
@@ -269,7 +375,7 @@ It builds and runs without any Firebase config; Android then has no push identif
269
375
 
270
376
  - Put your SDK key in `PUSHPILOT_SDK_KEY` in `example/src/App.tsx`.
271
377
  - Android: add your own `example/android/app/google-services.json`. It is git-ignored; never commit it. The build applies the Google Services plugin only when the file exists.
272
- - iOS: set your signing team and bundle ids you own on both targets, and give PushPilot the matching APNs key. The extension's bundle id must start with the app's.
378
+ - iOS: set your signing team, bundle ids and an App Group you own on all three targets, and give PushPilot the matching APNs key. The extensions' bundle ids must start with the app's.
273
379
 
274
380
  On the iOS simulator you can try taps without a server:
275
381
 
@@ -294,7 +400,7 @@ and switch these three places locally (don't commit them):
294
400
 
295
401
  1. **Android:** `cd ../pushpilot-android && ./gradlew :sdk:publishToMavenLocal`, then add `allprojects { repositories { mavenLocal { content { includeGroup("ai.pushpilot") } } } }` to `example/android/build.gradle` (or another app's root `build.gradle`).
296
402
  2. **iOS:** in `PushPilotReactNative.podspec`, set the `spm_dependency` `url:` to the absolute path of your `pushpilot-ios` checkout. Local paths need React Native 0.84 or later; on 0.81 to 0.83 use `"file:///absolute/path/to/pushpilot-ios"` with `requirement: { kind: "branch", branch: "<branch>" }`, which builds the committed branch, not uncommitted edits.
297
- 3. **The example's Notification Service Extension:** in Xcode, replace the `pushpilot-ios` package under *Package Dependencies* with *Add Local…* and the checkout.
403
+ 3. **The example's extensions** (Notification Service and Live Activity, which share one package reference): in Xcode, replace the `pushpilot-ios` package under *Package Dependencies* with *Add Local…* and the checkout.
298
404
 
299
405
  ### Checks
300
406
 
@@ -303,7 +409,7 @@ yarn typecheck
303
409
  yarn lint
304
410
  yarn test # Jest: the JavaScript layer, with the native module mocked
305
411
  yarn test:ios # the iOS APNs-hex parser, compiled with swiftc (macOS)
306
- cd example/android && ./gradlew :pushpilot_react-native:testDebugUnitTest # the Android receiver's data filter
412
+ cd example/android && ./gradlew :pushpilotai_react-native:testDebugUnitTest # the Android receiver's data filter
307
413
  ```
308
414
 
309
415
  ## Releasing
@@ -33,6 +33,6 @@ android {
33
33
 
34
34
  dependencies {
35
35
  implementation "com.facebook.react:react-android"
36
- implementation "ai.pushpilot:sdk:2.0.0"
36
+ implementation "ai.pushpilot:sdk:2.3.0"
37
37
  testImplementation "junit:junit:4.13.2"
38
38
  }
@@ -4,13 +4,18 @@ import ai.pushpilot.sdk.PushPilot
4
4
  import ai.pushpilot.sdk.TappedNotification
5
5
  import android.app.Activity
6
6
  import android.content.Intent
7
+ import android.util.Log
8
+ import android.view.Choreographer
7
9
  import com.facebook.react.bridge.ActivityEventListener
8
10
  import com.facebook.react.bridge.Arguments
9
11
  import com.facebook.react.bridge.LifecycleEventListener
12
+ import com.facebook.react.bridge.Promise
10
13
  import com.facebook.react.bridge.ReactApplicationContext
11
14
  import com.facebook.react.bridge.ReadableArray
12
15
  import com.facebook.react.bridge.ReadableMap
16
+ import com.facebook.react.bridge.UiThreadUtil
13
17
  import com.facebook.react.modules.core.DeviceEventManagerModule
18
+ import com.facebook.react.uimanager.UIManagerHelper
14
19
 
15
20
  /** Passes each JavaScript call straight to the native PushPilot SDK, and tapped pushes back to JavaScript. */
16
21
  class PushPilotModule(reactContext: ReactApplicationContext) :
@@ -28,10 +33,19 @@ class PushPilotModule(reactContext: ReactApplicationContext) :
28
33
  /** Starts the SDK (a null base URL means its default server); then taps that waited for JavaScript go to it. */
29
34
  override fun initialize(sdkKey: String, baseUrl: String?) {
30
35
  PushPilot.init(reactApplicationContext.applicationContext, sdkKey, baseUrl)
36
+ // JavaScript's init runs after the activity resumed, which the SDK's lifecycle watcher missed.
37
+ reactApplicationContext.currentActivity?.let(PushPilot::setCurrentActivity)
31
38
  PushPilotTaps.opened(reactApplicationContext.currentActivity?.intent)
32
39
  PushPilotTaps.attach(this)
33
40
  }
34
41
 
42
+ /** Same as [initialize]: the App Group is for iOS live activities and has no use on Android. */
43
+ override fun initializeWithAppGroup(sdkKey: String, baseUrl: String?, appGroup: String) =
44
+ initialize(sdkKey, baseUrl)
45
+
46
+ /** Android needs no URL handling for live activities (the SDK opens their links), so the URL comes back unchanged. */
47
+ override fun handleLiveActivityURL(url: String, promise: Promise) = promise.resolve(url)
48
+
35
49
  /** Forwards the Firebase Installation ID or FCM token, or null to clear it. */
36
50
  override fun setPushToken(token: String?) = PushPilot.setPushToken(token)
37
51
 
@@ -41,6 +55,9 @@ class PushPilotModule(reactContext: ReactApplicationContext) :
41
55
  /** Forwards the attributes as a plain map; the SDK checks the value types. */
42
56
  override fun setAttributes(attributes: ReadableMap) = PushPilot.setAttributes(attributes.toHashMap())
43
57
 
58
+ /** Forwards a custom event with its properties as a plain map; the SDK validates and batches it. */
59
+ override fun track(name: String, properties: ReadableMap) = PushPilot.track(name, properties.toHashMap())
60
+
44
61
  /** Forwards the topic list; the SDK validates the names. */
45
62
  override fun setTopics(topics: ReadableArray) =
46
63
  PushPilot.setTopics(topics.toArrayList().filterIsInstance<String>())
@@ -51,6 +68,34 @@ class PushPilotModule(reactContext: ReactApplicationContext) :
51
68
  /** Deletes this installation and clears local SDK state. */
52
69
  override fun forget() = PushPilot.forget()
53
70
 
71
+ /** Shows a cached in-app message on the main thread, where the SDK requires it, and resolves whether one is on screen. */
72
+ override fun showInApp(name: String, promise: Promise) {
73
+ UiThreadUtil.runOnUiThread { promise.resolve(PushPilot.showInApp(name)) }
74
+ }
75
+
76
+ /** Looks the view up by its React tag and names it for coach marks; a tag with no native view is logged and ignored. */
77
+ override fun markView(viewTag: Double, name: String) {
78
+ onNextFrame {
79
+ val tag = viewTag.toInt()
80
+ val view = UIManagerHelper.getUIManagerForReactTag(reactApplicationContext, tag)?.resolveView(tag)
81
+ if (view != null) PushPilot.markView(view, name)
82
+ else Log.w(TAG, "markView ignored: no native view for that ref (is it mounted, with collapsable={false}?)")
83
+ }
84
+ }
85
+
86
+ /** Forgets the named view; on the same queue as [markView], so an earlier mark never lands after it. */
87
+ override fun unmarkView(name: String) {
88
+ onNextFrame { PushPilot.unmarkView(name) }
89
+ }
90
+
91
+ /**
92
+ * Runs [block] on the UI thread in the next frame: Fabric mounts a commit's views from a frame callback it
93
+ * keeps posted ahead of this one, so a ref marked in an effect right after render has its native view.
94
+ */
95
+ private fun onNextFrame(block: () -> Unit) {
96
+ UiThreadUtil.runOnUiThread { Choreographer.getInstance().postFrameCallback { block() } }
97
+ }
98
+
54
99
  /** JavaScript set (true) or cleared its link handler; the SDK's links come here only while one is set. */
55
100
  override fun setLinkHandlerEnabled(enabled: Boolean) {
56
101
  wantsLinks = enabled
@@ -105,5 +150,6 @@ class PushPilotModule(reactContext: ReactApplicationContext) :
105
150
 
106
151
  companion object {
107
152
  const val NAME = NativePushPilotSpec.NAME
153
+ private const val TAG = "PushPilot"
108
154
  }
109
155
  }
@@ -126,7 +126,59 @@ RCT_EXPORT_METHOD(setTapHandlerEnabled:(BOOL)enabled)
126
126
  // to the handlers JavaScript set before init.
127
127
  RCT_EXPORT_METHOD(initialize:(NSString *)sdkKey baseUrl:(NSString *)baseUrl)
128
128
  {
129
- [RNPushPilotBridge startWithSdkKey:sdkKey baseUrl:baseUrl];
129
+ [self startWithSdkKey:sdkKey baseUrl:baseUrl appGroup:nil];
130
+ }
131
+
132
+ // Starts the SDK as initialize does, with the App Group shared with the app's Widget Extension.
133
+ RCT_EXPORT_METHOD(initializeWithAppGroup:(NSString *)sdkKey baseUrl:(NSString *)baseUrl appGroup:(NSString *)appGroup)
134
+ {
135
+ [self startWithSdkKey:sdkKey baseUrl:baseUrl appGroup:appGroup];
136
+ }
137
+
138
+ // Records a live activity tap and resolves to the activity's own link (nil when it has none); other URLs unchanged.
139
+ RCT_EXPORT_METHOD(handleLiveActivityURL:(NSString *)url
140
+ resolve:(RCTPromiseResolveBlock)resolve
141
+ reject:(RCTPromiseRejectBlock)reject)
142
+ {
143
+ resolve([RNPushPilotBridge handleLiveActivityURL:url]);
144
+ }
145
+
146
+ // Shows a cached in-app message on the main thread, where the SDK requires it, and resolves whether one is on screen.
147
+ RCT_EXPORT_METHOD(showInApp:(NSString *)name
148
+ resolve:(RCTPromiseResolveBlock)resolve
149
+ reject:(RCTPromiseRejectBlock)reject)
150
+ {
151
+ dispatch_async(dispatch_get_main_queue(), ^{
152
+ resolve(@([RNPushPilotBridge showInApp:name]));
153
+ });
154
+ }
155
+
156
+ // Looks the view up by its React tag on the main thread, after views already queued for mounting, and names it
157
+ // for coach marks. A tag with no native view is logged and ignored.
158
+ RCT_EXPORT_METHOD(markView:(double)viewTag name:(NSString *)name)
159
+ {
160
+ [self.viewRegistry_DEPRECATED addUIBlock:^(RCTViewRegistry *registry) {
161
+ UIView *view = [registry viewForReactTag:@(viewTag)];
162
+ if (view) {
163
+ [RNPushPilotBridge markView:view name:name];
164
+ } else {
165
+ NSLog(@"[PushPilot] markView ignored: no native view for that ref (is it mounted, with collapsable={false}?)");
166
+ }
167
+ }];
168
+ }
169
+
170
+ // Forgets the named view; on the main queue like markView, so an earlier mark never lands after it.
171
+ RCT_EXPORT_METHOD(unmarkView:(NSString *)name)
172
+ {
173
+ dispatch_async(dispatch_get_main_queue(), ^{
174
+ [RNPushPilotBridge unmarkViewWithName:name];
175
+ });
176
+ }
177
+
178
+ // The work of both initialize calls; a nil App Group means none.
179
+ - (void)startWithSdkKey:(NSString *)sdkKey baseUrl:(NSString *)baseUrl appGroup:(NSString *)appGroup
180
+ {
181
+ [RNPushPilotBridge startWithSdkKey:sdkKey baseUrl:baseUrl appGroup:appGroup];
130
182
  dispatch_async(dispatch_get_main_queue(), ^{
131
183
  tapModule = self;
132
184
  NSArray *waiting = [waitingTaps copy];
@@ -155,6 +207,12 @@ RCT_EXPORT_METHOD(setAttributes:(NSDictionary *)attributes)
155
207
  [RNPushPilotBridge setAttributes:attributes];
156
208
  }
157
209
 
210
+ // Forwards a custom event; the SDK validates, stores and batches it.
211
+ RCT_EXPORT_METHOD(track:(NSString *)name properties:(NSDictionary *)properties)
212
+ {
213
+ [RNPushPilotBridge track:name properties:properties];
214
+ }
215
+
158
216
  // Forwards the topic list; the SDK validates the names.
159
217
  RCT_EXPORT_METHOD(setTopics:(NSArray *)topics)
160
218
  {
@@ -1,5 +1,6 @@
1
1
  import Foundation
2
2
  import PushPilot
3
+ import UIKit
3
4
  import UserNotifications
4
5
 
5
6
  /// Calls the Swift-only PushPilot SDK for the Objective-C++ module, which cannot import it directly.
@@ -7,10 +8,18 @@ import UserNotifications
7
8
  @objc(RNPushPilotBridge)
8
9
  public final class RNPushPilotBridge: NSObject {
9
10
  /// Starts the SDK. A base URL that is not a URL is logged and ignored rather than silently using the default server.
10
- @objc public static func start(sdkKey: String, baseUrl: String?) {
11
- guard let baseUrl else { return PushPilot.initialize(sdkKey: sdkKey) }
11
+ /// `appGroup` is the App Group shared with the Widget Extension, or nil.
12
+ @objc public static func start(sdkKey: String, baseUrl: String?, appGroup: String?) {
13
+ guard let baseUrl else { return PushPilot.initialize(sdkKey: sdkKey, appGroup: appGroup) }
12
14
  guard let url = URL(string: baseUrl) else { return NSLog("[PushPilot] init ignored: baseUrl is not a URL") }
13
- PushPilot.initialize(sdkKey: sdkKey, baseUrl: url)
15
+ PushPilot.initialize(sdkKey: sdkKey, baseUrl: url, appGroup: appGroup)
16
+ }
17
+
18
+ /// For a URL the app opened: a live activity tap is recorded and its own link returned (nil when it has
19
+ /// none). Any other URL, including one that does not parse, comes back unchanged.
20
+ @objc public static func handleLiveActivityURL(_ url: String) -> String? {
21
+ guard let parsed = URL(string: url) else { return url }
22
+ return PushPilot.handleLiveActivityURL(parsed)?.absoluteString
14
23
  }
15
24
 
16
25
  /// Call from `application(_:didRegisterForRemoteNotificationsWithDeviceToken:)` with the token as iOS gives it.
@@ -38,6 +47,11 @@ public final class RNPushPilotBridge: NSObject {
38
47
  PushPilot.setAttributes(attributes)
39
48
  }
40
49
 
50
+ /// Forwards a custom event; the SDK validates the name and property values and batches the event.
51
+ @objc public static func track(_ name: String, properties: [String: Any]) {
52
+ PushPilot.track(name, properties: properties)
53
+ }
54
+
41
55
  /// Forwards the topic list, keeping only strings.
42
56
  @objc public static func setTopics(_ topics: [Any]) {
43
57
  PushPilot.setTopics(topics.compactMap { $0 as? String })
@@ -59,6 +73,21 @@ public final class RNPushPilotBridge: NSObject {
59
73
  RNPushPilotNotifications.handle(response)
60
74
  }
61
75
 
76
+ /// Shows the first eligible cached in-app message with this trigger name; returns whether one is on screen.
77
+ @MainActor @objc public static func showInApp(_ name: String) -> Bool {
78
+ PushPilot.showInApp(name)
79
+ }
80
+
81
+ /// Names a view for coach-mark messages whose target is `name`; the SDK holds it weakly.
82
+ @MainActor @objc public static func markView(_ view: UIView, name: String) {
83
+ PushPilot.markView(view, name: name)
84
+ }
85
+
86
+ /// Forgets the view marked with `name`.
87
+ @MainActor @objc public static func unmarkView(name: String) {
88
+ PushPilot.unmarkView(name: name)
89
+ }
90
+
62
91
  /// Sends the links of tapped PushPilot pushes to `handler` on the main thread instead of opening them.
63
92
  @objc public static func setLinkHandler(_ handler: @escaping (URL) -> Void) {
64
93
  PushPilot.setLinkHandler(handler)
@@ -1 +1 @@
1
- {"version":3,"names":["TurboModuleRegistry","get"],"sourceRoot":"../../src","sources":["NativePushPilot.ts"],"mappings":";;AAAA,SACEA,mBAAmB,QAGd,cAAc;;AAErB;;AAkBA;AACA,eAAeA,mBAAmB,CAACC,GAAG,CAAO,WAAW,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["TurboModuleRegistry","get"],"sourceRoot":"../../src","sources":["NativePushPilot.ts"],"mappings":";;AAAA,SACEA,mBAAmB,QAGd,cAAc;;AAErB;;AAiCA;AACA,eAAeA,mBAAmB,CAACC,GAAG,CAAO,WAAW,CAAC","ignoreList":[]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- import { NativeEventEmitter, Platform } from 'react-native';
3
+ import { NativeEventEmitter, Platform, findNodeHandle } from 'react-native';
4
4
  import Native from "./NativePushPilot.js";
5
5
 
6
6
  /** A custom attribute value; `null` removes the attribute. Pass dates as RFC 3339 strings. */
@@ -38,7 +38,24 @@ function setHandler(event, handler, enable) {
38
38
  const PushPilot = {
39
39
  /** Starts the SDK with the app's public SDK key. Later calls are ignored; earlier calls are queued. */
40
40
  init(sdkKey, options) {
41
- call('init', n => n.initialize(sdkKey, options?.baseUrl ?? null));
41
+ const baseUrl = options?.baseUrl ?? null;
42
+ const appGroup = options?.appGroup;
43
+ call('init', n => appGroup ? n.initializeWithAppGroup(sdkKey, baseUrl, appGroup) : n.initialize(sdkKey, baseUrl));
44
+ },
45
+ /**
46
+ * Pass every URL your app is opened with (React Native's `Linking`). For a tap on an iOS live
47
+ * activity it records the click once and resolves to the activity's own link without PushPilot's
48
+ * marker, or `null` when the activity has none (just show the app). Any other URL, and every URL on
49
+ * Android, resolves unchanged. Never rejects: on a failure it resolves to the URL as given.
50
+ */
51
+ async handleLiveActivityURL(url) {
52
+ try {
53
+ if (Native) return await Native.handleLiveActivityURL(url);
54
+ console.warn('[PushPilot] handleLiveActivityURL ignored: the native module is not linked. Rebuild the app (Expo Go is not supported).');
55
+ } catch (e) {
56
+ console.warn(`[PushPilot] handleLiveActivityURL failed: ${String(e)}`);
57
+ }
58
+ return url;
42
59
  },
43
60
  /**
44
61
  * Passes the push identifier; `null` clears it.
@@ -64,6 +81,13 @@ const PushPilot = {
64
81
  setAttributes(attributes) {
65
82
  call('setAttributes', n => n.setAttributes(attributes));
66
83
  },
84
+ /**
85
+ * Records a custom event such as `order_placed`. Names are snake_case, at most 40 characters;
86
+ * property values are strings, numbers or booleans. The native SDK stores and sends events in batches.
87
+ */
88
+ track(name, properties) {
89
+ call('track', n => n.track(name, properties ?? {}));
90
+ },
67
91
  /** Replaces this installation's topic list. */
68
92
  setTopics(topics) {
69
93
  call('setTopics', n => n.setTopics(topics));
@@ -91,6 +115,38 @@ const PushPilot = {
91
115
  setTapHandler(handler) {
92
116
  setHandler('PushPilotTap', handler, (n, on) => n.setTapHandlerEnabled(on));
93
117
  },
118
+ /**
119
+ * Shows the first eligible cached in-app message whose trigger name is `name` and resolves to whether
120
+ * one is now on screen: `false` when none is cached and eligible, another message is showing, or the
121
+ * SDK has not started. No network call. Never rejects: on a failure it resolves to `false`.
122
+ */
123
+ async showInApp(name) {
124
+ try {
125
+ if (Native) return await Native.showInApp(name);
126
+ console.warn('[PushPilot] showInApp ignored: the native module is not linked. Rebuild the app (Expo Go is not supported).');
127
+ } catch (e) {
128
+ console.warn(`[PushPilot] showInApp failed: ${String(e)}`);
129
+ }
130
+ return false;
131
+ },
132
+ /**
133
+ * Names a mounted view for coach-mark messages whose target is `name`: pass its `ref` (or a view tag
134
+ * from `findNodeHandle`). Give a plain `<View>` `collapsable={false}` so it has a native view. The SDK
135
+ * holds the view weakly; a later view with the same name replaces it.
136
+ */
137
+ // `any`: refs of every host component type (View, Pressable, TextInput...) are accepted.
138
+ markView(ref, name) {
139
+ const tag = typeof ref === 'number' ? ref : findNodeHandle(ref.current);
140
+ if (tag == null) {
141
+ console.warn('[PushPilot] markView ignored: the ref has no mounted native view yet.');
142
+ return;
143
+ }
144
+ call('markView', n => n.markView(tag, name));
145
+ },
146
+ /** Forgets the view marked with `name`. */
147
+ unmarkView(name) {
148
+ call('unmarkView', n => n.unmarkView(name));
149
+ },
94
150
  /** True when a received push's data came from PushPilot. Same rule as the native SDKs; no native call. */
95
151
  handleMessage(data) {
96
152
  return data?.source === 'pushpilot';
@@ -1 +1 @@
1
- {"version":3,"names":["NativeEventEmitter","Platform","Native","call","name","run","console","warn","e","String","APNS_HEX","subscriptions","setHandler","event","handler","enable","n","remove","addListener","undefined","PushPilot","init","sdkKey","options","initialize","baseUrl","setPushToken","token","OS","test","setExternalUserId","id","setAttributes","attributes","setTopics","topics","logout","forget","setLinkHandler","on","setLinkHandlerEnabled","setTapHandler","setTapHandlerEnabled","handleMessage","data","source"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SACEA,kBAAkB,EAClBC,QAAQ,QAEH,cAAc;AACrB,OAAOC,MAAM,MAAqB,sBAAmB;;AAErD;;AAGA;;AAQA;;AAMA;AACA,SAASC,IAAIA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AAE,CAAC,CAAC;EAC5E,CAAC;EAED;EACAI,aAAaA,CAACC,IAAmD,EAAW;IAC1E,OAAOA,IAAI,EAAEC,MAAM,KAAK,WAAW;EACrC;AACF,CAAC;AAED,eAAezB,SAAS","ignoreList":[]}
1
+ {"version":3,"names":["NativeEventEmitter","Platform","findNodeHandle","Native","call","name","run","console","warn","e","String","APNS_HEX","subscriptions","setHandler","event","handler","enable","n","remove","addListener","undefined","PushPilot","init","sdkKey","options","baseUrl","appGroup","initializeWithAppGroup","initialize","handleLiveActivityURL","url","setPushToken","token","OS","test","setExternalUserId","id","setAttributes","attributes","track","properties","setTopics","topics","logout","forget","setLinkHandler","on","setLinkHandlerEnabled","setTapHandler","setTapHandlerEnabled","showInApp","markView","ref","tag","current","unmarkView","handleMessage","data","source"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AACA,SACEA,kBAAkB,EAClBC,QAAQ,EACRC,cAAc,QAET,cAAc;AACrB,OAAOC,MAAM,MAAqB,sBAAmB;;AAErD;;AAGA;;AAQA;;AAWA;AACA,SAASC,IAAIA,CAACC,IAAY,EAAEC,GAA2B,EAAQ;EAC7D,IAAI;IACF,IAAIH,MAAM,EAAE;MACVG,GAAG,CAACH,MAAM,CAAC;IACb,CAAC,MAAM;MACLI,OAAO,CAACC,IAAI,CACV,eAAeH,IAAI,wFACrB,CAAC;IACH;EACF,CAAC,CAAC,OAAOI,CAAC,EAAE;IACVF,OAAO,CAACC,IAAI,CAAC,eAAeH,IAAI,YAAYK,MAAM,CAACD,CAAC,CAAC,EAAE,CAAC;EAC1D;AACF;;AAEA;AACA,MAAME,QAAQ,GAAG,uBAAuB;AAIxC;AACA,MAAMC,aAA4D,GAAG,CAAC,CAAC;;AAEvE;AACA,SAASC,UAAUA,CACjBC,KAAQ,EACRC,OAA8C,EAC9CC,MAAgD,EAC1C;EACNZ,IAAI,CAACU,KAAK,KAAK,eAAe,GAAG,gBAAgB,GAAG,eAAe,EAAGG,CAAC,IAAK;IAC1EL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  import { type CodegenTypes, type TurboModule } from 'react-native';
2
2
  export interface Spec extends TurboModule {
3
3
  initialize(sdkKey: string, baseUrl: string | null): void;
4
+ initializeWithAppGroup(sdkKey: string, baseUrl: string | null, appGroup: string): void;
5
+ handleLiveActivityURL(url: string): Promise<string | null>;
4
6
  setPushToken(token: string | null): void;
5
7
  setExternalUserId(id: string | null): void;
6
8
  setAttributes(attributes: CodegenTypes.UnsafeObject): void;
7
9
  setTopics(topics: string[]): void;
10
+ track(name: string, properties: CodegenTypes.UnsafeObject): void;
8
11
  logout(): void;
9
12
  forget(): void;
13
+ showInApp(name: string): Promise<boolean>;
14
+ markView(viewTag: number, name: string): void;
15
+ unmarkView(name: string): void;
10
16
  setLinkHandlerEnabled(enabled: boolean): void;
11
17
  setTapHandlerEnabled(enabled: boolean): void;
12
18
  addListener(eventName: string): void;
@@ -1 +1 @@
1
- {"version":3,"file":"NativePushPilot.d.ts","sourceRoot":"","sources":["../../../src/NativePushPilot.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,WAAW,EACjB,MAAM,cAAc,CAAC;AAGtB,MAAM,WAAW,IAAK,SAAQ,WAAW;IAEvC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IACzD,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IACzC,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAC3C,aAAa,CAAC,UAAU,EAAE,YAAY,CAAC,YAAY,GAAG,IAAI,CAAC;IAC3D,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAClC,MAAM,IAAI,IAAI,CAAC;IACf,MAAM,IAAI,IAAI,CAAC;IAEf,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAC9C,oBAAoB,CAAC,OAAO,EA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,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAE/B,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAC9C,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAE7C,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC;;AAGD,wBAA0D"}
@@ -1,3 +1,4 @@
1
+ import type { RefObject } from 'react';
1
2
  /** A custom attribute value; `null` removes the attribute. Pass dates as RFC 3339 strings. */
2
3
  export type AttributeValue = string | number | boolean | null;
3
4
  /** A tapped PushPilot push that opened the app. */
@@ -11,10 +12,22 @@ export interface TappedNotification {
11
12
  export interface InitOptions {
12
13
  /** Your own server, for self-hosted PushPilot. Defaults to https://pushpilot.ai. */
13
14
  baseUrl?: string;
15
+ /**
16
+ * iOS: the App Group shared with your Widget Extension, so images in live activity layouts can be
17
+ * shown. Pass the same id to `PushPilotLiveActivityWidget(appGroup:)`. Ignored on Android.
18
+ */
19
+ appGroup?: string;
14
20
  }
15
21
  declare const PushPilot: {
16
22
  /** Starts the SDK with the app's public SDK key. Later calls are ignored; earlier calls are queued. */
17
23
  init(sdkKey: string, options?: InitOptions): void;
24
+ /**
25
+ * Pass every URL your app is opened with (React Native's `Linking`). For a tap on an iOS live
26
+ * activity it records the click once and resolves to the activity's own link without PushPilot's
27
+ * marker, or `null` when the activity has none (just show the app). Any other URL, and every URL on
28
+ * Android, resolves unchanged. Never rejects: on a failure it resolves to the URL as given.
29
+ */
30
+ handleLiveActivityURL(url: string): Promise<string | null>;
18
31
  /**
19
32
  * Passes the push identifier; `null` clears it.
20
33
  * - Android: the Firebase Installation ID from `register` / `onRegistered` where your Firebase
@@ -29,6 +42,11 @@ declare const PushPilot: {
29
42
  setExternalUserId(id: string | null): void;
30
43
  /** Merges custom attributes declared in the dashboard. */
31
44
  setAttributes(attributes: Record<string, AttributeValue>): void;
45
+ /**
46
+ * Records a custom event such as `order_placed`. Names are snake_case, at most 40 characters;
47
+ * property values are strings, numbers or booleans. The native SDK stores and sends events in batches.
48
+ */
49
+ track(name: string, properties?: Record<string, string | number | boolean | null>): void;
32
50
  /** Replaces this installation's topic list. */
33
51
  setTopics(topics: string[]): void;
34
52
  /** Clears the external user id; the device stays registered and keeps receiving pushes. */
@@ -46,6 +64,20 @@ declare const PushPilot: {
46
64
  * Set it before `init` to also get the tap that launched the app; each tap arrives once.
47
65
  */
48
66
  setTapHandler(handler: ((tap: TappedNotification) => void) | null): void;
67
+ /**
68
+ * Shows the first eligible cached in-app message whose trigger name is `name` and resolves to whether
69
+ * one is now on screen: `false` when none is cached and eligible, another message is showing, or the
70
+ * SDK has not started. No network call. Never rejects: on a failure it resolves to `false`.
71
+ */
72
+ showInApp(name: string): Promise<boolean>;
73
+ /**
74
+ * Names a mounted view for coach-mark messages whose target is `name`: pass its `ref` (or a view tag
75
+ * from `findNodeHandle`). Give a plain `<View>` `collapsable={false}` so it has a native view. The SDK
76
+ * holds the view weakly; a later view with the same name replaces it.
77
+ */
78
+ markView(ref: RefObject<any> | number, name: string): void;
79
+ /** Forgets the view marked with `name`. */
80
+ unmarkView(name: string): void;
49
81
  /** True when a received push's data came from PushPilot. Same rule as the native SDKs; no native call. */
50
82
  handleMessage(data: {
51
83
  [key: string]: unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAOA,8FAA8F;AAC9F,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAE9D,mDAAmD;AACnD,MAAM,WAAW,kBAAkB;IACjC,0EAA0E;IAC1E,cAAc,EAAE,MAAM,CAAC;IACvB,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED,oCAAoC;AACpC,MAAM,WAAW,W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.0.0",
3
+ "version": "2.3.0",
4
4
  "description": "PushPilot push notifications for React Native",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -8,12 +8,27 @@ import {
8
8
  export interface Spec extends TurboModule {
9
9
  // Named `initialize` because Objective-C reserves methods starting with `init`.
10
10
  initialize(sdkKey: string, baseUrl: string | null): void;
11
+ // `initialize` plus the App Group shared with the iOS Widget Extension; Android ignores the group.
12
+ initializeWithAppGroup(
13
+ sdkKey: string,
14
+ baseUrl: string | null,
15
+ appGroup: string
16
+ ): void;
17
+ // The link of a live activity tap without PushPilot's marker, or null; other URLs come back unchanged.
18
+ handleLiveActivityURL(url: string): Promise<string | null>;
11
19
  setPushToken(token: string | null): void;
12
20
  setExternalUserId(id: string | null): void;
13
21
  setAttributes(attributes: CodegenTypes.UnsafeObject): void;
14
22
  setTopics(topics: string[]): void;
23
+ // Queues a custom event; the native SDK validates, stores and batches it.
24
+ track(name: string, properties: CodegenTypes.UnsafeObject): void;
15
25
  logout(): void;
16
26
  forget(): void;
27
+ // The first eligible cached in-app message with this trigger name; resolves whether it is now on screen.
28
+ showInApp(name: string): Promise<boolean>;
29
+ // Names the native view with this React tag (from findNodeHandle) for coach-mark messages, or forgets one.
30
+ markView(viewTag: number, name: string): void;
31
+ unmarkView(name: string): void;
17
32
  // Whether JavaScript has a link handler / tap handler; native sends those events only while it does.
18
33
  setLinkHandlerEnabled(enabled: boolean): void;
19
34
  setTapHandlerEnabled(enabled: boolean): void;
package/src/index.tsx CHANGED
@@ -1,6 +1,8 @@
1
+ import type { RefObject } from 'react';
1
2
  import {
2
3
  NativeEventEmitter,
3
4
  Platform,
5
+ findNodeHandle,
4
6
  type EmitterSubscription,
5
7
  } from 'react-native';
6
8
  import Native, { type Spec } from './NativePushPilot';
@@ -20,6 +22,11 @@ export interface TappedNotification {
20
22
  export interface InitOptions {
21
23
  /** Your own server, for self-hosted PushPilot. Defaults to https://pushpilot.ai. */
22
24
  baseUrl?: string;
25
+ /**
26
+ * iOS: the App Group shared with your Widget Extension, so images in live activity layouts can be
27
+ * shown. Pass the same id to `PushPilotLiveActivityWidget(appGroup:)`. Ignored on Android.
28
+ */
29
+ appGroup?: string;
23
30
  }
24
31
 
25
32
  // Runs one native call, logging instead of throwing so the SDK can never crash the app.
@@ -63,7 +70,31 @@ function setHandler<E extends keyof Events>(
63
70
  const PushPilot = {
64
71
  /** Starts the SDK with the app's public SDK key. Later calls are ignored; earlier calls are queued. */
65
72
  init(sdkKey: string, options?: InitOptions): void {
66
- call('init', (n) => n.initialize(sdkKey, options?.baseUrl ?? null));
73
+ const baseUrl = options?.baseUrl ?? null;
74
+ const appGroup = options?.appGroup;
75
+ call('init', (n) =>
76
+ appGroup
77
+ ? n.initializeWithAppGroup(sdkKey, baseUrl, appGroup)
78
+ : n.initialize(sdkKey, baseUrl)
79
+ );
80
+ },
81
+
82
+ /**
83
+ * Pass every URL your app is opened with (React Native's `Linking`). For a tap on an iOS live
84
+ * activity it records the click once and resolves to the activity's own link without PushPilot's
85
+ * marker, or `null` when the activity has none (just show the app). Any other URL, and every URL on
86
+ * Android, resolves unchanged. Never rejects: on a failure it resolves to the URL as given.
87
+ */
88
+ async handleLiveActivityURL(url: string): Promise<string | null> {
89
+ try {
90
+ if (Native) return await Native.handleLiveActivityURL(url);
91
+ console.warn(
92
+ '[PushPilot] handleLiveActivityURL ignored: the native module is not linked. Rebuild the app (Expo Go is not supported).'
93
+ );
94
+ } catch (e) {
95
+ console.warn(`[PushPilot] handleLiveActivityURL failed: ${String(e)}`);
96
+ }
97
+ return url;
67
98
  },
68
99
 
69
100
  /**
@@ -95,6 +126,17 @@ const PushPilot = {
95
126
  call('setAttributes', (n) => n.setAttributes(attributes));
96
127
  },
97
128
 
129
+ /**
130
+ * Records a custom event such as `order_placed`. Names are snake_case, at most 40 characters;
131
+ * property values are strings, numbers or booleans. The native SDK stores and sends events in batches.
132
+ */
133
+ track(
134
+ name: string,
135
+ properties?: Record<string, string | number | boolean | null>
136
+ ): void {
137
+ call('track', (n) => n.track(name, properties ?? {}));
138
+ },
139
+
98
140
  /** Replaces this installation's topic list. */
99
141
  setTopics(topics: string[]): void {
100
142
  call('setTopics', (n) => n.setTopics(topics));
@@ -129,6 +171,45 @@ const PushPilot = {
129
171
  setHandler('PushPilotTap', handler, (n, on) => n.setTapHandlerEnabled(on));
130
172
  },
131
173
 
174
+ /**
175
+ * Shows the first eligible cached in-app message whose trigger name is `name` and resolves to whether
176
+ * one is now on screen: `false` when none is cached and eligible, another message is showing, or the
177
+ * SDK has not started. No network call. Never rejects: on a failure it resolves to `false`.
178
+ */
179
+ async showInApp(name: string): Promise<boolean> {
180
+ try {
181
+ if (Native) return await Native.showInApp(name);
182
+ console.warn(
183
+ '[PushPilot] showInApp ignored: the native module is not linked. Rebuild the app (Expo Go is not supported).'
184
+ );
185
+ } catch (e) {
186
+ console.warn(`[PushPilot] showInApp failed: ${String(e)}`);
187
+ }
188
+ return false;
189
+ },
190
+
191
+ /**
192
+ * Names a mounted view for coach-mark messages whose target is `name`: pass its `ref` (or a view tag
193
+ * from `findNodeHandle`). Give a plain `<View>` `collapsable={false}` so it has a native view. The SDK
194
+ * holds the view weakly; a later view with the same name replaces it.
195
+ */
196
+ // `any`: refs of every host component type (View, Pressable, TextInput...) are accepted.
197
+ markView(ref: RefObject<any> | number, name: string): void {
198
+ const tag = typeof ref === 'number' ? ref : findNodeHandle(ref.current);
199
+ if (tag == null) {
200
+ console.warn(
201
+ '[PushPilot] markView ignored: the ref has no mounted native view yet.'
202
+ );
203
+ return;
204
+ }
205
+ call('markView', (n) => n.markView(tag, name));
206
+ },
207
+
208
+ /** Forgets the view marked with `name`. */
209
+ unmarkView(name: string): void {
210
+ call('unmarkView', (n) => n.unmarkView(name));
211
+ },
212
+
132
213
  /** True when a received push's data came from PushPilot. Same rule as the native SDKs; no native call. */
133
214
  handleMessage(data: { [key: string]: unknown } | null | undefined): boolean {
134
215
  return data?.source === 'pushpilot';