Skip to content

Add Sift.setScreenTitle to set and clear the reported screen name - #116

Open
ostfrost wants to merge 2 commits into
SiftScience:masterfrom
ostfrost:android-set-screen-title
Open

ostfrost wants to merge 2 commits into
SiftScience:masterfrom
ostfrost:android-set-screen-title

Conversation

@ostfrost

@ostfrost ostfrost commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Add a way to set and clear the screen name reported with App State events, mirroring the iOS SDK's setScreenTitle: (sift-ios#167). Needed so the React Native wrapper can expose one setPageName(name | null) with the same semantics on both platforms (MSUE-242, iOS side MSUE-243).

Today the only way to set a screen name is Sift.open(context, activityName) or Sift.resume(context, activityName), and both coalesce a null name to context.getClass().getSimpleName(). There is no unset: in a React Native app that writes the literal context class name into activity_class_name. Changing that coalescing would break the documented per-Activity integration (Sift.open(this) with no name), so this adds a separate channel instead.

Summary

  • Sift.setScreenTitle(String title): new public API. Stores a manual screen name on AppStateCollector. null or an empty string resets it, after which the automatic Activity name is used again. It does not collect by itself; call Sift.collect() to send an event right away. Called before Sift.open(), the title is held and applied when the collector is created, following the existing unboundUserId pattern.

  • AppStateCollector: new volatile field manualScreenTitle with setManualScreenTitle(String). When building AndroidAppStateJson, activity_class_name uses the manual title when set, otherwise the automatic name.

  • open() and resume() are unchanged, so existing integrations behave exactly as before.

  • The title is not persisted and does not survive a process restart, same as iOS.

  • Docs: README (custom screen name section in both integration styles), DESIGNDOC (sections 3.2, 4.1, 4.4), CHANGELOG.

  • CI: android-actions/setup-android@v3 now runs with packages: ''. Its default list includes tools, which sdkmanager no longer provides, so the job failed at that step before building; the next step already installs the packages the build needs.

Versioning, for the maintainers to decide:

  • Bumped to 1.4.0 as a minor release because it adds public API without breaking changes. Happy to change to 1.3.2 if you prefer.
  • VERSION_CODE bumped 26 to 27 to match the previous release. Note it is not read anywhere in the build (only VERSION_NAME is used, in buildConfigField and maven-push.gradle), so it can be reverted if you prefer a minimal diff.

Testing

  • ./gradlew :sift:test passes, including three new tests in SiftTest:
    • testManualScreenTitleOverridesActivityName
    • testManualScreenTitleResetFallsBackToActivityName (covers both null and empty string)
    • testUnboundSetScreenTitle (title set before Sift.open() is applied on open; resets the static Sift state via reflection so it does not depend on test order)
  • End to end through the React Native example (sift-react-native#48) against this branch published with ./gradlew :sift:publishToMavenLocal, API 37 emulator, activity_class_name from logcat:
Step Observed
setScreenTitle("BeforeConfig") before Sift.open() no event; title applied on open, then BeforeConfig
setScreenTitle("Checkout") + collect() Checkout
Background and foreground (Sift.resume()) Checkout, the manual title survives resume
setScreenTitle(null) + collect() automatic name again (BridgelessReactContext in React Native)
  • hello-sift on an API 37 emulator, unchanged: app state events report activity_class_name as HelloSift, then OtherActivity after navigating, so the automatic names are unaffected by the new code path.

Checklist

  • The change was thoroughly tested manually (end to end through the React Native example, see Testing)
  • The change was covered with unit tests
  • The change was tested with the integration example (hello-sift, no regression in automatic screen names)
  • Necessary changes were made in the integration example (if applicable): not applicable, the new API is optional
  • New functionality is reflected in README (if applicable)

The Activity class name was the only source of the screen name and null could not clear it, so a React Native app had no way to report or reset one; this mirrors the iOS SDK's setScreenTitle:. Released as 1.4.0.
@ostfrost
ostfrost marked this pull request as draft October 21, 2026 18:36
The action's default package list includes tools, which sdkmanager no longer provides, so the step failed before the build ran.
@ostfrost
ostfrost marked this pull request as ready for review October 21, 2026 19:29
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