Skip to content

feat(auth): emit glean events on device disconnect and session sign-out#20787

Open
vbudhram wants to merge 1 commit into
mainfrom
fxa-13092
Open

feat(auth): emit glean events on device disconnect and session sign-out#20787
vbudhram wants to merge 1 commit into
mainfrom
fxa-13092

Conversation

@vbudhram

Copy link
Copy Markdown
Contributor

Because

  • We want to record when a device/account signs out of the browser, including which account and the platform (desktop / iOS / Android), to analyze sign-out behavior.
  • The existing frontend account_pref.device_signout event only fires for web-settings disconnects and carries no platform, so browser- and app-initiated sign-outs go unrecorded.

This pull request

  • Adds two server-side Glean events in fxa-backend-metrics.yaml: account.device_disconnected (on /account/device/destroy) and account.session_destroyed (on /session/destroy), each with a platform extra key.
  • Adds a pure platformFromOS helper in fxa-shared/lib/user-agent.ts that maps a parsed user-agent OS to desktop/ios/android/unknown.

Issue that this pull request solves

Closes: https://mozilla-hub.atlassian.net/browse/FXA-13092

Checklist

  • My commit is GPG signed.
  • If applicable, I have modified or added tests which pass locally.
  • I have added necessary documentation (if appropriate).
  • I have verified that my changes render correctly in RTL (if appropriate).
  • I have manually reviewed all AI generated code.

Other information

  • Why derive platform from OS, not deviceType? Two existing deviceType signals were considered and rejected:
    • The auto-attached session_device_type (UA-derived) only yields mobile/tablet/'', can't distinguish iOS from Android, and reflects the acting client's UA rather than the disconnected device.
    • The device record's type only exists for registered Sync/OAuth devices, so it's empty for plain web/settings sessions (/session/destroy) and still doesn't split iOS vs Android.
    • The parsed OS (device.uaOS / request.app.ua.os) is present on both paths and cleanly buckets to desktop/ios/android.
  • Overlap note: on the web-settings disconnect path, both the existing frontend account_pref.device_signout and the new server-side account.device_disconnected fire. The server event is the comprehensive one; flag to the data team to avoid double-counting.
  • No flow id: browser/app-initiated disconnects carry no metricsContext, so session_flow_id/utm_* are empty on those events (expected).

@vbudhram vbudhram requested a review from a team as a code owner June 25, 2026 01:55
@vbudhram vbudhram self-assigned this Jun 25, 2026
Because:
 - We want to record when a device/account signs out of the browser,
   including which account and platform (desktop/iOS/Android). The
   existing frontend account_pref.device_signout event only covers
   web-settings disconnects and carries no platform, so browser- and
   app-initiated sign-outs go unrecorded.

This commit:
 - Adds two server-side Glean events: account.device_disconnected (on
   /account/device/destroy) and account.session_destroyed (on
   /session/destroy), each with a platform extra key.
 - Adds a pure platformFromOS helper in fxa-shared/lib/user-agent that
   maps a parsed user-agent OS to desktop/ios/android/unknown.
 - Threads glean into the devices factory and emits at both destroy
   paths; platform is derived from the disconnected device uaOS and the
   session user-agent OS respectively.
 - Regenerates server_events.ts and adds unit tests for the helper and
   both emission sites.
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