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.
- Master User List: Your application maintains user data and traits (attributes).
- Dynamic Filtering: You define a segment by creating rules that filter this list (e.g.,
Country = USANDPlan = Premium). - Manual Management: You can also manually add specific users to a segment (e.g., adding a specific
User IDto 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
- Navigate to Segments in the Toggly dashboard
- Click Create Segment
- Define segment conditions using attributes and operators
- Give the segment a name and description
- 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:
- User: Has attributes (Country: US, Plan: Premium).
- Segment: "Premium Users" (Plan = Premium).
- Named Filter: "North America" (Country IN ['US', 'CA', 'MX']).
- 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
- Start with 1% of users
- Monitor metrics and error rates
- Gradually increase to 5%, 10%, 25%, 50%, 100%
- Roll back if issues are detected
Segment-Based Rollout
- Enable for internal users or beta testers
- Expand to specific customer segments
- Roll out to all users once validated
Canary Deployments
Use segments for canary deployments:
- Create a "Canary" segment with a small percentage of users
- Enable the feature for the canary segment
- Monitor metrics and performance
- Expand to larger segments if successful
- 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
- Learn about Rollouts and Experiments
- Explore Creating Feature Flags
- Read about Monitoring Metrics