@oneuptime/react-native-replay 16.0.0 → 17.1.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.
package/README.md CHANGED
@@ -128,8 +128,8 @@ await OneUptimeReplay.revokeConsent();
128
128
  ```
129
129
 
130
130
  Revocation stops capture and clears the in-memory buffer, session identifier,
131
- anonymous visitor identifier, and AsyncStorage outbox. A later grant starts a
132
- new visit.
131
+ anonymous visitor identifier, AsyncStorage outbox, and the product analytics
132
+ events kept unsent. A later grant starts a new visit.
133
133
 
134
134
  ## Identity, tags, events, and routes
135
135
 
@@ -142,6 +142,7 @@ OneUptimeReplay.identify("support-user-42", {
142
142
  OneUptimeReplay.setTags({ build: "2026.09.13", experiment: "checkout-b" });
143
143
  OneUptimeReplay.addTag("region", "eu-west");
144
144
  OneUptimeReplay.track("checkout_opened", { cartSize: 3 });
145
+ OneUptimeReplay.metric("cart.value", 42.5, { currency: "EUR" });
145
146
 
146
147
  // Call from the navigation container's state-change callback.
147
148
  await OneUptimeReplay.setRoute("/checkout?payment_token=discarded");
@@ -159,13 +160,81 @@ Identity and traits are sent only when the RUM application's policy enables
159
160
  user-identity capture. Under mobile's mandatory `MaskAllText`, trait values,
160
161
  custom-event property values, and manual-capture reasons use the same coarse
161
162
  text masks as the browser recorder. Event names and the explicitly supplied
162
- user reference stay readable. Tag values deliberately stay readable and
163
+ user reference stay readable. So does a custom-event property or metric
164
+ attribute whose key the application lists under **Readable event
165
+ properties** on its Replay Policy page, while its value is a short token
166
+ (letters, digits and `_ . : / -`, at most 32 characters); any other value
167
+ under that key is still masked, and traits always are. Tag values deliberately stay readable and
163
168
  searchable, matching the browser contract; do not use tags for secrets. All
164
169
  maps remain count/length bounded. Routes always drop query strings and
165
170
  fragments and are stored as `app://com.example.checkout/checkout`. The
166
171
  remaining path stays readable, so pass stable screen templates rather than
167
172
  account names, order numbers, or other sensitive path values.
168
173
 
174
+ ## Product analytics events and metrics
175
+
176
+ With **Send product analytics events** on for the RUM application (its
177
+ **Analytics Settings** page in OneUptime), the SDK also sends the
178
+ application's product analytics: the session's start, each screen
179
+ `setRoute()` names as a page view, every `track()` event, and the numbers
180
+ the app measures with `metric()`:
181
+
182
+ ```ts
183
+ OneUptimeReplay.track("checkout_opened", { cartSize: 3 });
184
+ OneUptimeReplay.metric("cart.value", 42.5, { currency: "EUR" });
185
+ ```
186
+
187
+ They feed the application's **Events**, **Funnels** and **User Retention**
188
+ pages, and a `metric()` point is a point of a metric of the application's,
189
+ for charts, dashboards and Metrics monitors. They follow the browser
190
+ recorder's contract (`Common/Types/Rum/ProductAnalyticsEvents.ts`, copied
191
+ in `src/ProductAnalyticsContract.ts` and held to it by `ContractParity`):
192
+
193
+ - **Every session, recorded or not.** The replay sample decides which
194
+ sessions are recorded, not which are counted: a session it leaves out
195
+ still sends its events (`start()` still resolves `false` for it, as
196
+ before), and those events are what keeps its session alive.
197
+ - **Consent.** When the policy requires consent, events wait for
198
+ `grantConsent()`, at most 500 of them, and are then filed under the
199
+ session the grant opens; `revokeConsent()` drops them.
200
+ - **Masked as the recording is.** The SDK always masks text, so property,
201
+ attribute and trait values arrive masked; event names, keys and metric
202
+ values are sent as written. A screen is its scrubbed route. A property or
203
+ attribute whose key the application lists as a readable event property
204
+ keeps a short token value as written, as the recording's marker does.
205
+ - **Small batches.** Every 5 seconds and as the app leaves the foreground,
206
+ at most 100 events and 100 metric points each, one session's and one
207
+ person's per batch. A failed batch is retried with backoff up to 5 minutes
208
+ (a `Retry-After` is honoured up to 300 seconds), at once when the app
209
+ returns to the foreground or a `connectivity` source says the device is
210
+ back online, and nothing is tried while it says the device is offline.
211
+ A batch sent again says when it was sent again, so its events are filed
212
+ when they happened. A 204, 400 or 403 stops them until the next `start()`,
213
+ and drops what was held.
214
+ - **Kept across a relaunch.** What has not been sent is also kept in
215
+ AsyncStorage, under its own key: an app used offline (on a plane, in a
216
+ tunnel) and then killed, or stopped by the system in the background, sends
217
+ those events and metric points after its next `start()`, under the session
218
+ and the person they happened under, and the batch that was on its way
219
+ under its own id. It is written a second after a change and at once as the
220
+ app leaves the foreground, holds at most 500 events and 500 metric points
221
+ in at most 512 KB (the oldest left out first), and drops what is older
222
+ than the server's 3 days before sending. Nothing held before a required
223
+ consent is written, and `revokeConsent()` - or a policy that starts
224
+ requiring consent - deletes it.
225
+ - **The context** is the one recorded sessions are filed under: `mobile`,
226
+ or `tablet` from a shorter side of 600 points; the system the native
227
+ module names; and the `appVersion` start option, or the binary's own.
228
+ - **Diagnostics.** `getDiagnostics().productAnalytics` reports `state`
229
+ (`off`, `on`, or why they stopped), `pending` (what waits to be sent,
230
+ what a relaunch brought back included) and `dropped` (events dropped
231
+ because too many waited, or they waited longer than 3 days); the codes
232
+ `analytics-started`, `analytics-restored`, `analytics-store-unreadable`,
233
+ `analytics-stopped`, `metric-analytics-off`, `metric-name-refused` and
234
+ `metric-value-refused` say what happened.
235
+
236
+ `metric()` sends nothing while the events are off for the application.
237
+
169
238
  ## Manual and error capture
170
239
 
171
240
  ```ts
@@ -187,20 +256,33 @@ pre-roll is uploaded after a manual or JavaScript error trigger.
187
256
  ## Frustration signals of your own
188
257
 
189
258
  A RUM application can name signals of its own on its **Frustration Signals**
190
- page in OneUptime, and this SDK detects three kinds of them with no code change:
259
+ page in OneUptime, and this SDK detects four kinds of them with no code change:
191
260
 
192
- | signal | fires when |
193
- | ------ | ---------------------------------------------------------------------------------------------------------------------------------- |
194
- | page | `setRoute()` moves to a route whose path matches the pattern (`*` stands for any characters; case, query and fragment are ignored) |
195
- | event | `track()` is called with that event name (case is ignored) |
196
- | error | a JavaScript error or `captureError()` carries a message containing the given words (case is ignored) |
261
+ | signal | fires when |
262
+ | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
263
+ | tap | a tap lands on a view whose `testID` is the one named, or starts with it when the pattern ends in `*` (`product-card-*`), or on anything inside it (case is ignored) |
264
+ | page | `setRoute()` moves to a route whose path matches the pattern (`*` stands for any characters; case, query and fragment are ignored) |
265
+ | event | `track()` is called with that event name (case is ignored) |
266
+ | error | a JavaScript error or `captureError()` carries a message containing the given words (case is ignored) |
197
267
 
198
268
  A hit is recorded as a marker carrying the signal's **name** only - never the
199
- route, the event's properties or the error's text, which are only compared on
200
- the device - and counted on the chunk. A signal that counts as frustration
201
- starts the upload in error-triggered mode, like an error. The same name fires
202
- at most once a second, and a chunk holds at most 50 markers. Nothing is
203
- detected while capture is paused because nobody is using the app.
269
+ route, the event's properties, the error's text or a view's `testID`, which
270
+ are only compared on the device - and counted on the chunk. A tap signal's
271
+ marker also says where on the screen the tap was, as the recorded touch does,
272
+ except on a view inside a `ReplayMask`, an image, a web view or another view
273
+ the replay never records. A signal that counts as frustration starts the
274
+ upload in error-triggered mode, like an error. The same name fires at most
275
+ once a second, and a chunk holds at most 50 markers. Nothing is detected while
276
+ capture is paused because nobody is using the app.
277
+
278
+ A tap is a touch that ends within 10 points of where it started, on the view
279
+ it started on: a finger that slides further was scrolling. Give the views you
280
+ want to name a `testID` (`<Pressable testID="pay-button">`): the SDK reads the
281
+ touched view's `testID` and those of the views around it from the native
282
+ module, so a tap on a label inside a named button is a tap on the button. A
283
+ binary built with an older version of this SDK's native code (a JavaScript-only
284
+ over-the-air update) detects no tap signal and records everything else as
285
+ before.
204
286
 
205
287
  Signals that react to a click on an element are CSS selectors on a web page,
206
288
  and the built-in rage, dead and error clicks and refresh rage are about a mouse
@@ -210,7 +292,8 @@ on a web page: the browser recorder detects those, and this SDK leaves them out.
210
292
 
211
293
  ```ts
212
294
  const diagnostics = OneUptimeReplay.getDiagnostics();
213
- // status, sessionId, sampled, triggered, consentState, pendingEvents, events
295
+ // status, sessionId, sampled, triggered, consentState, pendingEvents,
296
+ // productAnalytics, events
214
297
  ```
215
298
 
216
299
  Diagnostics contain recorder decisions and fixed reason codes, not view text.
@@ -35,6 +35,9 @@ public final class OneUptimeReplayViewTreeModule extends ReactContextBaseJavaMod
35
35
  private static final String REPLAY_MASK_TEST_ID = "oneuptime-replay-mask";
36
36
  private static final int MAX_TREE_DEPTH = 64;
37
37
  private static final int MAX_TREE_NODES = 5000;
38
+ /* A tap signal's match is at most 200 characters; a longer testID never matches. */
39
+ private static final int MAX_TAP_TEST_ID_LENGTH = 200;
40
+ private static final int MAX_TAP_TEST_IDS = 32;
38
41
 
39
42
  private static final class TraversalState {
40
43
  int visited = 0;
@@ -166,6 +169,69 @@ public final class OneUptimeReplayViewTreeModule extends ReactContextBaseJavaMod
166
169
  });
167
170
  }
168
171
 
172
+ /*
173
+ * The testIDs of the touched view and of the views around it, out to the
174
+ * replay root, the touched one first: what the application's tap signals
175
+ * are matched against in JavaScript, on the device, and never recorded.
176
+ * Only the testID tag React Native sets is read - no text, content or
177
+ * accessibility label - and nothing is offered for a target outside the
178
+ * replay root or a tag that no longer resolves.
179
+ */
180
+ @ReactMethod
181
+ public void touchTargetTestIds(
182
+ double targetTagValue,
183
+ double replayRootTagValue,
184
+ Promise promise
185
+ ) {
186
+ if (!isReactTag(targetTagValue) || !isReactTag(replayRootTagValue)) {
187
+ promise.resolve(Arguments.createArray());
188
+ return;
189
+ }
190
+
191
+ final int targetTag = (int) targetTagValue;
192
+ final int replayRootTag = (int) replayRootTagValue;
193
+ UiThreadUtil.runOnUiThread(() -> {
194
+ try {
195
+ View target = resolveView(targetTag);
196
+ View replayRoot = resolveView(replayRootTag);
197
+ if (target == null || replayRoot == null) {
198
+ promise.resolve(Arguments.createArray());
199
+ return;
200
+ }
201
+
202
+ WritableArray testIds = Arguments.createArray();
203
+ int found = 0;
204
+ int depth = 0;
205
+ View current = target;
206
+ while (current != null && depth <= MAX_TREE_DEPTH) {
207
+ Object testId = current.getTag(com.facebook.react.R.id.react_test_id);
208
+ if (testId instanceof String && found < MAX_TAP_TEST_IDS) {
209
+ String value = (String) testId;
210
+ if (!value.isEmpty() && value.length() <= MAX_TAP_TEST_ID_LENGTH
211
+ && !REPLAY_MASK_TEST_ID.equals(value)) {
212
+ testIds.pushString(value);
213
+ found += 1;
214
+ }
215
+ }
216
+ if (current == replayRoot) {
217
+ promise.resolve(testIds);
218
+ return;
219
+ }
220
+
221
+ android.view.ViewParent parent = current.getParent();
222
+ current = parent instanceof View ? (View) parent : null;
223
+ depth += 1;
224
+ }
225
+
226
+ /* The event target was not a descendant of this replay root. */
227
+ promise.resolve(Arguments.createArray());
228
+ } catch (Throwable ignored) {
229
+ /* A stale tag or a renderer error matches no tap signal. */
230
+ promise.resolve(Arguments.createArray());
231
+ }
232
+ });
233
+ }
234
+
169
235
  private WritableMap serializeView(
170
236
  View view,
171
237
  int rootX,