Skip to content

feat(analytics): mobile churn instrumentation - platform + trigger properties and Push Token Status events - #18883

Merged
Git-on-my-level merged 9 commits into
BasedHardware:mainfrom
Git-on-my-level:feat/mobile-churn-metrics
Sep 27, 2026
Merged

Git-on-my-level merged 9 commits into
BasedHardware:mainfrom
Git-on-my-level:feat/mobile-churn-metrics

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds the analytics instrumentation that mobile churn/retention analysis needs (baseline study 2026-09-25, feeding EXP-002 day-3 re-engagement push design). Two commits, two testable surfaces:

  1. feat(analytics) (Dart): every mobile analytics event now carries platform (ios/android — desktop already sends platform; mobile sent only app_platform, so all mobile events showed platform=(missing)) and trigger (user | background | system) so analysts can exclude non-user-initiated events instead of hand-maintained exclusion lists. Default user; a name-based map tags known background/system emitters; an explicit trigger in event properties overrides (emit-site escape hatch).
  2. feat(analytics) (backend): Push Token Status PostHog events on the push-token lifecycle — status=registered (with lowercased platform) on /v1/users/fcm-token saves, status=invalidated (with count) when per-user sends remove permanently-dead FCM tokens. Firestore remains the source of truth for token state; PostHog gets the analytics-only lifecycle signal, emitted fail-open.

Why (evidence)

  • Mobile churn baseline (PostHog 302298, 90d, queried 2026-09-25): mobile strict day-3–9 return is 54.1% (current bundle) vs 25.3% (legacy), and the EXP-002-eligible baseline is 35.0%/8.4% — but those numbers currently overstate user-initiated return because mobile background/telemetry events cannot be excluded (no distinction exists). Post-EXP-002 eligibility also needs token reachability, which was unobservable.
  • Segmentation: mobile events carried no platform property at all (all rows (missing) in a 90d event/platform/app_namespace breakdown).

Account Created mobile coverage floor (gap 3 cause)

Mobile Account Created exists only since cohort week 2026-08-30. Cause found in git history: the emit site (accountCreated in app/lib/utils/analytics/analytics_manager.dart, called from app/lib/providers/auth_provider.dart:277 on the shared auth path used by both iOS and Android) was added to mobile in fdb45db205 (2026-08-31, #11539, "close mobile lifecycle and device gaps"). The floor is instrumentation timing, not a signup-volume change. This commit adds a pin test asserting Account Created carries platform and trigger=user.

Test evidence

  • Backend (real run, worktree venv, Python 3.14): .venv/bin/python -m pytest tests/unit/test_push_token_status_telemetry.py → 4 passed: registered-emit (structural AST pin on the router), invalidated-emit on permanent-failure removal, no-noise on clean sends, and emit-failure-never-breaks-send. Bulk sends (no uid) intentionally do not emit — documented and pinned to prevent misattribution.
  • Formatter: black --line-length 120 --skip-string-normalization on all touched backend files → 3 files left unchanged.
  • Dart: new/updated tests in app/test/unit/analytics_manager_fail_open_test.dart (platform+trigger on every delivered event; map classifications; explicit-override wins; Account Created pin). Local verification limitation, stated explicitly: this machine has no Flutter/Dart SDK (repo pins 3.44.5; dart-format hook skipped via the documented OMI_SKIP_DART_FORMAT=1), so the Flutter unit tests and formatting are verified by CI, not locally.

Risk / rollout

Purely additive analytics properties and fail-open emissions; no product behavior change, no schema/permission/workflow changes. Event volume is bounded (registered at most once per app launch/token refresh; invalidated only on permanent-failure removals).

Failure-Class

Failure-Class: none

⚠️ Known red check: Dart tests blocked by the spine contract — needs a C7 oracle revision

This PR adds two global properties (platform, trigger) to every mobile emission,
which fails the C7 emission-privacy spine contract (app/test/spine/c7_emission_privacy_test.dart):
its adapter-boundary allowlist is exact-bytes protected and a builder PR may not carry
oracle revisions — verified locally, and an attempted oracle-only branch
(spine/c7-emission-privacy-globals) was abandoned when the spine checker rejected every
chain shape: main has already retired c7's pendingContract('C7') marker, and retired
markers can never return
, so no revision record with a marker-preserving payload can
chain from current main. This needs a spine coordinator ruling (per
scripts/dev-harness/PENDING_CONTRACTS.md): either a coordinator-authored C7 revision
admitting the two globals, or sanctioned retirement. The implementation diff itself is
complete and verified (see below); only the two Dart tests checks + downstream
release-eligibility stay red pending that ruling. All backend checks pass.

Line-count exceptions (oversized-file ratchet)

Line-Count-Exception: app/lib/utils/analytics/analytics_manager.dart | 2688 -> 2715 | churn-event registry and fail-open machinery are cohesive; +27 lines are new registered-event definitions plus doc comments, not extractable helpers
Line-Count-Exception: backend/utils/notifications.py | 858 -> 874 | token-invalidation emit lives beside the existing permanent-failure removal paths it mirrors; extracting a new module would duplicate the PERMANENT_FAILURE_CODES context
Line-Count-Exception: backend/routers/notifications.py | 158 -> 168 | registered-emit belongs at the token-save route where uid+platform are already resolved

@Git-on-my-level
Git-on-my-level force-pushed the feat/mobile-churn-metrics branch from 5255fb9 to 2e436ca Compare September 25, 2026 13:15
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Monitor run — analytics test-expectation fixes pushed (head 5255fb95c9 → 2e436ca674)

What was fixed

The platform + trigger instrumentation changes every event payload, but 13 pre-existing test expectations across 8 files still asserted the old shape. CI only surfaced 2 (test.sh aborts at the spine phase), so the other 12 would have failed the next run. All updated in eb73edaeda:

  • app/test/unit/analytics_manager_fail_open_test.dart — 4 literal payload maps
  • app/test/utils/analytics/c8_slice_goldens_test.dart (×2 blocks), c8_slice2, c8_slice3, c8_slice4, c8_leftover_bool, omi_double_tap goldens — globals now include the classification fields (all trigger: 'user'; verified no golden event is in the non-user map)
  • app/test/widgets/conversation_action_analytics_test.dart — extended the existing manager-provenance filter (app_*) to also exclude platform/trigger, so it still asserts the event itself carries only action+surface

Verified locally: full flutter test suite 3157 passed / 5 skipped / 0 failed; flutter analyze clean; dart format --set-exit-if-changed 0 diffs; repo pre-push gate passed (including spine-contracts).

Remaining red — needs a sequencing decision (not a code fix)

Dart Analyze & Tests, Dart Tests (Pacific/Kiritimati), and Mobile Release Eligibility (aggregator) still fail on exactly 2 tests: C7 registered emission payload excludes user content in app/test/spine/c7_emission_privacy_test.dart.

That file is a protected spine oracle — the spine-contracts gate rejects editing it alongside implementation paths, by design. Fixing it requires landing an oracle-only revision PR first (contracts/spine/revisions/ record + oracle edit, nothing else), then rebasing this PR on top. I attempted the in-PR edit and reverted it (2e436ca674) once the gate explained the rule; bundling both in one PR is explicitly disallowed ("Separate commits in one PR do not satisfy this rule").

The one-line oracle change when that revision PR happens: extend the test's globals allowlist with 'platform': <same as app_platform> and 'trigger': 'user' (all five events there are interaction-driven).

Git-on-my-level and others added 7 commits September 25, 2026 22:33
…alytics events

Cross-platform churn analysis (mobile churn baseline, 2026-09-25) could not
segment mobile events: desktop sets a per-event 'platform' property
(macos/windows) while mobile sent only 'app_platform', so every mobile event
showed platform=(missing) in PostHog. Mobile now sends both 'platform' and
'app_platform' (ios/android) as global event properties, and every event
carries a 'trigger' classification (user | background | system): default
user, a name-based map tags the known background/telemetry emitters
(background resource sessions, telemetry health, startup timing, update
checks, notification system events, auth/fallback telemetry), and an
explicit 'trigger' in the event properties wins as an emit-site escape
hatch. Retention analysis must exclude non-user-initiated events when
measuring return - background refresh keeps telemetry warm exactly like
launch-at-login keeps App Launched warm on desktop (churn decision log
2026-08-30). Tests updated/added in analytics_manager_fail_open_test
including a pin that Account Created carries platform and trigger=user
(mobile Account Created exists only since 2026-08-31, commit fdb45db
BasedHardware#11539 - instrumentation timing, not a volume change).

Verification note: dart-format hook skipped via OMI_SKIP_DART_FORMAT (no
Flutter/Dart SDK on this machine); edits mirror existing style at 120 cols.
Flutter unit tests must be confirmed by CI.
…ter and invalidate

EXP-002 (day-3 re-engagement push) eligibility needs 'user has a deliverable
push token as of a date'. Firestore stays the eligibility source of truth;
PostHog now gets the analytics lifecycle signal: the /v1/users/fcm-token
router emits status=registered (platform lowercased) after a successful
save, and per-user sends emit status=invalidated with a count when
_collect_send_results removes permanently dead tokens (UNREGISTERED and
friends). Emission is fail-open: a PostHog outage can never fail a token
save or a notification send. Bulk sends carry no uid, so they intentionally
do not emit (asserted in tests to prevent misattribution). Tests in
test_push_token_status_telemetry cover register (structural AST pin on the
router), invalidate, no-noise on clean sends, and emit-failure isolation.

Verified: backend/.venv python -m pytest tests/unit/test_push_token_status_telemetry.py
-> 4 passed (worktree venv, Python 3.14, google-api-core installed for the
unit conftest).
Purely additive analytics properties/events with no user-visible behavior
change; kind=none fragment per the changelog contract for internal-only
production edits.
Canonical formatting for the new platform/trigger code; the machine's
default dart shim resolves a different SDK, so formatting is done with the
pinned 3.44.5 toolchain explicitly.
pub get resolves flutter_lints so the formatter reads the repo's
analysis_options include (matches CI exactly); the earlier format pass ran
without package resolution and applied CLI defaults.
… properties

The churn instrumentation adds 'platform' (global) and 'trigger'
(per-event classification) to every mobile analytics event payload.
Update the exact-payload expectations that predate those fields:

- spine c7_emission_privacy_test allowlist gains both fields
- fail-open manager tests: add trigger/platform to the four literal
  property maps (one already carried platform)
- c8 golden tests + omi_double_tap goldens: globals now include
  trigger=platform classification (all user-initiated events)
- conversation action analytics: filter the manager-added
  platform/trigger provenance the same way app_* is filtered, so the
  test still asserts the event itself carries only action+surface
The c7_emission_privacy_test.dart allowlist edit belongs in an
oracle-only spine revision PR (contracts/spine/revisions/), not mixed
with this implementation PR; the spine-contracts gate correctly
rejects oracle edits alongside implementation paths. Reverting it here;
the two spine c7 failures remain until that revision lands.
@Git-on-my-level
Git-on-my-level force-pushed the feat/mobile-churn-metrics branch from 2e436ca to b8a722d Compare September 25, 2026 15:39
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Monitor run — synced branch onto latest main (rebase), no code changes (head 2e436ca674 → b8a722d017)

What was done

The monitor auto-rebased this branch onto the latest upstream main (was 17 behind). Verified the rebase preserved the PR exactly — net diff vs main byte-identical before/after (13 files, +476/−127), no conflict markers, spine-contracts gate clean — then re-ran verification and pushed:

  • flutter analyze clean for all PR-changed files; all 39 tests across the 8 changed app test files pass; backend test_push_token_status_telemetry.py 4/4.
  • Full repo pre-push gate: 57 checks pass / 0 fail. Two notes from that run:
    • The line-count ratchet passes with the PR body's declared analytics_manager.dart exception — the allowance (71 lines) still covers the actual growth after the base moved (2744 → 2815). The earlier gate failure was an artifact of running without the PR body (local branch name ≠ PR branch).
    • The two backend Line-Count-Exception entries (utils/notifications.py, routers/notifications.py) now warn as unused — upstream's recent commits grew those files past this PR's deltas. Harmless; can be dropped from the body in a future edit.
  • The repo pre-push hook additionally rebased onto ebbbf74813 (desktop v0.12.391 changelog roll that landed mid-run) before pushing; git range-diff confirms all 7 commits identical.

Post-push CI re-scan

All checks completed. Failures are unchanged and expected — the same 2 tests, C7 registered emission payload excludes user content in the spine oracle app/test/spine/c7_emission_privacy_test.dart (both timezone runs), plus Mobile Release Eligibility as their aggregate. The rebase introduced no new failures; everything else including the Android compile/JVM lanes is green. No new review threads.

These 2 remain blocked on the sequencing decision from the earlier run summary: the oracle-only spine revision PR (contracts/spine/revisions/) must land first, then this branch rebases onto it. The branch is now current with main, so that future rebase is clean.

@Git-on-my-level
Git-on-my-level marked this pull request as ready for review September 27, 2026 00:31
@Git-on-my-level
Git-on-my-level merged commit 694a7a5 into BasedHardware:main Sep 27, 2026
39 checks passed
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