> ## Documentation Index
> Fetch the complete documentation index at: https://backstage.spotify.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Audience

> Define audiences with inclusion criteria and logical operators to target specific users or units in Confidence Flags rules.

Use an audience to create a slice of your population that you can use in rules.

The audience is the set of users or other units that are eligible for a rule.

## Inclusion Criteria

The audience is a set of filters that describe the conditions for inclusion.
The filters must match the values in the evaluation context that clients use when resolving flags.
For example, if you add `country is Sweden` as an inclusion criterion, you must include `country` in the evaluation context.
The value for `country` in the evaluation context must match `Sweden` to be part of the audience.

Filters can vary in complexity. They can, for example, exactly match a user ID,
or be more elaborate and match users in a certain country that are using a specific
browser with a specific version. You select how multiple criteria should logically work
together by choosing the operator to be `AND` or `OR`.

You can add multiple criteria to a group. With groups, you can create arbitrarily
complex inclusion criteria by adjusting the logical operator used between and within
groups.

### Add an Inclusion Criterion

To add a criterion, follow these steps.

1. Go to where you want to add the criterion in the Confidence Flags plugin in Portal. This can be in an already
   created rule or a new flag rule.
2. Click **+ Add attribute criterion** in the **Inclusion Criteria** part of the **Audience** section.
3. Type in the name of the criterion, and select its type.
4. Select the appropriate operator by clicking it to unfold the dropdown list.

If the field has been seen by Confidence Flags before, it is auto-completed and the
type is populated for you. The operators available to choose from is
dependent on the type of the field. For example, if the field is a string, the
operator is one of: `is` (equals), `is not` (not equals), `in` (one of many) or
`not in` (not one of many).

## Allocation

The allocation is the percentage of the targeted audience (after the inclusion criteria) that you
want to allocate.
You set the allocation as a percentage of the total audience size.
For example, if the audience size is potentially 2,000, a 50% allocation allocates 1,000 users.

## Randomization

Confidence Flags uses randomization to assign variants to users. To randomize, Confidence Flags needs to know which field in the evaluation context
it should take the value from. If you do not specify a randomization field,
Confidence Flags uses the value from the `targeting_key` field in the evaluation
context. If the field is not present in the evaluation context, the rule
doesn't match and users are not assigned an variant by the rule.

The randomization field is often an identifier that has a value that is unique
for each user. For example, if you have a field called `user_id` in the
evaluation context, you can use that field for randomization.

<Info>
  The field in the evaluation context that you use for randomization must be a
  string.
</Info>
