Building blocks
Segments
Segments are made up of conditions against various attributes. They are the groups of users that you can target in your features via rules.
Create a segment#
Let's assume we already have a country attribute.
Now we with to create a segment that targets users from The Netherlands. We can do that by creating a segment:
description: Users from The Netherlandsconditions: - attribute: country operator: equals value: nlThe segment will match when the context in SDK contains an attribute country with value nl.
Conditions#
Targeting everyone#
You can target everyone via a segment by using asterisk * as the value in conditions:
description: Everyoneconditions: '*'Attribute#
The attribute is the name of the attribute you want to check against in the context.
Nested path#
If you are using an attribute that is of type object, you can make use of dot separated paths to access nester properties, like myAttribute.nestedProperty.
Operator#
There are numerous operators that can be used to compare the attribute value against given value. Find all supported operators in below section.
Value#
The value property is the value you want to operator to compare against. The type of the value depends on the attribute being used.
Operators#
These operators are supported as conditions:
| Operator | Type of attribute | Description |
|---|---|---|
exists | Attribute exists in context | |
notExists | Attribute does not exist | |
equals | any | Equals to |
notEquals | any | Not equals to |
greaterThan | integer, double | Greater than |
greaterThanOrEquals | integer, double | Greater than or equal to |
lessThan | integer, double | Less than |
lessThanOrEquals | integer, double | Less than or equal to |
contains | string | Contains string |
notContains | string | Does not contain string |
startsWith | string | Starts with string |
endsWith | string | Ends with string |
in | string | In array of strings |
notIn | string | Not in array of strings |
before | string, date | Date comparison |
after | string, date | Date comparison |
matches | string | Matches regex pattern |
notMatches | string | Does not match regex pattern |
semverEquals | string | Semver equals to |
semverNotEquals | string | Semver not equals to |
semverGreaterThan | string | Semver greater than |
semverGreaterThanOrEquals | string | Semver greater than or equals |
semverLessThan | string | Semver less than |
semverLessThanOrEquals | string | Semver less than or equals |
includes | array | Array includes value |
notIncludes | array | Array does not include value |
Examples of each operator below:
equals#
# ...conditions: - attribute: country operator: equals value: usnotEquals#
# ...conditions: - attribute: country operator: notEquals value: usgreaterThan#
# ...conditions: - attribute: age operator: greaterThan value: 21greaterThanOrEquals#
# ...conditions: - attribute: age operator: greaterThanOrEquals value: 18lessThan#
# ...conditions: - attribute: age operator: lessThan value: 65lessThanOrEquals#
# ...conditions: - attribute: age operator: lessThanOrEquals value: 64contains#
# ...conditions: - attribute: name operator: contains value: JohnnotContains#
# ...conditions: - attribute: name operator: notContains value: SmithstartsWith#
# ...conditions: - attribute: name operator: startsWith value: JohnendsWith#
# ...conditions: - attribute: name operator: endsWith value: Smithin#
# ...conditions: - attribute: country operator: in value: - be - nl - lunotIn#
# ...conditions: - attribute: country operator: notIn value: - fr - gb - debefore#
Date comparisons use ISO 8601 timestamps with an explicit timezone. Use Z for UTC or include an offset such as +01:00.
# ...conditions: - attribute: date operator: before value: 2023-12-25T00:00:00Zafter#
# ...conditions: - attribute: date operator: after value: 2023-12-25T00:00:00ZsemverEquals#
Semantic version operators follow standard prerelease ordering. Build metadata after + does not affect precedence or equality.
# ...conditions: - attribute: version operator: semverEquals value: 1.0.0semverNotEquals#
# ...conditions: - attribute: version operator: semverNotEquals value: 1.0.0semverGreaterThan#
# ...conditions: - attribute: version operator: semverGreaterThan value: 1.0.0semverGreaterThanOrEquals#
# ...conditions: - attribute: version operator: semverGreaterThanOrEquals value: 1.0.0semverLessThan#
# ...conditions: - attribute: version operator: semverLessThan value: 1.0.0semverLessThanOrEquals#
# ...conditions: - attribute: version operator: semverLessThanOrEquals value: 1.0.0exists#
# ...conditions: - attribute: country operator: existsnotExists#
# ...conditions: - attribute: country operator: notExistsincludes#
# ...conditions: - attribute: permissions operator: includes value: writenotIncludes#
# ...conditions: - attribute: permissions operator: notIncludes value: writematches#
Featurevisor projects support the portable regular expression flags g, i, m, and s. The g flag does not make evaluations stateful. Each match starts from the beginning, consistently across SDKs.
Patterns use a deliberately portable subset shared by every Featurevisor SDK. Character classes, anchors, capturing groups, alternation, escaped literals, and ordinary quantifiers are supported. Do not use lookaround, backreferences, named or noncapturing groups, atomic groups, inline mode groups, or possessive quantifiers. npx featurevisor lint rejects these constructs before a datafile is built.
# ...conditions: - attribute: email operator: matches value: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ # optional regex flags regexFlags: i # case-insensitivenotMatches#
# ...conditions: - attribute: email operator: notMatches value: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ # optional regex flags regexFlags: i # case-insensitiveAdvanced conditions#
Conditions can also be combined using and, or, and not operators.
and#
When using and, it means all the direct children conditions under it must match against provided context.
# ...conditions: and: - attribute: country operator: equals value: us - attribute: device operator: equals value: iPhoneBy default if and is not specified directly under conditions, it is implied.
or#
When using or, it means at least one of the direct children conditions under it must match against provided context.
# ...conditions: or: - attribute: country operator: equals value: us - attribute: country operator: equals value: canot#
When using not, the direct children under it are treated as an implied and, and the final result is negated.
# ...conditions: not: - attribute: country operator: equals value: usThis means multiple direct children behave as "not all of these conditions match":
# ...conditions: not: - attribute: country operator: equals value: us - attribute: device operator: equals value: iPhoneIf you want "none of these conditions match", wrap them in or:
# ...conditions: not: - or: - attribute: country operator: equals value: us - attribute: country operator: equals value: caComplex#
and and or can be combined to create complex conditions:
# ...conditions: - and: - attribute: device operator: equals value: iPhone - or: - attribute: country operator: equals value: us - attribute: country operator: equals value: caYou can also nest and, or, and not operators:
# ...conditions: - not: - or: - attribute: country operator: equals value: us - attribute: country operator: equals value: caArchiving#
You can archive a segment by setting archived: true:
archived: truedescription: Users from The Netherlandsconditions: - attribute: country operator: equals value: nl
