Rules and rollouts
Rules let you choose who sees a value before the default applies.
Tenant targeting
Section titled “Tenant targeting”Use tenant targeting when one customer should receive a feature early.
checkoutV2: flag.boolean({ default: false, rules: [ flag.tenants(["tenant_acme"]).value(true), ],})Pass the tenant ID when you evaluate the flag.
const enabled = await flags.enabled("checkoutV2", { tenantId: tenant.id,})User targeting
Section titled “User targeting”Use user targeting for a direct allow list or a narrow beta.
waitlistAccess: flag.boolean({ default: false, rules: [ flag.users(["user_123"]).value(true), ],})Attribute targeting
Section titled “Attribute targeting”Use attributes for app-owned facts such as plan, region, or tier.
advancedReports: flag.boolean({ default: false, rules: [ flag.attribute("plan").equals("enterprise").value(true), ],})Pass attributes from the current request, tenant, or domain object.
const enabled = await flags.enabled("advancedReports", { attributes: { plan: tenant.plan, region: tenant.region, },})Percentage rollouts
Section titled “Percentage rollouts”Use a percentage rule when you want gradual exposure.
checkoutV2: flag.boolean({ default: false, rules: [ flag.percentage(10, { stickiness: "userId" }).value(true), ],})The stickiness key keeps the same subject on the same side of the rollout as the percentage changes.
Common choices:
userIdtenantIdsessionId
Rule order
Section titled “Rule order”When a flag has multiple rules, Layeron checks them in the order they appear in your code. Put the most specific rule first.
checkoutV2: flag.boolean({ default: false, environments: { preview: true, }, rules: [ flag.tenants(["tenant_acme"]).value(true), flag.users(["user_123"]).value(true), flag.percentage(10, { stickiness: "userId" }).value(true), ],})When to use which rule
Section titled “When to use which rule”- Use tenant targeting for account-level access.
- Use user targeting for internal testers or narrow betas.
- Use attribute targeting for product tiers or plans.
- Use percentage rollouts for gradual launches.