Skip to main content

Segments & Targeting

Segments allow you to create reusable groups of users based on their attributes, making it easy to target specific audiences for feature rollouts and experiments.

How Segments Work

Think of segments as dynamic filters on your user base.

  1. Master User List: Your application maintains user data and traits (attributes).
  2. Dynamic Filtering: You define a segment by creating rules that filter this list (e.g., Country = US AND Plan = Premium).
  3. Manual Management: You can also manually add specific users to a segment (e.g., adding a specific User ID to a "Beta Testers" segment).

Once created, a segment becomes a reusable target. Instead of redefining "US Premium Users" for every single feature flag, you define it once as a Segment and simply select it when configuring your flags.

What are Segments?

Segments are groups of users defined by shared attributes or conditions. You can create segments based on:

  • User attributes: Plan type, account age, job title
  • Custom traits: Tags, preferences, behavior
  • Manual Inclusion: Specific list of User IDs

Note: While you can target features based on runtime context (like Country, Browser, or Device Type), Segments are typically used for more stable user attributes that define membership (like "Premium Plan" or "Beta Testers").

Creating Segments

  1. Navigate to Segments in the Toggly dashboard
  2. Click Create Segment
  3. Define segment conditions using attributes and operators
  4. Give the segment a name and description
  5. Click Create

Example Segment Conditions

# Premium Users Segment
- Attribute: plan
Operator: equals
Value: premium

# US-Based Users Segment
- Attribute: country
Operator: equals
Value: US

# Active Users Segment
- Attribute: last_active_days
Operator: less_than
Value: 30

Reusable Filters

To avoid repeating the same targeting logic across multiple feature flags (e.g., Country = 'US' OR 'CA'), you can create Named Filters.

A Named Filter acts as a reusable container for runtime logic. You can then reference it in your targeting rules just like a segment.

Example Hierarchy:

  1. User: Has attributes (Country: US, Plan: Premium).
  2. Segment: "Premium Users" (Plan = Premium).
  3. Named Filter: "North America" (Country IN ['US', 'CA', 'MX']).
  4. Targeting Rule: Enable feature for Segment: Premium Users AND Filter: North America.

This separation allows you to manage "Who they are" (Segments) separately from "Where/What they are" (Filters).

Gradual Rollouts

Gradual rollouts allow you to safely release features:

Percentage-Based Rollout

  1. Start with 1% of users
  2. Monitor metrics and error rates
  3. Gradually increase to 5%, 10%, 25%, 50%, 100%
  4. Roll back if issues are detected

Segment-Based Rollout

  1. Enable for internal users or beta testers
  2. Expand to specific customer segments
  3. Roll out to all users once validated

Canary Deployments

Use segments for canary deployments:

  1. Create a "Canary" segment with a small percentage of users
  2. Enable the feature for the canary segment
  3. Monitor metrics and performance
  4. Expand to larger segments if successful
  5. Roll back if issues occur

Best Practices

1. Start Small

Always start with a small percentage or specific segment when rolling out new features.

2. Monitor Closely

Watch metrics, error rates, and user feedback during rollouts.

3. Have a Rollback Plan

Know how to quickly disable a feature if issues arise.

4. Use Descriptive Segment Names

Name segments clearly: premium-users-us, beta-testers, internal-team.

5. Document Targeting Logic

Document why certain targeting rules are in place for future reference.

Next Steps