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.
1// Send the visitor's subscription plan2avsb.track.segment('subscriptionPlan', 'pro');1// Send multiple segment values2avsb.track.segment('subscriptionPlan', 'enterprise');3avsb.track.segment('userTier', 'vip');4avsb.track.segment('cohort', '2024-q1');1// Reading from your application's global user object2if (window.currentUser) {3 avsb.track.segment('subscriptionPlan', window.currentUser.plan);4 avsb.track.segment('accountAge', window.currentUser.accountAge > 180 ? 'mature' : 'new');5}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.
Go to organization settings
Add a new segment
avsb.track.segment()) and a human-readable label.Define possible values (optional)
free, pro, enterprise — list them here. This makes the Audience Builder show a dropdown instead of a free-text field, reducing typos.Save
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.
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.