Skip to Content
Config SystemDefining Segments

Defining Segments

Segments group customers based on rules and attributes. Define segments in your config to create rule-based customer groups that can be used for content targeting, experiments, and analytics.

Segment Interface

interface ApplyConfigSegmentInput { key: string; // Unique identifier (e.g., 'vip-customers') name: string; // Display name description?: string; // What this segment represents rules?: Record<string, unknown>; // Matching rules evaluationMode?: string; // 'realtime' or 'batch' isActive?: boolean; // Whether the segment is evaluating (default: true) }

Basic Example

import { defineConfig, defineSegment } from '@eide/foir-cli/configs'; export default defineConfig({ key: 'my-app', name: 'My App', segments: [ defineSegment({ key: 'vip-customers', name: 'VIP Customers', description: 'Customers with total spend over $500', rules: { type: 'condition', left: { type: 'field', path: 'totalSpend' }, operator: 'greaterThan', right: { type: 'literal', value: 500 }, }, isActive: true, }), ], });

Rules Structure

Segment rules use a condition expression format. Each rule specifies a left operand, an operator, and a right operand.

Simple Condition

rules: { type: 'condition', left: { type: 'field', path: 'orderCount' }, operator: 'greaterThan', right: { type: 'literal', value: 5 }, }

Combining Conditions

Use and or or to combine multiple conditions:

rules: { type: 'and', conditions: [ { type: 'condition', left: { type: 'field', path: 'totalSpend' }, operator: 'greaterThan', right: { type: 'literal', value: 500 }, }, { type: 'condition', left: { type: 'field', path: 'orderCount' }, operator: 'greaterThan', right: { type: 'literal', value: 5 }, }, ], }

Available Operators

OperatorDescription
equalsExact match
notEqualsDoes not match
greaterThanGreater than a value
lessThanLess than a value
greaterThanOrEqualGreater than or equal
lessThanOrEqualLess than or equal
containsString contains value
startsWithString starts with value
inValue is in a list
notInValue is not in a list

Evaluation Modes

ModeDescriptionUse Case
realtimeEvaluated on every content requestTargeting rules that need instant accuracy
batchEvaluated periodically in the backgroundLarge segments where slight delay is acceptable
segments: [ { key: 'high-value', name: 'High Value', evaluationMode: 'realtime', rules: { ... }, }, { key: 'inactive-users', name: 'Inactive Users', evaluationMode: 'batch', rules: { ... }, }, ]

Examples

Mobile Users

defineSegment({ key: 'mobile-users', name: 'Mobile Users', description: 'Customers who primarily use mobile devices', rules: { type: 'condition', left: { type: 'field', path: 'primaryDevice' }, operator: 'equals', right: { type: 'literal', value: 'mobile' }, }, evaluationMode: 'realtime', isActive: true, })

High-Spend Repeat Buyers

defineSegment({ key: 'high-spend-repeat', name: 'High-Spend Repeat Buyers', description: 'Customers with 10+ orders and over $1000 total spend', rules: { type: 'and', conditions: [ { type: 'condition', left: { type: 'field', path: 'totalSpend' }, operator: 'greaterThan', right: { type: 'literal', value: 1000 }, }, { type: 'condition', left: { type: 'field', path: 'orderCount' }, operator: 'greaterThanOrEqual', right: { type: 'literal', value: 10 }, }, ], }, isActive: true, })

Regional Segment

defineSegment({ key: 'eu-customers', name: 'EU Customers', description: 'Customers in European markets', rules: { type: 'condition', left: { type: 'field', path: 'market' }, operator: 'in', right: { type: 'literal', value: ['uk', 'de', 'fr', 'es', 'it', 'nl'] }, }, evaluationMode: 'batch', isActive: true, })

Next Steps

Last updated on