fix(web): decode JSON-stringified ajs_anonymous_id from localStorage (#196)#197
Open
Jharrison23 wants to merge 1 commit intosegmentio:mainfrom
Open
fix(web): decode JSON-stringified ajs_anonymous_id from localStorage (#196)#197Jharrison23 wants to merge 1 commit intosegmentio:mainfrom
Jharrison23 wants to merge 1 commit intosegmentio:mainfrom
Conversation
…egmentio#196) analytics.js stores ajs_anonymous_id as a JSON-encoded string, wrapping the UUID in surrounding double-quote characters. getExistingAnonymousId() read the raw value without decoding, causing identity mismatches between the JS and Flutter SDKs.
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.
Fix for Issue #196: Decode JSON-stringified ajs_anonymous_id from localStorage
Problem
analytics.js(the Segment JavaScript SDK) storesajs_anonymous_idin localStorage usingJSON.stringify(), which wraps the UUID in surrounding double-quote characters. The Flutter SDK'sgetExistingAnonymousId()reads this value vialocalStorage.getItem()but does not decode it, so the quotes become part of the anonymous ID string.This causes identity mismatches between the JS and Flutter SDKs for any Flutter web app running on a domain where
analytics.jshas previously setajs_anonymous_id.Fix
Added
json.decodeof the raw localStorage/cookie value ingetExistingAnonymousId()with a try/catch fallback, so:"d039d945-...") are decoded to clean UUIDsRelated
Files Changed
packages/core/lib/utils/store/web.dart