Skip to content

Track every WordPress.com logout and its duration - #26118

Draft
jkmassel wants to merge 1 commit into
task/cookiejar-behavior-changesfrom
jkmassel/track-logout-duration
Draft

jkmassel wants to merge 1 commit into
task/cookiejar-behavior-changesfrom
jkmassel/track-logout-duration

Conversation

@jkmassel

@jkmassel jkmassel commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Tracks account_logout on every WordPress.com logout and adds a duration_ms property saying how long logout kept the main thread busy. Until now the event only fired when logging out left the user with no account and no sites, and it carried no timing.

Nothing reports how long logout takes today: Sentry app-hang tracking and performance tracing are both off in this app. On trunk, logging out freezes the main thread for about 2.5 s when WebKit's cookie store holds at least one WordPress.com cookie, and that went unnoticed until it was measured by hand. #26106 removes that wait. This PR is stacked on it, touches no file it changes, and makes the next such freeze visible.

Changes

  • WordPress/Classes/Utility/AccountHelper.swift: logOutDefaultWordPressComAccount() tracks account_logout with duration_ms when there was a WordPress.com account to log out of.
  • WordPress/Classes/System/WordPressAppDelegate.swift: the handler for the account-changed notification no longer calls trackLogoutIfNeeded(), which would now double-count. trackLogoutIfNeeded() stays for its other caller: removing the last self-hosted site still tracks account_logout, without a duration.

What duration_ms measures

The time from the start of logOutDefaultWordPressComAccount() until the main queue next runs a block. The event is tracked from a DispatchQueue.main.async at the end of the method, not inline.

Timing only the method body would have missed the freeze this metric exists to catch: on trunk, the 2 s cookie wait runs in a WebKit completion handler after the method has returned. Measured next to a main-thread stall monitor, duration_ms was within 28 ms of the stall in all three runs below.

The event's meaning changes

account_logout no longer means "fully signed out". It now fires when a WordPress.com account is logged out even if self-hosted sites remain, so counts will rise. A user who logs out of WordPress.com and later removes their last self-hosted site produces two events, and nothing on the event tells the two cases apart.

Replacing the default account during sign-in no longer tracks a logout. WordPressComSyncService removes an existing default account when a different one signs in. That went through the notification handler and tracked account_logout if no self-hosted sites were left. It is not a user logout and has no duration to report.

The event is lost if the app exits before the next main queue turn. That is the cost of measuring past the end of the method.

Test plan

Measured on an iOS 27.0 simulator (Debug build) signed in to an account with 389 sites, using a temporary analytics tracker and main-thread stall monitor that are not part of this PR:

Scenario duration_ms Stall monitor account_logout events
WordPress.com account only 366 354 ms 1
Same, with trunk's cookie removal swapped in 2,489 2,461 ms 1
WordPress.com account plus a self-hosted site 407 388 ms 1

Before this PR no event fired in the third scenario. The self-hosted site there was a placeholder Blog inserted into Core Data, not a site added through the UI.

  • Each scenario tracked exactly one account_logout, with duration_ms within 28 ms of the stall monitor.
  • With trunk's cookie removal swapped in, duration_ms reported the 2 s main-thread wait that Change CookieJar behaviors ahead of the async conversion #26106 removes.
  • Log out of WordPress.com (Me → Log Out) with the Xcode console open: exactly one 🔵 Tracked: account_logout <duration_ms: …> line appears.
  • Add a self-hosted site, then log out of WordPress.com: the same line appears once.

There is no unit test. Running the real logout in the unit-test host resets process-wide state (the disk cache, WordPressClientFactory.shared, JetpackSocialFactory.shared) in a host shared with other suites.

`account_logout` only fired when logging out left the user with no account
or sites, and carried no timing.

Track it from `AccountHelper.logOutDefaultWordPressComAccount()` instead, on
every WordPress.com logout, with a `duration_ms` property. The duration is
taken on the next main queue turn, so it also covers main thread work that
logging out starts but that only runs after the method returns.

Removing the last self-hosted site still tracks the event as before.
@jkmassel jkmassel added this to the 27.4 milestone Oct 5, 2026
@jkmassel jkmassel self-assigned this Oct 5, 2026
@dangermattic

Copy link
Copy Markdown
Collaborator
1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

@wpmobilebot

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number34828
VersionPR #26118
Bundle IDorg.wordpress.alpha
Commit6cb3272
Installation URL76162fekd3qe0
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number34828
VersionPR #26118
Bundle IDcom.jetpack.alpha
Commit6cb3272
Installation URL0mnj8vcjaldn0
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants