---
title: Real-Time Audiences for Feature Experimentation segment qualification methods for the JavaScript SDK v6+
slug: feature-experimentation/docs/real-time-audiences-for-feature-experimentation-segment-qualification-methods-for-the-javascript-sdk
docTags: 
createdAt: 2026-08-05T20:39:52.000Z
---

## Prerequisites

You must enable and configure [Real-Time Audiences for Feature Experimentation](docId:6UBBxxRv331nBIVZ2lun8) before fetching qualified segments and checking if the user is qualified for the given audience segment.

## Minimum SDK version

v6.0.0+

For versions 5.3.5 and below, see [JavaScript (Browser) SDK](https://docs.developers.optimizely.com/feature-experimentation/docs/real-time-segments-for-feature-experimentation-segment-qualification-methods-javascript) or [JavaScript (Node) SDK](https://docs.developers.optimizely.com/feature-experimentation/docs/real-time-segments-for-feature-experimentation-segment-qualification-methods-javascript-node). See the [SDK compatibility matrix](docId:2shbZfPCkPAZ0mlZpL1TU) documentation for a list of current SDK releases and the features they support.

## `fetchQualifiedSegments`

Fetches all qualified audience segments for the user context.

`fetchQualifiedSegments` is a method of the `UserContext` object. See [OptimizelyUserContext](docId\:OExtupzmm3AyVp8uWgIoC) for details.

### Parameters

The following table describes the parameters for the `fetchQualifiedSegments` method:

| Parameter            | Type                       | Description                                                |
| -------------------- | -------------------------- | ---------------------------------------------------------- |
| `options `(optional) | OptimizelySegmentOption\[] | A set of options for fetching qualified segments from ODP. |

### Returns

This method returns a `Promise<boolean>`, which resolves with `true` if segments are fetched, and `false` otherwise.

:::hint{type="info"}
**Note**
You can read and write directly to the qualified segments array. This lets you bypass the remote fetching process from ODP or use your own fetching service. This can be helpful when testing or debugging.
:::

### Example

The following is an example of calling the `fetchQualifiedSegments` method and accessing the returned completion object:

```javascript
const attributes = { "app_version": "1.3.2" };

const user = optimizely.createUserContext("fs-id-123", attributes);

const asyncFunction = async () => {
  const fetched = await user.fetchQualifiedSegments()
  console.log(fetched) // true
  console.log(user.qualifiedSegments) // Updated qualified audience segments for the target user
}
// Call user.decide() to get a feature flag decision for a user. Each decision includes whether the flag is enabled and which variation the user receives.
```

After the audience segments are fetched, they are cached. This means that if you are requesting the segments again (when new user contexts are created), the audience segment information can be retrieved from the cache instead of being fetched again from the remote ODP server.

The cache is used for the `fetchQualifiedSegments` call. This method is called on the user context (the user context is fixed, including the real-time audiences the user qualifies for).

The cache *only* applies when calling the `fetchQualifiedSegments` call. If you set the cache timeout to 0, the cache is disabled. Optimizely uses the LRU algorithm, so the oldest record is bumped out when the maximum size is reached. If there is a cache miss upon the method call, Optimizely makes a network request.

If you would like to bypass caching, you can add the following options to your `options` array:

- `OptimizelySegmentOption.IGNORE_CACHE` – Bypass segments cache for lookup and save.
- `OptimizelySegmentOption.RESET_CACHE` – Reset all segments cache.

### `fetchQualifiedSegments` network diagram

The following diagram shows the network calls between your application, the Feature Experimentation JavaScript SDK, and the ODP server when calling `fetchQualifiedSegments`:

![](https://api.archbee.com/api/optimize/BrbvVORKJ5iIeSMZye5kI/ydhrIVhD87879LZ2FedbE_27185c40095f826754cebd38de1ca523fd63b0a69a4298a327d4af34f0e4ee62-image.png)

1. Your application calls the `fetchQualifiedSegments` method.
2. The Feature Experimentation JavaScript SDK makes a GraphQL call to ODP to fetch segments the user ID qualifies for.
3. ODP responds with the qualified audience segments.
4. The JavaScript SDK automatically caches the fetched segments mapping the user ID to the qualified segments.
5. The `fetchQualifiedSegments` method returns a boolean if the qualified segments array was updated.
6. Call the `decide` method to get the flag decision for a given user, a decision object that contains the flag's status (enabled or disabled), and the assigned variation key.

## `isQualifiedFor`

Check if the user is qualified for the given segment.

### Parameters

The following table describes the parameters for the `isQualifiedFor` method:

| Parameter | Type   | Description                                                         |
| --------- | ------ | ------------------------------------------------------------------- |
| segment   | String | The ODP audience segment name to check if the user is qualified for |

### Returns

`true` if the user is qualified.

### Example

The following is an example of whether the user is qualified for an ODP segment:

```javascript
const attributes = { "laptop_os": "mac" };
const user = optimizely.createUserContext("user123", attributes);

const isQualified = user.isQualifiedFor('segment1');
console.log(isQualified); // true
```

## Source files

The language and platform source files containing the implementation for the JavaScript SDK are available on [GitHub](https://github.com/optimizely/javascript-sdk/blob/master/lib/optimizely/index.ts).
