Configure Targeting and Audiences
Why audience targeting matters
Section titled “Why audience targeting matters”Running an experiment on every visitor dilutes results and wastes traffic. Audience targeting lets you restrict experiments to the users who matter — paid subscribers, mobile visitors, specific geographies — so you get cleaner signals and protect irrelevant segments from unfinished experiences.
What you will do
Section titled “What you will do”- Define user attributes that describe your audience
- Build audience conditions in Optimizely
- Apply the audience to an experiment
- Verify targeting resolves correctly
Step 1: Define user attributes
Section titled “Step 1: Define user attributes”Attributes are key-value pairs that describe a user. Both products use attributes for targeting, but the mechanism differs.
Feature Experimentation: pass attributes in code
Section titled “Feature Experimentation: pass attributes in code”const user = optimizely.createUserContext('user-456', {
plan: 'enterprise',
country: 'DE',
lifetime_value: 12500,
is_beta_tester: true,
});
const decision = user.decide('redesigned_dashboard'); user = client.create_user_context('user-456', {
'plan': 'enterprise',
'country': 'DE',
'lifetime_value': 12500,
'is_beta_tester': True,
})
decision = user.decide('redesigned_dashboard') var user = optimizely.CreateUserContext("user-456", new UserAttributes
{
{ "plan", "enterprise" },
{ "country", "DE" },
{ "lifetime_value", 12500 },
{ "is_beta_tester", true },
});
var decision = user.Decide("redesigned_dashboard"); Web Experimentation: set attributes via the JavaScript API
Section titled “Web Experimentation: set attributes via the JavaScript API”window.optimizely = window.optimizely || [];
window.optimizely.push({
type: 'user',
attributes: {
plan: 'enterprise',
country: 'DE',
lifetime_value: 12500,
},
}); Step 2: Build audience conditions
Section titled “Step 2: Build audience conditions”- Navigate to Audiences in the Optimizely application
- Click Create New Audience
- Name the audience descriptively (e.g., “Enterprise users in EMEA”)
- Add conditions using the condition builder:
| Condition | Source | Example |
|---|---|---|
| Custom attribute | Passed via SDK or snippet | plan equals premium |
| Device | Detected automatically (Web) | Device type is mobile |
| Browser | Detected automatically (Web) | Browser is Chrome |
| Location | IP-based geolocation (Web) | Country is United States |
| Third-party integration | Platforms like Salesforce or BlueKai | Segment membership |
- Combine conditions with AND / OR / NOT logic:
- AND — All conditions must be true (narrows the audience)
- OR — Any condition can be true (broadens the audience)
- NOT — Negates a condition (excludes a segment)
- Example:
(country = "US" OR country = "CA") AND plan = "premium"targets premium users in North America
- Save the audience
Available operators depend on the attribute type: strings support is, is not, contains; numbers support greater than, less than, equals; booleans support is true / is false.
Step 3: Apply the audience to an experiment
Section titled “Step 3: Apply the audience to an experiment”- Open your experiment and navigate to the Audiences section
- Click Add Audience and select the audience you created
- To combine multiple audiences, choose AND (user must match all) or OR (user must match any)
- Save the experiment
Traffic allocation applies only to users who pass the audience filter. If you allocate 50% traffic and apply an audience that matches 20% of visitors, roughly 10% of total visitors enter the experiment.
Step 4: Verify targeting
Section titled “Step 4: Verify targeting”Feature Experimentation
Section titled “Feature Experimentation”const user = optimizely.createUserContext('test-user', {
plan: 'enterprise',
country: 'DE',
});
const decision = user.decide('redesigned_dashboard');
console.log('Enabled:', decision.enabled);
console.log('Variation:', decision.variationKey);
console.log('Reasons:', decision.reasons);
// Enable decision reasons for debugging:
// user.decide('redesigned_dashboard', ['INCLUDE_REASONS']) user = client.create_user_context('test-user', {
'plan': 'enterprise',
'country': 'DE',
})
decision = user.decide('redesigned_dashboard')
print('Enabled:', decision.enabled)
print('Variation:', decision.variation_key)
print('Reasons:', decision.reasons) var user = optimizely.CreateUserContext("test-user", new UserAttributes
{
{ "plan", "enterprise" },
{ "country", "DE" },
});
var decision = user.Decide("redesigned_dashboard");
Console.WriteLine($"Enabled: {decision.Enabled}");
Console.WriteLine($"Variation: {decision.VariationKey}"); Web Experimentation
Section titled “Web Experimentation”Open your page with the Optimizely browser extension active. The extension displays which experiments are running, which audiences matched, and which variation was served.
Troubleshooting
Section titled “Troubleshooting”| Issue | Cause | Fix |
|---|---|---|
| User not entering experiment | Attribute value missing or wrong type | Log attributes before the decide call and compare with audience conditions |
| Audience matches nobody | Condition logic too restrictive | Test with a single condition first, then add constraints |
| Web attributes not recognized | Attributes pushed after snippet evaluates | Push attributes before the snippet loads or use the activate event |
1. You set up an audience targeting enterprise users in EMEA and allocate 50% traffic to your experiment. Your site gets 100,000 visitors per month, of which 20% match the EMEA enterprise audience. Roughly how many visitors will enter the experiment each month?
Traffic allocation applies only to users who pass the audience filter. If 20% of visitors match (20,000) and 50% of those are allocated to the experiment, roughly 10,000 visitors enter the experiment each month.
Traffic allocation applies only to users who pass the audience filter. If 20% of visitors match (20,000) and 50% of those are allocated to the experiment, roughly 10,000 visitors enter the experiment each month.
Review this topic →2. A developer passes user attributes for a Feature Experimentation audience, but no users are entering the experiment. The decide() call returns enabled: false for all test users. What debugging step should they take first?
When users are not entering an experiment, the most common cause is an attribute value mismatch or wrong type. Logging the attributes passed to createUserContext and comparing them with the audience conditions reveals discrepancies like typos, case sensitivity issues, or type mismatches.
When users are not entering an experiment, the most common cause is an attribute value mismatch or wrong type. Logging the attributes passed to createUserContext and comparing them with the audience conditions reveals discrepancies like typos, case sensitivity issues, or type mismatches.
Review this topic →3. In Web Experimentation, a marketer sets up custom attributes for audience targeting, but the audience matches nobody. The attributes are pushed via window.optimizely.push(). What is the most likely timing issue?
In Web Experimentation, attributes must be pushed before the snippet evaluates audience conditions. If attributes are pushed after the snippet loads, the snippet cannot see them during experiment activation. Push attributes before the snippet loads or use the activate event.
In Web Experimentation, attributes must be pushed before the snippet evaluates audience conditions. If attributes are pushed after the snippet loads, the snippet cannot see them during experiment activation. Push attributes before the snippet loads or use the activate event.
Review this topic →