Symptoms
- Anonymous users receive inconsistent feature flag experiences when returning to your site.
- Your Monthly Active User (MAU) counts appear unexpectedly high or inflated.
- You're considering writing custom logic to store and retrieve context keys manually in local storage or session storage.
Cause
These symptoms usually stem from either:
- Not letting the SDK generate and persist the anonymous key automatically, for example, by manually providing a new key every time.
- Misunderstanding how the SDK handles anonymous contexts, leading to redundant or conflicting logic.
- Local storage being cleared by your app, browser settings, or extensions, which causes the SDK to treat returning users as new.
Manual persistence often adds unnecessary complexity and may interfere with the SDK's internal key management, especially during context transitions (like when a user logs in).
Solution
Let the SDK handle anonymous key generation
If you're using a client-side SDK, omit the key when initializing an anonymous context. The SDK will:
- Generate a unique key,
- Store it in local storage,
- Reuse it across sessions (as long as storage isn’t cleared).
For implementation examples, read Anonymous contexts.
Transitioning to authenticated users
When users log in, call identify() to transition from their anonymous context to an authenticated one. This preserves their existing experience and avoids duplicate MAU counts.
To learn more, read Associate anonymous contexts with logged-in users.
Troubleshoot storage issues
If users still receive inconsistent experiences:
- Check your browser’s local storage to confirm whether the SDK’s anonymous key is present and persistent.
- Ensure no code or privacy settings are clearing local storage on page load or between sessions.
- Avoid manually generating new anonymous keys unless you have a specific reason and a solid storage strategy.