[Statsig] Don't log extra background events #5134
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes excessive logging of
state:background:sampled
withsecondsActive = 0
on iOS.The problem is that on iOS, app state goes
active
->inactive
->background
. As a result, theelse
branch of this code gets triggered both oninactive
andbackground
. It "correctly" counts the time only once (i.e. when goingactive
->inactive
) and reports the other change assecondsActive = 0
(because we weren't active in the first place). But it would be better not to send the event at all. With this change, only actual changes to and fromactive
state emit the event.Test Plan
On iOS, verify logs show up when you switch away from the app and back to it. Verify there is no extra "log background 0" log which would've happened before this change. Verify pulling the notification center and back also gets counted as backgrounding and foregrounding.
On Android, verify logs show up when you switch away from the app and back to it.
On web, it doesn't feel like this setup works reliably at all — not sure if it broke at some point. Concretely, the listener only seems to fire as the tab is about to be closed, but it doesn't seem triggered on tab switch. That's unrelated to this PR though.