Repository navigation
feat(analytics): mobile churn instrumentation - platform + trigger properties and Push Token Status events - #18883
Conversation
5255fb9 to
2e436ca
Compare
|
Monitor run — analytics test-expectation fixes pushed (head What was fixedThe
Verified locally: full Remaining red — needs a sequencing decision (not a code fix)
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 ( The one-line oracle change when that revision PR happens: extend the test's |
…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.
2e436ca to
b8a722d
Compare
|
Monitor run — synced branch onto latest main (rebase), no code changes (head What was doneThe monitor auto-rebased this branch onto the latest upstream
Post-push CI re-scanAll checks completed. Failures are unchanged and expected — the same 2 tests, These 2 remain blocked on the sequencing decision from the earlier run summary: the oracle-only spine revision PR ( |
…g SDK boundary instead of the governed emission
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:
feat(analytics)(Dart): every mobile analytics event now carriesplatform(ios/android — desktop already sendsplatform; mobile sent onlyapp_platform, so all mobile events showedplatform=(missing)) andtrigger(user|background|system) so analysts can exclude non-user-initiated events instead of hand-maintained exclusion lists. Defaultuser; a name-based map tags known background/system emitters; an explicittriggerin event properties overrides (emit-site escape hatch).feat(analytics)(backend):Push Token StatusPostHog events on the push-token lifecycle —status=registered(with lowercased platform) on/v1/users/fcm-tokensaves,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)
platformproperty at all (all rows(missing)in a 90d event/platform/app_namespace breakdown).Account Createdmobile coverage floor (gap 3 cause)Mobile
Account Createdexists only since cohort week 2026-08-30. Cause found in git history: the emit site (accountCreatedinapp/lib/utils/analytics/analytics_manager.dart, called fromapp/lib/providers/auth_provider.dart:277on the shared auth path used by both iOS and Android) was added to mobile infdb45db205(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 assertingAccount Createdcarriesplatformandtrigger=user.Test evidence
.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.black --line-length 120 --skip-string-normalizationon all touched backend files → 3 files left unchanged.app/test/unit/analytics_manager_fail_open_test.dart(platform+trigger on every delivered event; map classifications; explicit-override wins;Account Createdpin). Local verification limitation, stated explicitly: this machine has no Flutter/Dart SDK (repo pins 3.44.5; dart-format hook skipped via the documentedOMI_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 (
registeredat most once per app launch/token refresh;invalidatedonly on permanent-failure removals).Failure-Class
Failure-Class: none
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 everychain shape: main has already retired c7's
pendingContract('C7')marker, and retiredmarkers 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 revisionadmitting 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