HomeGuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityOptimizely GitHubOptimizely NuGetLog In

Target audiences

Describes how to build and target specific audiences in Optimizely Full Stack Flags version.

Audiences give you control over which users have access to your flag rules, for example, A/B tests or targeted deliveries.

You will describe which users to include based on custom attributes like their location, device type, or subscription plan. After you create an audience, you can add it to your flag rule.

ResourceDescription
How does Audience Targeting Work in Optimizely?3-minute video explaining high-level how Audience targeting works in Optimizely

A single audience is defined based on custom user attributes. When you call user-based methods like Decide and Track Event, Optimizely determines whether a user qualifies for a flag by evaluating the attributes.

Create an audience

After you have created and implemented a few attributes, you can start building audiences. You can reuse audiences that you have created across multiple flags and rules.

Audience match conditions

Optimizely supports several match comparison operations that you can use in audience conditions:

Match conditionComment
has any value
String equals
String contains substring
The only match type that is compatible with SDK version releases before March 2019 (pre-3.0.0 releases for most major SDKs) is String equals.
Boolean is false
Boolean is true
Number equals
Number is less than
Number is less than or equal to
Number is greater than
Number is greater than or equal to
For SDK version compatibility with "...or equal to" comparisons, see the SDK Compatibility Matrix.
Version equals
Version is less than
Version is less than or equal to
Version is greater than
Version is greater than or equal to
See the SDK Compatibility Matrix for SDK version compatibility.

You can use version to target audiences based on the version of your application that they use. Note that in your code, you still have to implement the attribute by passing in your application's semantic version specifications as a string to Optimizely. You can pass versions in the format "major.minor.patch-prerelease+build", where "patch", "prerelease, and "build" are optional. For example, you can pass "3.0" or "1.5.1-beta" or "2.0.5-alpha+001".

While attributes are not explicitly typed in the Optimizely app, you will still need to pass in values of the correct type and format for your audience conditions to evaluate correctly. An attribute value of the incorrect type will result in a false-y audience evaluation.

The Edit Audience window lets you define audience conditions by either dragging and dropping attributes from the right side pane or defining complex JSON objects using the Code Mode window.

Build audiences from attributes

To create audiences from attributes:

  1. Navigate to Audiences > Saved.
  2. Click Create New Audience.
  3. Drag and drop the desired attributes into the Audience Conditions field. See Define attributes.
    For example, to create an audience of visitors who are located in the US, based on specific location values, add the "LOCATION" attribute.
  4. Select the match condition (see preceding table).
    Add other attributes to help create your audience. They can be added as "and" or "or" conditions. When you choose any match type option other than String equals for exact matching, a message displays that the option requires using an SDK version of 3.0, at minimum.
  5. Click Save Audience.

After creating an audience, you can set the target audience or audiences for flag rules.

Create audience combinations

Using the Optimizely opp, you can easily use "and", "or" operators (i.e., 'any' or 'all') to create an audience combination composed of other audiences:

If you want to use more complex nested logical operators with "and, or, not", you can do so in JSON in Code Mode. For details, see Create advanced audience combinations.

Add multiple audiences

You can assign multiple audiences, including audience combinations, to flag rules.

10581058

Multiple audiences, including an audience combination

Helpful information

Here are some tips and tricks for using audiences:

  • To QA an experiment, base an audience on a test cookie. Use the cookie to manually force a variation. See Use a QA audience.
  • To schedule turning on a feature flag, base an audience on an epoch time attribute. First, compute the time in your application, then pass the time in as an attribute. In this scenario, your audience attribute condition would look something like time number is greater than 12312412 and time number is less than 12355555.

Advanced audience information

Excluding audiences

You can easily use audiences to include or allowlist users, but not to exclude them.

For example, you cannot exclude all Brazilian users by simply dialing back to 0% traffic for that audience. That is because if you turn off audience evaluation for Brazilian users, they end up in the "Everyone" audience.

To actually exclude or blocklist audiences, you need to define audience combinations using JSON. For more information, see Create advanced audience combinations.

Overlapping audiences

If you define multiple, overlapping audiences and multiple rules for a single flag, then the ways in which a single user successively evaluates against the rules can get complicated. For more information, see Interactions between flag rules.

Nested logical operators

πŸ“˜

Beta feature

Advanced audiences created in Code Mode are not currently available in Full Stack projects created after February 2021, but will be re-enabled in a future release.

If you want to use nested logical operators (and, or, not) to create audience combinations, 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 sandwiches AND User likes soup)."

For more information, see Create advanced audience combinations.