Skip to content

feat: lifecycle event emitter [rn] (2/4)#35

Open
choudlet wants to merge 2 commits into
chrish/sc-36800/rn-lifecycle-pr1-storagefrom
chrish/sc-36800/rn-lifecycle-pr2-emitter
Open

feat: lifecycle event emitter [rn] (2/4)#35
choudlet wants to merge 2 commits into
chrish/sc-36800/rn-lifecycle-pr1-storagefrom
chrish/sc-36800/rn-lifecycle-pr2-emitter

Conversation

@choudlet
Copy link
Copy Markdown
Collaborator

@choudlet choudlet commented Apr 27, 2026

Summary

  • Slice 2 of 4 in the RN lifecycle stack (sc-36800).
  • Adds the LifecycleEmitter class — thin wrapper mapping the four lifecycle events to the standard track() shape with the cross-platform wire format.
  • Stacked on feat: lifecycle storage foundation [rn] (1/4) #34 (storage foundation). Review the diff against that branch.

Wire format (parity with iOS / Android)

Event Properties
Application Installed version, build
Application Updated version, build, previous_version, previous_build
Application Opened from_background, version, build, optional url, optional referring_application
Application Backgrounded (none)

Title Case event names, snake_case property names — matches the iOS LifecycleEventEmitter and Android equivalent exactly so cross-platform pipelines see one shape.

Notes

  • Emitter holds the enabled flag (mirrors trackLifecycleEvents) so every emit is a no-op when the feature is off — slice 3 callers don't have to gate at every call site.
  • UNKNOWN_PREVIOUS = "unknown" sentinel is used for the SDK-upgrade case (existing user, no prior lifecycle storage), distinguishing it from the literal string a host might ship.
  • No wiring yet — slice 3 owns the call sites in MetaRouterAnalyticsClient.

Stack

  1. #34 — storage foundation
  2. This PR — emitter + tests (~235 LOC)
  3. AnalyticsClient wiring + `openURL` public API + opt-in default
  4. README documentation

Test plan

  • `npx jest src/analytics/lifecycle/lifecycleEvents.test.ts` — 11 tests cover each event shape, the disabled-emitter no-op, and the `isEnabled` accessor
  • `npx tsc --noEmit` clean

Adds the `LifecycleEmitter` class — a thin wrapper that maps the four
lifecycle events to the standard `track()` shape with snake_case
properties matching the iOS / Android wire format exactly:

  - Application Installed     {version, build}
  - Application Updated       {version, build, previous_version, previous_build}
  - Application Opened        {from_background, version, build, url?, referring_application?}
  - Application Backgrounded  {}

The emitter holds the `enabled` flag (mirrors `trackLifecycleEvents`)
so every emit is a no-op when the feature is disabled — callers do not
need to gate at every call site.

Property names use snake_case while event names use Title Case to match
the cross-platform SDK contract; the `UNKNOWN_PREVIOUS` sentinel is
used for the SDK-upgrade case (existing user, no prior lifecycle
storage) where the previous version is genuinely unknown rather than
the literal string the host shipped.

Slice 2 of 4 in the RN lifecycle stack (sc-36800).
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