Skip to content

fix(web): decode JSON-stringified ajs_anonymous_id from localStorage (#196)#197

Open
Jharrison23 wants to merge 1 commit intosegmentio:mainfrom
yendo-eng:fix/issue-196-web-anonymous-id-json-decode
Open

fix(web): decode JSON-stringified ajs_anonymous_id from localStorage (#196)#197
Jharrison23 wants to merge 1 commit intosegmentio:mainfrom
yendo-eng:fix/issue-196-web-anonymous-id-json-decode

Conversation

@Jharrison23
Copy link
Copy Markdown

Fix for Issue #196: Decode JSON-stringified ajs_anonymous_id from localStorage

Problem

analytics.js (the Segment JavaScript SDK) stores ajs_anonymous_id in localStorage using JSON.stringify(), which wraps the UUID in surrounding double-quote characters. The Flutter SDK's getExistingAnonymousId() reads this value via localStorage.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.js has previously set ajs_anonymous_id.

Fix

Added json.decode of the raw localStorage/cookie value in getExistingAnonymousId() with a try/catch fallback, so:

  • JSON-stringified values (e.g. "d039d945-...") are decoded to clean UUIDs
  • Plain string values pass through unchanged
  • Non-string or malformed values are left as-is

Related

Files Changed

  • packages/core/lib/utils/store/web.dart

…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.
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