Repository navigation
fix(analytics): keep timed events started before JS-mode storage load completes - #481
Draft
rahul-mixpanel wants to merge 2 commits into
Draft
rahul-mixpanel wants to merge 2 commits into
rahul-mixpanel wants to merge 2 commits into
Conversation
… completes In JavaScript mode, `init()` (and the persistent singleton) re-read time events from storage asynchronously and replaced the in-memory map with the stored value. A `timeEvent()` call made while that read was in flight, e.g. right after an un-awaited `init()`, was overwritten, so the later `track()` was sent without `$duration`. `loadTimeEvents` now merges in-memory timers over the stored ones, and `reset()` clears the in-memory timers explicitly. Related to #261 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
[Medium impact] The PR appears safe to merge; no blocking issues were found. Reviews (2) · Last reviewed commit: "test(analytics): cover $duration for tim..." · Reviewed by Greptile |
Related to #261 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Related to #261 (Linear SDK-257).
In JavaScript mode,
init()(and theMixpanelPersistentsingleton on construction) re-read time events from storage asynchronously and then replaced the in-memory map with whatever was stored. AtimeEvent()made while that read was in flight, e.g. right after an un-awaitedinit()(which the README sample shows), was wiped. The matchingtrack()then went out without$duration.The payload in #261 points to JS mode. It has none of the automatic properties native Android adds, such as
$screen_dpi,$wifi,$app_version_stringand$carrier. Itstimeis in milliseconds, which is what JS mode'strack()sends.Change
loadTimeEventsmerges in-memory timers over the stored ones. In-memory timers are always at least as new as storage, because every update is persisted.reset()clears in-memory timers explicitly, since it relied on the old overwrite.No change to payload shape or public API. Native mode is untouched.
Cross-SDK parity
mixpanel-android, mixpanel-swift and mixpanel-js all attach
$durationwhen an event started withtimeEvent/time_eventis tracked. This brings RN JS mode in line.Tests
__tests__/main-time-event.test.js: un-awaitedinitialize()→timeEvent()→track()queues the event with$duration. It uses the realMixpanelPersistentwith slow storage and fails on base.MixpanelPersistent - time events: a timer started during a load survives it, and reset clears timers.npx jest: 531 passed, 4 skipped.Note (not changed here)
JS mode sends
$durationin whole seconds (Math.roundineventElapsedTime), while Android, Swift and mixpanel-js send fractional seconds. This predates the PR. It's a possible parity follow-up, but it's a data change, so it needs a decision.🤖 Generated with Claude Code