> ## Documentation Index
> Fetch the complete documentation index at: https://confidence.spotify.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a Conditional Targeting Rule

> Learn how to create a conditional targeting rule to assign variants to users based on criteria and percentage allocation.

export const HowToSchema = ({name, description, steps = []}) => {
  const schema = {
    "@context": "https://schema.org",
    "@type": "HowTo",
    name,
    description
  };
  if (steps.length > 0) {
    schema.step = steps.map((s, i) => ({
      "@type": "HowToStep",
      position: i + 1,
      name: typeof s === "string" ? s : s.name,
      text: typeof s === "string" ? s : s.text || s.name
    }));
  }
  return <script type="application/ld+json" dangerouslySetInnerHTML={{
    __html: JSON.stringify(schema)
  }} />;
};

<HowToSchema
  name="Create a Conditional Targeting Rule"
  description="Learn how to create a conditional targeting rule to assign variants to users based on criteria and percentage allocation."
  steps={[
"Go to Confidence and select Flags on the left sidebar",
"Go to the flag you want to add a rule to",
"Click the add rule button in the Rules section",
"Select Create conditional targeting rule",
{
  name: "Step 1: Add a description (optional)",
  text: "Describe why you're adding this rule. This helps others understand the purpose and intended effect.",
},
{
  name: "Step 2: Define the targeting",
  text: "- Serve: Select the variant to serve to matching users. - To: Set the percentage of traffic that should receive the variant (0-100%). - Of: Select the attribute to use for randomization. - Matching: Define conditions based on context attributes, or select Any context to match all users.",
},
{
  name: "Step 3: Choose environments",
  text: "Select whether the rule applies to all environments or only specific environments. This step only appears if you have more than one environment.",
},
{
  name: "Click Create and activate",
  text: "The rule is created and immediately active. To create without activating, select Create as draft from the dropdown menu next to the button.",
},
]}
/>

[Conditional targeting rules](../flags/define-rules#conditional-targeting-rules) assign variants to users based on conditions and percentage allocation.

## Create a Conditional Targeting Rule

To create a conditional targeting rule, follow these steps.

<Steps>
  <Step title="Go to Confidence and select Flags on the left sidebar" />

  <Step title="Go to the flag you want to add a rule to" />

  <Step title="Click the add rule button in the Rules section" />

  <Step title="Select Create conditional targeting rule" />

  <Step title="Step 1: Add a description (optional)">
    Describe why you're adding this rule. This helps others understand the purpose and intended effect.
  </Step>

  <Step title="Step 2: Define the targeting">
    * **Serve**: Select the variant to serve to matching users.
    * **To**: Set the percentage of traffic that should receive the variant (0-100%).
    * **Of**: Select the attribute to use for randomization.
    * **Matching**: Define conditions based on context attributes, or select **Any context** to match all users.
  </Step>

  <Step title="Step 3: Choose environments">
    Select whether the rule applies to all environments or only specific environments. This step only appears if you have more than one environment.
  </Step>

  <Step title="Click Create and activate">
    The rule is created and immediately active. To create without activating, select **Create as draft** from the dropdown menu next to the button.
  </Step>
</Steps>

Traffic matching your conditions receives the variant according to the percentage you defined.

## Related Resources

<CardGroup cols={2}>
  <Card title="Rules Reference" href="/docs/flags/define-rules">
    Deep dive into rule types and configuration
  </Card>

  <Card title="Create Individual Targeting Rules" href="/docs/how-to-guides/create-individual-targeting-rule">
    Force specific variants for testing
  </Card>

  <Card title="Reorder Rules" href="/docs/how-to-guides/reorder-rules">
    Manage rule priority and order
  </Card>

  <Card title="Define Audience" href="/docs/how-to-guides/define-audience-criteria">
    Configure targeting criteria
  </Card>
</CardGroup>
