Rules are used to enable a flag for a subset of users. Rules are evaluated from top to bottom. If a rule matches, the flag will return the configured value and stop evaluating the remaining rules.

See the example below.

Each rule has an attribute (1), a comparison operator (2), one or multiple targets (3) and an output value (4).

Available Attributes

Geolocation Attributes

Geolocation is not available when running your edge function locally in development.

City

The city name for the location of the requester’s public IP address. Non-ASCII characters are encoded according to RFC3986.

Country

Countries are identified by their ISO 3166-1 alpha-2 code.

We provide a list of many available countries as suggestions in the input component in the console.

IP

The public IP address of the client that made the request.

Region

A string of up to three characters containing the region-portion of the ISO 3166-2 code for the first level region associated with the requester’s public IP address.

Unfortunately, there is no official extensive list of available regions from Vercel.

Custom Attribute

You can use custom attributes to enable a flag for a subset of users. For example, you can enable a flag for users with a specific userId or email.

Please refer to the API documentation for more information on how to set custom attributes.

Comparison Operators

These are the available rule types. Each of them includes a small code snippet that shows the exact implementation for reference

value is the value of the attribute. target is what we compare the attribute value to.

is in array

The rule will apply if the attribute is in the target array.

return target.includes(attribute);

is not in array

The rule will apply if the attribute is not in the target array.

return !target.includes(attribute);

contains

The rule will apply if the attribute contains the specified target.

return attribute.includes(target);

does not contain

The rule will apply if the attribute value does not contain the specified target.

return !attribute.includes(target);

equals

The rule will apply if the attribute value equals the specified targe.

return attribute === target;

does not equal

The rule will apply if the attribute value does not equal the specified target.

return attribute !== target;

is empty

The rule will apply if the attribute value is empty.

return attribute === "";

is not empty

The rule will apply if the attribute value is not empty.

return attribute !== "";

is greater than

The rule will apply if the attribute value is greater than the specified value.

return attribute > target;

is greater than or equals

The rule will apply if the attribute value is greater than or equals the specified value.

return attribute >= target;

is less than

The rule will apply if the attribute value is less than the specified value.

return attribute < target;

is less than or equals

The rule will apply if the attribute value is less than or equals the specified value.

return attribute <= target;

Example

The following flag will be evaluated for 80% of all users and enabled for those in Germany or the United Kingdom and for users with the attribute userId set to chronark.

First Rule matches

Let’s assume our user is lucky enough to be chosen for the 80% and is located in Germany: The order of operations is as follows:

  1. Evaluate percentage: ✅
  2. Evaluate country: ✅ Since the user is located in Germany, and that is one of the countries specified in the rule, the value true will be returned.

Any Rule matches

Our user is located in Norway and their userId is chronark, the order of operations is as follows:

  1. Evaluate country: ❌
  2. Evaluate userId: ✅

All rules will be avaluated until one of them matches. In this case, the flag will return true.

Percentage fall through

Our user is not lucky enough to be chosen for the 80%:

In this case the rules will not be avalated and the flag returns false

No rule hit

Lastly, let’s look at what happens if none of the rules match:

If your user is in the United States, and their username is not chronark:

  1. Evaluate country: ❌
  2. Evaluate userId: ❌

The flag will return false.