Targeting Rules

Enable flags for specific users, groups, or environments.

Tar­get­ing rules let you enable a flag for spe­cif­ic users, groups, or envi­ron­ments with­out turn­ing it on for everyone.

How rules work #

Rules are eval­u­at­ed in order. If any rule match­es, the flag is enabled for that request. If no rules match, eval­u­a­tion falls through to the per­cent­age roll­out (if con­fig­ured), and then to the default of false.

Rules are eval­u­at­ed before per­cent­age roll­outs. A user who match­es a tar­get­ing rule gets the flag regard­less of the roll­out percentage.

Rule types #

Envi­ron­ment

Match against Craft’s cur­rent envi­ron­ment (CRAFT_ENVIRONMENT).

FieldVal­ue to enter
Rule TypeEnvi­ron­ment
Rule Val­ueThe envi­ron­ment name, e.g. staging, production, dev

Use this to enable a flag only in spe­cif­ic envi­ron­ments. For exam­ple, you can turn on a flag in staging for test­ing while keep­ing it off in production.

User ID

Tar­get a spe­cif­ic user by their Craft user ID.

FieldVal­ue to enter
Rule TypeUser ID
Rule Val­ueThe user’s numer­ic ID, e.g. 42

Use this for dog­food­ing: give a spe­cif­ic devel­op­er or stake­hold­er ear­ly access to a feature.

User Group

Tar­get all users in a Craft user group.

FieldVal­ue to enter
Rule TypeUser Group
Rule Val­ueThe group’s han­dle, e.g. betaTesters, editors

Use this to enable a fea­ture for an entire group, like grant­i­ng beta access to every­one in a betaTesters group.

Sub­scrip­tion Plan

Tar­get users with an active Craft Com­merce subscription.

FieldVal­ue to enter
Rule TypeSub­scrip­tion Plan
Rule Val­ueThe sub­scrip­tion plan’s han­dle, e.g. premium, pro

This rule type is only avail­able when Craft Com­merce is installed. It match­es users who have an active sub­scrip­tion to the spec­i­fied plan.

Com­bin­ing rules #

You can add mul­ti­ple rules to a sin­gle flag. Since rules are OR’d, a flag with these three rules:

  • Envi­ron­ment = staging
  • User Group = betaTesters
  • User ID = 7

…would be enabled for any­one in the staging envi­ron­ment, or any user in the betaTesters group, or user 7 specif­i­cal­ly regard­less of which envi­ron­ment they’re in or which groups they belong to.