Audience Conditions

Audiences are defined using logical rules called conditions. Each condition is a rule like "Browser equals Chrome", and an audience is a Boolean combination of these rules, like "Browser equals Chrome OR Referrer matches the substring google.com".

Each individual condition is a JSON object with a type and other properties depending on that type. You can see how each condition type is defined below, or just create an audience on Optimizely and GET it back to see its condition JSON.

Conditions are joined together in lists. The first element in each list should be "and", "or", or "not", and the rest of the conditions will be combined using that operator. You can replace any individual condition with another list, which allows for a nested structure of ANDs and ORs. A "not" list should only have one condition or list, which will be negated. Otherwise, a list with a single condition like ["and", {...}] will just match that condition.

The full condition object should be passed to the API as a serialized string (for example, by using JSON.stringify(data) in JavaScript). We'll return it in the same format, so to traverse it you'll need to parse it as an object (with JSON.parse(string) or equivalent).

If you're using a Full Stack v3.0 SDK, you can define audiences using the Audience Combinations functionality. For more information, see Audience Combinations.

Ad Campaign

type: campaign

match_type: required

value: optional

Will match if the utm_campaign query parameter matches value according to match_type. If you don't provide a match type, it will default to exact if a value is provided or exists if a value is not provided.

Example JSON

Custom Attribute

type: custom_attribute

name: required

match_type: optional

value: optional

Will match if the custom_attribute parameter matches value according to match_type. If you don't
provide a match type, it will default to exact if a value is provided or exists if a value isn't provided.
Note: Full Stack accepts string, number, and boolean values and exists, exact, substring, gt,
and lt match types. Web accepts only string values of an exact match type.

Example JSON

Referrer URL

Will match visitors who came from a URL that matches value according to match_type.

The match_type can be:

simple Simple match (hostname/path only)

exact Exact match

substring Substring match

regex Regular expression match

Example JSON

{
"type": "source_type",
"value": "referral"
}

Traffic Source

type: source_type

value: required

Acceptable values are:

direct

Direct

search

Search

referral

Referral

campaign

Campaign

Example JSON

{
"type": "source_type",
"value": "referral"
}

Time/Day of Visit

type: time_and_day

value: required

Will match visitors who come during certain days of the week, and certain times within those days. The value takes the form START_END_DAYS, where the start and end are 24-hour times in the form hh:mm like 14:30 for 2:30pm. Use 00:00_23:59 to target the full day.
For days, provide a comma separated list of lowercase days of the week like saturday,sunday. You must provide at least one day. To target the full week, use monday,tuesday,wednesday,thursday,friday,saturday,sunday.
Putting this together, to target just weekday mornings, you could provide value: &#39;06:00_11:00_monday,tuesday,wednesday,thursday,friday&#39;.