Skip to Content
PlatformTargeting Rules

Targeting Rules

Targeting rules allow you to control which users see specific features or variations of a feature based on the context of the user. This enables precise feature delivery and personalized experiences.

What are Targeting Rules?

Targeting rules are conditions that determine whether a user should receive a feature or variation. They evaluate user attributes against defined criteria to make targeting decisions.

In the following example, we are targeting users with userIDs (user-1 and user-2) and giving serving them true. Everyone else will get a false variation.

Targeting Rules

When a user makes a request to the Supaship API, the platform will evaluate the targeting rules and return the appropriate variation.

import { SupaClient } from '@supashiphq/sdk-javascript' const client = new SupaClient({ apiKey: '1234567890abcdef1234567890abcdef', environment: 'production', context: { userId: user.id, // user context plan: 'premium', device: 'mobile', }, }) // The platform automatically evaluates targeting rules const isEnabled = await client.getFeature('feature-flag', { fallback: false, }) // Returns true if user.id === 'user-1' or user.id === 'user-2' // Returns false for all other users

Types of Targeting

1. User Targeting

Target based on user context properties such as userId, email, etc.

Targeting Rule 1

2. Geographic Targeting

Target users by location such as country, continent, etc.

Targeting Rule 2

Targeting Operators

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