In Split, a segment is a list of user ids. A segment is a list (or group) of users which can be linked up with a feature flag in Split. While users can be added to feature flags individually, segments provide a convenient way to add groups of users with common roles or characteristics.
Creating a Segment in Split
You can log in or create a free Split account and create your segments in the Split Admin Console. You then add users to your segment by creating meaningful strings that will be the user ids.
How Segments Work With Feature Flags in Split
Once created, you can add a segment to a feature flag definition in the Split Admin Console instead of adding individual user ids. (The segment “Traffic type” and “Environment” settings must match these same settings of the feature flag.) You can add a segment to a feature flag’s individual targets. You can also create a feature flag targeting rule and set the percentage for the feature flag result for that segment. For instance, you can set a feature flag called high_contrast_color_scheme
to be on
for 50% of the users in a segment named american_customers
.
When you evaluate your feature flag in code, you provide a key along with the feature flag name. If the key exactly matches one of the user ids in your segment (the key cannot be the segment name), then Split will execute the feature flag targeting rule that targets that segment.