# Targeting Rules

Targeting rules let you serve different flag values to different users based on their attributes, organization membership, or custom criteria.

## How Targeting Works

When a flag is evaluated, AccessIQ checks targeting rules in order from top to bottom. The first matching rule determines the value. If no rule matches, the default value is returned.

## Creating a Targeting Rule

1. Open a flag and select an environment.
2. Click **Add Rule**.
3. Define the conditions and the value to serve when matched.
4. Click **Save**.

## Rule Conditions

Each rule has one or more conditions. All conditions in a rule must be true for the rule to match (AND logic). To use OR logic, create separate rules.

### Available Attributes

| Attribute        | Description                  | Example             |
| ---------------- | ---------------------------- | ------------------- |
| User ID          | The user's unique identifier | `user-123`          |
| Email            | The user's email address     | `*@acme.com`        |
| Organization     | The user's organization      | `Engineering`       |
| Role             | The user's role              | `Admin`             |
| Custom attribute | Any attribute you define     | `plan = enterprise` |

### Operators

| Operator     | Works with | Example                           |
| ------------ | ---------- | --------------------------------- |
| equals       | All types  | `email equals john@acme.com`      |
| not equals   | All types  | `role not equals guest`           |
| contains     | Strings    | `email contains @acme.com`        |
| starts with  | Strings    | `email starts with admin`         |
| ends with    | Strings    | `email ends with @acme.com`       |
| in list      | All types  | `userId in list [user-1, user-2]` |
| not in list  | All types  | `userId not in list [user-5]`     |
| greater than | Numbers    | `loginCount greater than 10`      |
| less than    | Numbers    | `loginCount less than 5`          |

## Rule Priority

Rules are evaluated top to bottom. Drag rules to reorder them. The first matching rule wins.

**Example:**

| Priority | Rule                                    | Value   |
| -------- | --------------------------------------- | ------- |
| 1        | Email in `[qa@acme.com, test@acme.com]` | `true`  |
| 2        | Organization is `Beta Testers`          | `true`  |
| 3        | Default                                 | `false` |

In this example, the QA team always sees the feature. Members of the Beta Testers organization also see it. Everyone else does not.

## Individual User Targeting

For quick testing, you can target specific users without creating a full rule:

1. On the flag's environment page, find **Individual Targets**.
2. Add a user and set their value.
3. Individual targets always take priority over rules.

## Best Practices

* Use individual targets for internal testing, then switch to rule-based targeting for broader rollouts.
* Keep the number of rules manageable -- if you have many rules, consider whether a role or group-based approach would be simpler.
* Review and clean up rules after a feature is fully launched.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://accessiq.gitbook.io/accessiq-docs/feature-entitlements/targeting-rules.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
