Skip to content

[MSUE-242] restore screen tracking (setPageName) - #48

Open
ostfrost wants to merge 12 commits into
SiftScience:masterfrom
ostfrost:MSUE-242-restore-set-page-name
Open

ostfrost wants to merge 12 commits into
SiftScience:masterfrom
ostfrost:MSUE-242-restore-set-page-name

Conversation

@ostfrost

@ostfrost ostfrost commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Restore screen tracking in the React Native SDK with parity between iOS and Android (MSUE-242). The old setPageName was Android-only and was dropped in the RN 0.81 / TurboModule upgrade (PR #47, v1.0.0) without a changelog entry, so today screen names are reported on neither platform. Raised by Reward Gateway.

Summary

New method on the TurboModule spec:

setPageName(pageName: string | null): void;

Contract, identical on both platforms: a sticky screen label that stays attached to later app state collections until it is changed or cleared; each call also requests one collection; null or an empty string clears it and returns to the SDK's automatic value; a call before setSiftConfig collects nothing, and the name is applied once the SDK is configured; the label survives background and foreground.

Both platforms delegate to a native SDK API that owns the label:

  • iOS: [Sift setScreenTitle:] from sift-ios#167 (MSUE-243), followed by collect. setSiftConfig collects when a label is already set, so the first screen is reported right away.
  • Android: Sift.setScreenTitle(String) from sift-android#116, followed by Sift.collect(). Requires sift-android 1.4.0.

The configured flag is kept process-wide (Kotlin companion object, ObjC file statics under @synchronized), because the Sift SDK is a process-wide singleton and a JS reload creates a new module instance.

Why the Android side moved to a new SDK API

The first version of this PR worked with the API Android already had: Sift.open(context, name) to set the label. That had two problems.

  1. No way to clear. Sift.open() and Sift.resume() coalesce a null name to context.getClass().getSimpleName(). So setPageName(null) on Android did not clear the label, it wrote the React context class name, while on iOS nil restores the automatic value. Same call, different meaning per platform. Fixing this by changing the coalescing in the SDK would break the documented per-Activity integration, where Sift.open(this) with no name relies on it, so a separate setter was the only safe option.
  2. Fragile state in the wrapper. Because the label lived in the same field as the automatic Activity name, every Sift.resume() on return from background and every Sift.open() in setSiftConfig overwrote it. The module had to keep its own copy and thread it back through open and resume. That is the exact behaviour that silently broke the old 2022 implementation.

sift-android#116 adds Sift.setScreenTitle(String) with the same shape as iOS: a manual label kept separately from the automatic name, used when set, cleared by null. With it the module no longer stores the name and no longer passes it through open and resume, and null means the same thing on both platforms.

Clearing returns to each SDK's automatic value, and those values differ: on iOS a React Native app has none, so the field is omitted; on Android it is the React context class name, for example BridgelessReactContext. This is documented in the README.

Also: README API reference and usage, CHANGELOG, example app controls, and one unit test asserting the method on the spec surface.

Dependencies

This PR is ready for review but must not be merged before both native releases:

  • Sift iOS SDK release containing sift-ios#167 (setScreenTitle:). Then add a Sift version floor to the podspec, pin it in the example Podfile, refresh the lock, and replace the PR links in README and CHANGELOG with the version.
  • sift-android 1.4.0 containing sift-android#116. The wrapper already pins com.siftscience:sift-android:1.4.0, which will resolve once it is published.

Known limitations

  • The screen name is read at collection time rather than captured at call time on both platforms, so two rapid calls label both events with the second name.
  • On Android with location collection enabled, Sift.collect() produces the event from the location callback, so it can be delayed or skipped.
  • Each call emits one app state event and nothing rate limits it; the README documents one call per screen change.
  • Unrelated cleanup included: the unused import android.text.TextUtils, dead since the 1.0.0 migration.

Testing

Automated: yarn lint, yarn typecheck and yarn test pass.

Android, end to end against sift-android 1.4.0 published to Maven Local from sift-android#116, example app on an API 37 emulator, activity_class_name from logcat:

Step Expected Observed
setPageName('BeforeConfig') before setSiftConfig no event no event
setSiftConfig + upload BeforeConfig BeforeConfig (x2, one per collection)
setPageName('Checkout') Checkout Checkout
Home, back to the app, setSiftConfig + upload Checkout Checkout (x2)
setPageName(null) automatic value BridgelessReactContext

iOS (iPhone 16 Pro simulator, iOS 18.6, sift-ios built from PR #167): ios_app_state carries window_root_view_controller_titles = ["Checkout"], the label survives backgrounding, and null clears it.

Coverage note: the unit test asserts the method on the bridge surface, not the native behaviour. The repo has no Android or iOS test targets and no CI, so native tests are a separate ticket; the native behaviour is covered by the SDKs' own tests (sift-android#116 adds three).

Checklist

  • The change was thoroughly tested manually
  • The change was covered with unit tests (bridge surface only, see above)
  • The change was tested with the integration example
  • The version refers to the latest stable version of sift-android (requires 1.4.0, not yet released, see Dependencies)
  • The version refers to the latest stable version of sift-ios (requires the release containing sift-ios#167, see Dependencies)
  • Necessary changes were made in the integration example
  • New functionality is reflected in README

Restores the screen tracking API that was dropped in 1.0.0, with identical semantics on both platforms: a sticky screen label plus one app state collection per call.
A name reported before configuration was lost; it is now stored and applied once setSiftConfig runs, on both platforms.
The iOS SDK renamed the manual screen label selector in sift-ios#167.
The Sift SDK is a singleton for the life of the process, so module-instance state went stale after a JS reload and left a screen label that JS could no longer clear.
collect only requests a collection and uploads on the normal schedule, clearing is not symmetric across platforms, and the historical note moved out of the released 1.0.0 section.
The property moved into the companion object, so the instance-qualified assignment did not compile.
Android already collects there, so without this the first screen was not reported until an automatic collection.
The three forwarding tests only asserted that a jest mock received what it was just handed.
They claimed success even before setSiftConfig, when the native call does nothing, and CLEAR left the input populated.
@ostfrost
ostfrost marked this pull request as ready for review October 13, 2026 15:27
Latest stable; the release is build-system and generated-model changes only, and the wrapper uses no com.sift.api.representations types directly.
The SDK now owns the screen name and clears it on null, so the module no longer stores the name or threads it through Sift.open and Sift.resume.
Clearing returns to each SDK's automatic value, which on Android in a React Native app is the React context class name, not an empty field.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant