Overview
Before an end-user context logs in, they may represent a certain context kind with different attributes. After they login, they may be represented by additional contexts, each with unique keys.
To associate two or more contexts together for a consistent experience between end-user states and for experimentation purposes, use a multi-context in each of your variation
, identify
, and track
calls.
Solution
1. Evaluate the anonymous context by calling variation
before logging in:
const anon_context = {
"kind": "anonContext",
"key": "context-key-123abc",
"anonymous": true
}
const client = LDClient.initialize('client-side-id-123abc', anon_context);
client.variation(my-flag, false)
const logged_in_context = {
"kind": "loggedInContext",
"key": "context-key-456def",
"plan": "platinum",
"active": true,
"country": "australia"
}
multi
context and calling identify
:const multi_context_user = {
"kind": "multi",
anon_context,
logged_in_context
}
ldclient.identify(multi_context_user)
4. Call identify
and variation
moving forward with the multi
context to ensure a seamless variation experience for the context.
5. If using the Experimentation feature, set the Randomization unit as anonContext
and also in the associated metric to ensure a consistent experience between anonymous and logged-in states and accurate Experiment results.