Custom Segments
Custom segments let you send your own data about a visitor to A vs B, then use that data to slice your experiment results. Say your application knows a visitor's subscription plan, user tier, cohort, or language preference. Pass that information to A vs B, and see how each value performed on the Results page.
A custom segment only affects the Results page. It lets you break results down by a value your code sent, after the experiment has run. It does not add a new condition to the Audience Builder, and it cannot decide who enters an experiment. To decide who enters an experiment, use a device or browser condition, a JavaScript or cookie condition, or, for feature flags, a custom attribute.
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 and makes it available as a filter on the Results page.
Sending segment data
Call avsb.track.segment(key, value) anywhere in your JavaScript code, ideally early in the page load so the value is captured before the visitor does anything else.
Basic segment tracking:
// Send the visitor's subscription planavsb.track.segment('subscriptionPlan', 'pro');Multiple segments:
// Send multiple segment valuesavsb.track.segment('subscriptionPlan', 'enterprise');avsb.track.segment('userTier', 'vip');avsb.track.segment('cohort', '2024-q1');Segment from your app's data:
// Reading from your application's global user objectconst user = window.currentUserif (user) { // Segment values are strings, so skip a field your user record has not set if (user.plan) avsb.track.segment('subscriptionPlan', user.plan) avsb.track.segment('accountAge', user.accountAge > 180 ? 'mature' : 'new')}Call avsb.track.segment() as early as you can. A good place is right after your application sets up the current user object: in a DOMContentLoaded listener, or right after a login check finishes. A segment value only covers the page views that happen after you send it. Call it late, and early page views are missing that value in your results.
Registering a segment
Before a segment shows up as a filter on the Results page, you need to register it. This tells A vs B what segment keys to expect, what values are valid, and what label to show.
Registration happens per project, on the Metrics page.
Go to Metrics, then Segments
Open your project and click Metrics in the left navigation, then click the Segments tab.
Click New segment
A form opens. Enter a Name (a human-readable label, such as "Subscription plan"). A matching key is filled in for you, and you can edit it: this is the key you must pass to avsb.track.segment(), exactly.
List the values (optional)
If the segment has a fixed set of values (like free, pro, enterprise), list them one per line. This makes those values show up as filter checkboxes right away, even before any visitor data arrives.
Click Create segment
The segment is now registered. Values your code actually sends will merge into the list the next time someone loads the Results page. If something is missing or not allowed, such as an empty name or a key with a space, the reason appears under that field.
avsb.track.segment() calls reach A vs B and get stored, unless the visitor has withdrawn consent and your site has called avsb.disable(), after which every track call is dropped. See Consent mode. But the Results page filter only shows a segment key that has been registered here first. Say you send subscriptionPlan values for months without registering the key. None of that data is filterable until you register subscriptionPlan. Nothing is lost, but it stays invisible until then. The two automatic commerce segments are the exception: cart_band and purchaser are built in and need no registration (see below).
Filtering results by segment
On an experiment's Results page, the Segment filter lists every segment with data. That means the auto-collected ones below, plus any custom segment you have registered and sent at least one value for. Pick a segment, tick the values you want, and the results table narrows to visitors who sent that value.
Auto-collected segments
A vs B automatically collects six segments for every visitor, with no code from you. They need no registration, so they always appear 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 six.
Some data arrives without you writing any code. When an experiment uses commerce conditions, the snippet sends two extra values for that experiment's visitors: cart_band (the visitor's cart total at exposure, bucketed) and purchaser (true or false, from purchase history). Like the six segments above, these two are built in: they show up in the Results page filter (as Cart value and Purchaser) as soon as an experiment has recorded them, with nothing to register on the Metrics Segments tab.
Use cases
Segments are for understanding your results, not for choosing who enters an experiment. Use them to answer questions like:
- Subscription plan: did the new upgrade prompt move free-tier users differently than enterprise users?
- User cohort: did visitors who signed up in a specific period respond differently from everyone else?
- Account status: did logged-in visitors react differently than logged-out ones?
- User intent: did visitors who had already shown purchase intent (wishlisted, started checkout) convert differently?
Deciding who is even in the experiment is a separate job: your audience. Build that with a device or browser condition, a JavaScript or cookie condition, or, for feature flags, a custom attribute.