You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/basic-features/segments.md
+64-11Lines changed: 64 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,8 +7,8 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
7
7
# Segments
8
8
9
9
A segment is a subset of [identities](/basic-features/managing-identities.md), defined by a set of rules that match
10
-
identity [traits](managing-identities.md#identity-traits). An identity always belongs to a single environment and can
11
-
belong to any number of segments.
10
+
identity [traits](managing-identities.md#identity-traits) or other [context values](#context-values). An identity always
11
+
belongs to a single environment and can belong to any number of segments.
12
12
13
13
Once you have defined a segment, you can create **segment overrides** for features within an environment. A segment
14
14
override allows you to control the state of a feature only for identities that belong to a specific segment. This is
@@ -69,14 +69,14 @@ Segment rules are evaluated in order, i.e. from top to bottom when viewed in the
69
69
70
70
For example, consider the following segment:
71
71
72
-
1. 10% percentage split
72
+
1. 10% percentage split over identifier
73
73
2.`is_subscriber = true`
74
74
75
75
This segment would first select 10% of _all_ identities, and then choose subscribers from that cohort. Instead, if we
76
76
used the opposite order:
77
77
78
78
1.`is_subscriber = true`
79
-
2. 10% percentage split
79
+
2. 10% percentage split over identifier
80
80
81
81
This would first select all subscriber identities, and then randomly choose 10% of them.
82
82
@@ -94,6 +94,60 @@ flag is:
94
94
2. Segment overrides
95
95
3. Default value for the current environment
96
96
97
+
## Context values
98
+
99
+
:::warning
100
+
101
+
Currently, context values are only available for remote evaluation. In local evaluation, rules using context values will evaluate to `false`.
102
+
103
+
:::
104
+
105
+
In addition to identity [traits](managing-identities.md#identity-traits), you can use the following context values as
106
+
Segment rule properties:
107
+
108
+
-**Identifier**: a unique identifier for an identity, used for segment and multivariate feature flag targeting, and displayed in the Flagsmith UI. Useful for bucketing via the
109
+
[`% Split`](?operators=percent#operator-details) operator, or managing a list of users via the
110
+
[`In`](?operators=in#operator-details) operator.
111
+
-**Identity Key**: a key used when selecting a value for a multivariate feature, or for % split segmentation. Set to an internal identifier or a composite value based on the environment key and identifier, depending on Flagsmith implementation.
112
+
-**Environment Name**: an environment's human-readable name. Useful for restricting Segments to certain environments.
113
+
114
+
Context values can be used to control your targeting more precisely:
115
+
116
+
### Gradual rollout across tenants
117
+
118
+
Suppose your application supports users who can belong to multiple organisations. Now, you want to roll out a new
119
+
feature to 20% of your organisations, ensuring that users only have access to the feature when they are part of an organisation included in that 20%. If they switch to an organisation outside this group, they will no longer have access to the feature.
120
+
121
+
Here's how you might define a segment to achieve this:
This setup, along with a segment override, instructs the evaluation engine to enable the feature if the user's current organisation belongs to consistent 20% of all organisations.
128
+
129
+
:::info Use transient traits for multi-tenancy
130
+
131
+
To avoid persisting the `organisation_name` trait on the user identity, mark it as
132
+
[transient](../advanced-use/transient-traits.md).
133
+
134
+
:::
135
+
136
+
### Restrict evaluation to select environments
137
+
138
+
Segments and segment overrides are defined at the project level. This means they apply across all environments, so you
139
+
may want to restrict your targeting to specific environments — for example, to avoid exposing features in production
140
+
while still running complex evaluations in staging or development.
0 commit comments