Skip to Content
PlatformTargeting Rules

Targeting Rules

Targeting rules control who sees which variation of a feature flag. They evaluate user context properties (like userID, country, plan) against conditions you define.

Example: Enable a feature for users in the US with premium plans, or for specific beta testers.

Targeting Rules

How Targeting Works

When you evaluate a feature flag, Supaship checks your targeting rules against the user’s context properties. If a rule matches, that variation is returned. Otherwise, the default variation is used.

const client = new SupaClient({ apiKey: 'your-api-key', environment: 'production', features: { 'new-feature': false, }, context: { userID: user.id, // Required for targeting plan: 'premium', country: 'US', }, }) // Supaship evaluates targeting rules automatically const isEnabled = await client.getFeature('new-feature') // Returns true if user matches a targeting rule // Returns false (fallback) if no rules match

Targeting Methods

User Attributes

Target based on any context property you send:

Targeting Rule 1

Segments

Reference reusable user groups (segments) in your targeting rules. Create segments once, use them across multiple feature flags.

Example: Target the “Premium Users” segment instead of repeating the same conditions everywhere.

Targeting Operators

Use these operators to build targeting conditions:

Comparison Operators

// Equals { attribute: 'user.plan', operator: 'equals', value: 'premium' } // Not equals { attribute: 'user.plan', operator: 'not_equals', value: 'free' } // Greater than { attribute: 'user.age', operator: 'greater_than', value: 18 } // Less than { attribute: 'user.age', operator: 'less_than', value: 65 } // Greater than or equal { attribute: 'user.purchase_count', operator: 'greater_than_or_equal', value: 5 } // Less than or equal { attribute: 'user.purchase_count', operator: 'less_than_or_equal', value: 10 }

String Operators

// Contains { attribute: 'user.email', operator: 'contains', value: 'admin' } // Starts with { attribute: 'user.email', operator: 'starts_with', value: 'test' } // Ends with { attribute: 'user.email', operator: 'ends_with', value: '@company.com' } // Regex match { attribute: 'user.email', operator: 'regex', value: '^admin@.*\\.com$' }

Array Operators

// In array { attribute: 'user.country', operator: 'in', value: ['US', 'CA', 'UK'] } // Not in array { attribute: 'user.country', operator: 'not_in', value: ['CN', 'RU'] } // Array contains { attribute: 'user.tags', operator: 'array_contains', value: 'premium' }
Last updated on