Skip to main content

Targeting Rules

Targeting rules determine which users see which features. Learn how to configure effective targeting rules.

Types of Targeting

All Users

Enable the feature for everyone. No targeting rules needed.

Targeting: All Users

Percentage Rollout

Gradually roll out to a percentage of users. Toggly automatically distributes the feature across users.

Targeting: Percentage Rollout
Percentage: 25% # Enable for 25% of users

User Segments

Target specific user segments you've created.

Targeting: User Segments
Segments:
- premium-users
- beta-testers
- internal-team

Custom Rules

Create complex targeting rules with multiple conditions.

Targeting: Custom Rules
Rule: (plan = 'premium' AND country IN ['US', 'GB']) OR (plan = 'enterprise')

Targeting Operators

Toggly supports various operators:

  • Equals (=): Exact match
  • Not Equals (!=): Exclude value
  • Contains (contains): String contains
  • In (in): Value in list
  • Greater Than (>): Numeric comparison
  • Less Than (<): Numeric comparison
  • Regex Match (matches): Pattern matching

Building Targeting Rules

Simple Conditions

# Enable for premium users
plan = 'premium'

# Enable for US users
country = 'US'

# Enable for users with specific tag
tags contains 'beta'

Multiple Conditions

Combine conditions with AND/OR:

# Premium users in US
plan = 'premium' AND country = 'US'

# Premium or enterprise users
plan = 'premium' OR plan = 'enterprise'

# Complex condition
(plan = 'premium' AND country = 'US') OR (plan = 'enterprise')

List Operations

# Users in specific countries
country IN ['US', 'GB', 'CA', 'AU']

# Users not in specific countries
country NOT IN ['CN', 'RU']

Percentage Rollouts

Gradual rollouts reduce risk:

Starting a Rollout

  1. Start with 1% of users
  2. Monitor metrics for 24-48 hours
  3. Increase to 5% if no issues
  4. Continue increasing: 10%, 25%, 50%, 100%

Rollout Best Practices

  • Start Small: Begin with 1-5%
  • Monitor Closely: Watch metrics and error rates
  • Increase Gradually: Don't jump from 10% to 100%
  • Have Rollback Plan: Know how to disable quickly

Segment-Based Targeting

Use segments for organized targeting:

Creating Segments

  1. Navigate to Segments
  2. Click Create Segment
  3. Define segment conditions
  4. Name and save the segment

Using Segments

Targeting: User Segments
Segments:
- premium-users-us
- beta-testers
- internal-team

Custom Rules Examples

Geographic Targeting

# US and Canada only
country IN ['US', 'CA']

# Exclude specific regions
country NOT IN ['CN', 'RU']

Plan-Based Targeting

# Premium and enterprise only
plan IN ['premium', 'enterprise']

# Not free plan
plan != 'free'

Date-Based Targeting

# Users who signed up in last 30 days
signupDate > '2024-01-01'

# Users with account age > 90 days
accountAge > 90

Complex Targeting

# Premium US users OR enterprise users OR beta testers
(plan = 'premium' AND country = 'US') OR plan = 'enterprise' OR tags contains 'beta'

Testing Targeting Rules

Test with Specific Users

Use the evaluation context to test:

const context = {
userId: 'test-user-123',
traits: {
plan: 'premium',
country: 'US',
tags: ['beta']
}
};

const result = await toggly.evaluateFeature('my-feature', context);

Verify in Dashboard

  1. Navigate to the feature flag
  2. Click Test Targeting
  3. Enter test user attributes
  4. Verify the result matches expectations

Targeting Best Practices

1. Start Broad, Narrow Later

Start with broader targeting (e.g., all users or large percentage), then narrow based on results.

2. Use Segments for Reusability

Create segments for commonly used targeting conditions.

3. Document Complex Rules

Add comments or descriptions explaining why targeting rules exist.

4. Test Before Production

Always test targeting rules in Development or Staging first.

5. Monitor Metrics

Watch metrics to ensure targeting is working as expected.

Next Steps