# 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:

```javascript
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.

---

<div class="page-metadata"><table class="page-metadata-table" aria-label="Page metadata"><thead><tr><th scope="col">Last modified</th><th scope="col">Last reviewed</th><th scope="col">Review due</th></tr></thead><tbody><tr><td><time datetime="2026-03-19">2026-03-19</time></td><td></td><td></td></tr><tr><td>Last commit: <a href="https://github.com/launchdarkly-labs/ps-flag-book/commit/d319a7d">d319a7d</a></td><td></td><td></td></tr></tbody></table></div>