---
title: Handle user IDs in Feature Experimentation
slug: feature-experimentation/docs/handle-user-ids-in-feature-experimentation
docTags: 
createdAt: 2026-08-05T20:39:56.000Z
---

- Optimizely Feature Experimentation

Optimizely Feature Experimentation identifies visitors with user IDs and determines which variation they see in an experiment ([A/B test](docId:8pnfCv-sR37goLcxTtCPv) or [multi-armed bandit](docId\:F5-ZUIoxCu2_XRy26tO-b)) or a [flag delivery (targeted delivery)](docId:_BjMxuGwwlVrhkNcx2kzm). Feature Experimentation lets you define user IDs based on your testing strategy. For example, you can use a first-party cookie, a device ID for anonymous users, or a stored identifier for logged-in users.

Consistent user IDs prevent users from being potentially re-bucketed into different variations, ensuring reliable experiment results. If your tests span multiple devices or applications, you can use a UUID to maintain a consistent experience for each user. Alternatively, you can use [bucketing IDs](docId:0mbVhcaiWJm6M96ZohwI-) to provide a consistent experience across different identifiers.

## Tips for user IDs

- **Ensure user IDs are unique** – Feature Experimentation buckets users based on the user IDs you provide, so ensure these IDs are unique within your testing population.
- **Anonymize user IDs** – Optimizely processes user IDs exactly as provided. Anonymize any personally identifiable information (PII), such as email addresses, according to your company's policies.
- **Use one namespace per project** – Feature Experimentation assumes a single namespace for user IDs per project. Mixing different ID conventions within a project (for example, anonymous visitor IDs and UUIDs) can affect [mutual exclusivity](docId\:Jx601K4Y1NWOlTXhKMZNy) between tests.
- **Use logged-out or logged-in IDs** – Optimizely does not alias logged-out IDs with logged-in IDs. Persist logged-out IDs for the duration of a test if you need to track users across authentication states. See the [Handle multiple user IDs](docId\:A5r9X69CRaxFk2RjeeOjY) section.
- **iOS 14 ID for advertisers and disclosure updates** – Feature Experimentation SDKs do not access user data or identifiers that you do not explicitly pass in through instrumented API calls. As a result, you should not depend on SDK changes planned to accommodate Apple's changes to its [privacy disclosure and opt-in policy](https://developer.apple.com/app-store/user-privacy-and-data-use/) related to their ID for Advertisers (IDFA). You should review Apple's full [requirements and guidance](https://developer.apple.com/app-store/app-privacy-details/), [other identifier options](https://developer.apple.com/documentation/uikit/uidevice/1620059-identifierforvendor), and your [data use](https://developer.apple.com/app-store/app-privacy-details/#data-type-usage) carefully to determine the correct path forward for your application and usage.

## Create a user context example

Feature Experimentation SDKs manage user IDs through user contexts. When you create a user context, you define a user ID and optional attributes for audience targeting. The SDKs consistently assign a user to the same variation as long as the traffic distribution is not modified. See [Why you should not change a running experiment](docId\:IsU8ejnD3mrkAia2mtIOA).

For SDK-specific code examples, see the [Create a user context example section](docId\:j0PPoMJWYbz04K76EKLUI) in the developer documentation. 

For information, see the SDK's user context documentation.

- [Android](docId\:gR9wq-XMrQQOtGcWhpyqQ)
- [C#](docId\:NMLEiJmrOW1XL9kGEplxb)
- [Flutter](docId:5k27nwFPeEn1-v7XWz1HT)
- [Go](docId\:UnFDhdqan0QQo54R4_7a3)
- [Java](docId\:AdphTGCbC7b8i3krPoZIc)
- [JavaScript](docId\:OExtupzmm3AyVp8uWgIoC) – SDK versions 6.0.0 and later.
- [JavaScript (Browser)](docId\:MXN8iOzOMT-fcdpbgwg8C) – SDK versions 5.3.5 and earlier.
- [JavaScript (Node)](docId:7WZjge5drvVl3_iYhV4IQ) – SDK versions 5.3.5 and earlier.
- [PHP](docId:6QxzVc8cTzURcLkeCt_sf)
- [Python](docId\:IQktksuBns7WFb6Xv_OVE)
- [React](https://docs.developers.optimizely.com/feature-experimentation/docs/initialize-sdk-react)
- [React Native](https://docs.developers.optimizely.com/feature-experimentation/docs/initialize-sdk-reactnative)
- [Ruby](docId\:EZ82PrPXF05kJvmd7OoxE)
- [Swift](docId\:MbsuKcGHantE-rEn9zRfw)

## Handle multiple user IDs

If a user interacts with an experiment or targeted delivery while logged out and then logs in, Optimizely does not merge their logged-out identity with their logged-in identity. You should persist the logged-out ID and continue using it after login instead of generating a new one if you need to track a user's journey across login states (for example, seeing the same experiment variation before and after login).

### Risks to changing a logged-out ID

- **Inconsistent user experience** – Users may see different variations before and after logging in.
- **Corrupted experiment data** – Optimizely may attribute conversion events to different IDs, inflating visitor counts and skewing results.
- **Billing inefficiencies** – If you are on the Monthly Active User (MAU)-based pricing model, unnecessary user ID changes can increase your MAUs. See the [users and invoices](docId\:A5r9X69CRaxFk2RjeeOjY) section.

### Best practices for multiple user IDs

- Do not change user IDs in an existing user context, as it may alter variation assignments.
- Maintain separate user context instances for anonymous and logged-in users.
- Only use the logged-in user context where necessary, specifically in omnichannel experiments.
- Ensure event tracking is performed separately for each user context to maintain accurate results.

### Recommended approach for handling multiple user IDs

To maintain experiment consistency, create separate user context instances for anonymous and logged-in users. Never modify the user ID in an existing user context. The code sample demonstrating how to do this are available in the[ developer documentation](docId\:j0PPoMJWYbz04K76EKLUI).

## Users and invoices

Starting in September 2020, Optimizely Feature Experimentation offers [monthly active user (MAU)](docId:7AHMiX4UcWP1iNUY6X17X) pricing as an alternative to impressions pricing. Optimizely counts an MAU each time one of the following occurs for a unique user ID:

- **When you call a Decide method** – A decision event (impression) is triggered.
- **When you call a Track Event method** – A conversion event is triggered.

The MAU count includes unique anonymous IDs. If you use [Optimizely Web Experimentation](docId:1dLEYI3XpG0gwe0yaBzp4) and Optimizely Feature Experimentation, you can override anonymous Optimizely Web Experimentation user IDs with known Feature Experimentation user IDs to avoid overcounting. See [Bring your own ID](docId\:bWDe9bZ0aZQnSMwAzdlrE).
