Session
Unauthenticated user sessions that maintain consistency pre and post-login.
Session contexts use these attributes:
| Attribute | Type | Source | Example | Private | Notes |
|---|---|---|---|---|---|
| key | String | Local/Session Storage | 7D97F0D3-B18C-4305-B110-0317BDB745DC | FALSE | Random UUID stored in session-bound storage |
| anonymous | Boolean | Static: true | true | FALSE | Always true for session contexts |
| startedAt | Number | Current time at session creation | 1640995200000 | FALSE | Unix timestamp in milliseconds |
Implementation example
Implement a session context like this:
const sessionContext = {
kind: "session",
key: getOrCreateSessionId(),
anonymous: true,
startedAt: Date.now()
};
function getOrCreateSessionId() {
let sessionId = sessionStorage.getItem('ld-session-id');
if (!sessionId) {
sessionId = crypto.randomUUID();
sessionStorage.setItem('ld-session-id', sessionId);
}
return sessionId;
}
Use cases
Progressive release for unauthenticated users
Use this when you roll out features to users before they log in. This ensures anonymous visitors see new features without authentication.
Maintain consistency across authentication
Use this when features should remain consistent before and after login. For example, a user sees a new checkout flow while browsing anonymously. They continue to see it after logging in during the same session.
Kill switch for resource-intensive features
Use this when you disable expensive features for unauthenticated users. For example, disable AI-powered recommendations or real-time chat for anonymous sessions. This reduces infrastructure costs.
Experimentation for pre-authentication paths
Use this when you run experiments on registration flows, shopping cart behavior, or add-to-cart functionality. Rolling out by session ensures consistent experience throughout the visitor’s journey.