Skip to content

Rules and rollouts

Rules let you choose who sees a value before the default applies.

Use tenant targeting when one customer should receive a feature early.

Terminal window
checkoutV2: flag.boolean({
default: false,
rules: [
flag.tenants(["tenant_acme"]).value(true),
],
})

Pass the tenant ID when you evaluate the flag.

Terminal window
const enabled = await flags.enabled("checkoutV2", {
tenantId: tenant.id,
})

Use user targeting for a direct allow list or a narrow beta.

Terminal window
waitlistAccess: flag.boolean({
default: false,
rules: [
flag.users(["user_123"]).value(true),
],
})

Use attributes for app-owned facts such as plan, region, or tier.

Terminal window
advancedReports: flag.boolean({
default: false,
rules: [
flag.attribute("plan").equals("enterprise").value(true),
],
})

Pass attributes from the current request, tenant, or domain object.

Terminal window
const enabled = await flags.enabled("advancedReports", {
attributes: {
plan: tenant.plan,
region: tenant.region,
},
})

Use a percentage rule when you want gradual exposure.

Terminal window
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:

  • userId
  • tenantId
  • sessionId

When a flag has multiple rules, Layeron checks them in the order they appear in your code. Put the most specific rule first.

Terminal window
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),
],
})
  • 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.