Targeting Rules
Enable flags for specific users, groups, or environments.
Targeting rules let you enable a flag for specific users, groups, or environments without turning it on for everyone.
How rules work #
Rules are evaluated in order. If any rule matches, the flag is enabled for that request. If no rules match, evaluation falls through to the percentage rollout (if configured), and then to the default of false.
Rules are evaluated before percentage rollouts. A user who matches a targeting rule gets the flag regardless of the rollout percentage.
Rule types #
Environment
Match against Craft’s current environment (CRAFT_ENVIRONMENT).
| Field | Value to enter |
|---|---|
| Rule Type | Environment |
| Rule Value | The environment name, e.g. staging, production, dev |
Use this to enable a flag only in specific environments. For example, you can turn on a flag in staging for testing while keeping it off in production.
User ID
Target a specific user by their Craft user ID.
| Field | Value to enter |
|---|---|
| Rule Type | User ID |
| Rule Value | The user’s numeric ID, e.g. 42 |
Use this for dogfooding: give a specific developer or stakeholder early access to a feature.
User Group
Target all users in a Craft user group.
| Field | Value to enter |
|---|---|
| Rule Type | User Group |
| Rule Value | The group’s handle, e.g. betaTesters, editors |
Use this to enable a feature for an entire group, like granting beta access to everyone in a betaTesters group.
Subscription Plan
Target users with an active Craft Commerce subscription.
| Field | Value to enter |
|---|---|
| Rule Type | Subscription Plan |
| Rule Value | The subscription plan’s handle, e.g. premium, pro |
This rule type is only available when Craft Commerce is installed. It matches users who have an active subscription to the specified plan.
Combining rules #
You can add multiple rules to a single flag. Since rules are OR’d, a flag with these three rules:
- Environment =
staging - User Group =
betaTesters - User ID =
7
…would be enabled for anyone in the staging environment, or any user in the betaTesters group, or user 7 specifically regardless of which environment they’re in or which groups they belong to.