---
title: Create advanced audience combinations in Feature Experimentation
slug: feature-experimentation/docs/create-advanced-audience-combinations-in-feature-experimentation
docTags: 
createdAt: 2026-08-05T20:39:51.000Z
---

- Optimizely Feature Experimentation

Using the [Optimizely Feature Experimentation UI](https://app.optimizely.com), you can use the `and` or `or` operators (that is, `any` or `all`) to [create an audience combination composed of other audiences](docId\:UDBvr5a8WHNkyOqzPhOr9).

If you want to use more complex nested logical operators with `and`, `or`, or `not`, you can do so in JSON in Code Mode. Each audience is a rule like `User likes salads`, and an audience combination is a boolean combination of these rules, like `User likes pizza NOT (User likes salads AND User likes soup)`

## SDK version compatibility

SDK versions released after February 2019 are compatible with the advanced audience combinations, `Match all audiences` or `Custom`.

If a flag rule using the `Match all audiences` or `Custom` audience type is evaluated with an older SDK, targeting will not pass and conversion events and decision events will be lost.

### Minimum SDK version

The table describes the minimum SDK version required for advanced audience combinations. For the current SDK versions, [refer to the SDK compatibility matrix](docId:2shbZfPCkPAZ0mlZpL1TU).

| Optimizely Feature Experimentation SDK                                 | Minimum version |
| ---------------------------------------------------------------------- | --------------- |
| Android C# Java JavaScript (Browser) JavaScript (Node) PHP Python Ruby | v3.0.0          |
| Flutter                                                                | v1.0.1          |
| Go                                                                     | v1.0.0          |
| React React Native                                                     | v1.0.0          |
| Swift                                                                  | v3.1.0          |

## Create an advanced audience using Code Mode

Create or select a [flag](docId\:eH-UMm_rOn_GdGDGLV6__) with at least one [rule](docId\:F8tdFPnxECabBXsQkBqDt) (targeted delivery, A/B test, or Multi-armed bandit optimization). Then click **Code Mode** on a rule to access the code editor and define your JSON audience combination.&#x20;

![136a31b-image.png](https://api.archbee.com/api/optimize/BrbvVORKJ5iIeSMZye5kI/czvc6lAEJGm4Kbx5YRty4-20260720-145741.png)

### Get the audience identifiers

Each individual condition is a JSON object with an `audience_id`. You can add these identifiers directly in Code Mode or add the audience identifier automatically by selecting the search box labeled **Search and add audiences** and selecting an audience.

![Click the Audiences ](https://api.archbee.com/api/optimize/BrbvVORKJ5iIeSMZye5kI/Etg1RZ0ZDOgk1DWocL0dT-20260720-145741.png)

### Define the conditions

Conditions are joined together in lists:

- The first element in each list is an operator, `"and"`, `"or"`, or `"not"`, and the rest of the conditions are combined using that operator.
- You can replace any individual condition with another list, which lets you create a nested structure of `"and"` and `"or"` conditions.
- A `"not"` list should only have one condition or list, which will be negated. A `"not"` with a list of other conditions like `["not", ["and", {...}, {...}]]` can negate the entire result of the child condition list.

The following example shows how you could define audience combination conditions. You can also create a feature with an audience combination in Optimizely and look at the **Code Mode** view.

```javascript
// "User who loves salads"
// or "User who loves sandwiches"
[
  "or",
  {
    "audience_id": 1038980040
  },
  {
    "audience_id": 1033280055
  }
]

// "User who loves salads"
// or "User who loves sandwiches"
// or does not "Like both salads & sandwiches"
[
  "or",
  {
    "audience_id": 1038980040
  },
  {
    "audience_id": 1033280055
  },
  [
    "not",
    {
      "audience_id": 1120870079
    }
  ]
]

// Is not "User who loves salads"
// AND is not "User who loves sandwiches"
[
  "not",
  [
    "and",
    {
      "audience_id": 1038980040
    },
    {
      "audience_id": 1033280055
    }
  ]
]
```

## Troubleshoot code mode

The following may be helpful to troubleshoot errors that arise while using **Code Mode**.

### Incorrect operator

If you use an invalid operator, you see this error.

![Incorrect operator error message](https://api.archbee.com/api/optimize/BrbvVORKJ5iIeSMZye5kI/9r_yENFdQlw8YWDlb47Qb-20260720-145741.png)

Refer to [Define the conditions](docId\:f-kDrilUaQvTtUINK2Wk1) for a list of the acceptable operators.

### Unable to leave code mode

If your audience is too advanced, you are not be able to toggle back to **Non-Code Mode**. Instead, when you click **Non-Code Mode** you see the following message: 

![Non-Code Mode message](https://api.archbee.com/api/optimize/BrbvVORKJ5iIeSMZye5kI/QhiyGRW3CWiX01e7P76eX-20260720-145741.png)

This does not mean that your audience is incorrect. Instead, it is alerting you that your audience cannot be represented in the simplified, non-code view. You can continue to edit your audience in **Code Mode**.

### Audience conditions must be valid JSON

Your audience must be written in [valid JSON](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON). If you have a syntax error, you see the following error: 

![Invalid JSON error message](https://api.archbee.com/api/optimize/BrbvVORKJ5iIeSMZye5kI/8khlj68Z-M-1t3DZ-8L5s-20260720-145741.png)

Additionally, when returning to **Non-Code Mode**, without defining an audience, you must have an opening and closing bracket to do so. If you select **Non-Code Mode** with an empty audience condition, you get the following error: 

![Empty Non-Code mode error message](https://api.archbee.com/api/optimize/BrbvVORKJ5iIeSMZye5kI/OoeOUcd6gZ5YPGpgOc3h7-20260720-145741.png)

To fix the error, add `[]`, like the following image:

![](https://api.archbee.com/api/optimize/BrbvVORKJ5iIeSMZye5kI/3LtFbHHWcWzDtZitJSKht-20260720-145741.png)
