/Docs

Custom Segments

Custom segments let you send your own data about a visitor to A vs B and then use that data in audience conditions. If your application knows something about a visitor — their subscription plan, their user tier, their cohort, their language preference set in your app — you can pass that information to A vs B and use it to precisely target experiments.

What are custom segments?

A custom segment is a key-value pair that you send to A vs B from your own JavaScript code. The key is a string identifier for the segment dimension (for example, subscriptionPlan), and the value is the visitor's value for that dimension (for example, pro). Once sent, A vs B stores the segment data for the visitor's session and makes it available for audience conditions and results filtering.

Sending segment data

Call avsb.track.segment(key, value) anywhere in your JavaScript code, ideally early in the page load so the data is available before experiments are evaluated.

Basic segment tracking
javascript
1// Send the visitor's subscription plan
2avsb.track.segment('subscriptionPlan', 'pro');
Multiple segments
javascript
1// Send multiple segment values
2avsb.track.segment('subscriptionPlan', 'enterprise');
3avsb.track.segment('userTier', 'vip');
4avsb.track.segment('cohort', '2024-q1');
Segment from your app's data
javascript
1// Reading from your application's global user object
2if (window.currentUser) {
3 avsb.track.segment('subscriptionPlan', window.currentUser.plan);
4 avsb.track.segment('accountAge', window.currentUser.accountAge > 180 ? 'mature' : 'new');
5}
Call avsb.track.segment() early
Call avsb.track.segment() before your experiments are likely to be evaluated. The best place is immediately after your application initializes the current user object — typically in a DOMContentLoaded listener or immediately after a user authentication check resolves. If an experiment is evaluated before the segment data arrives, the segment condition may not match.

Defining segments in organization settings

Before you can use a custom segment in audience conditions, you need to register it in your organization settings. This tells A vs B what segment keys to expect, what values are valid, and what label to show in the Audience Builder UI.

1

Go to organization settings

Click your organization name in the top navigation and go to Settings. Look for the Segments tab or section.
2

Add a new segment

Click Add segment. Enter the segment key (must match exactly what you pass to avsb.track.segment()) and a human-readable label.
3

Define possible values (optional)

If the segment has a fixed set of values — like free, pro, enterprise — list them here. This makes the Audience Builder show a dropdown instead of a free-text field, reducing typos.
4

Save

Save the segment definition. It now appears in the Audience Builder as a condition type.

Using segments in audience conditions

Once a segment is defined, it appears as a condition type in the Audience Builder. Add a condition, choose your segment from the type dropdown, select the operator (Is or Is Not), and enter the value.

text
1Condition: subscriptionPlan is "pro"
2Condition: userTier is not "free"
3Condition: cohort is "2024-q1"

Auto-collected segments

A vs B automatically collects several segments for every visitor without any additional code. These are available in the Audience Builder and in the Results page segment filter:

  • device — desktop, mobile, or tablet
  • browser — Chrome, Firefox, Safari, Edge, etc.
  • platform — the visitor's operating system
  • language — browser language code
  • userType — new or returning
  • country — determined by geo-IP lookup

Custom segments you send via avsb.track.segment() are in addition to these automatic ones.

Use cases

  • Subscription plan — target an experiment only at free-tier users to test upgrade prompts, or only at enterprise users to test power-user features.
  • User cohort — run experiments for users who signed up during a specific period to understand how cohort behavior differs.
  • Account status — target logged-in vs logged-out visitors with different experiment variations.
  • User intent — if your application tracks whether a visitor has indicated purchase intent (added to wishlist, started checkout), use that as a segment to run more targeted experiments.