/Docs

Execution Order

Every time a visitor loads a page on your website, the A vs B snippet follows the same precise sequence of steps. Understanding this order helps you know exactly when your variation code runs, when events are tracked, and what to expect when debugging.

The full sequence

1

Snippet loads, anti-flicker hides the page

The browser parses your HTML and encounters the A vs B snippet tag. The snippet file downloads from the CDN. As soon as it executes, it immediately applies opacity: 0 to the <html> element. This prevents the visitor from seeing the original page while experiments are being evaluated. A 3-second safety timeout is also started at this point — if anything goes wrong, the page will be revealed after 3 seconds regardless.
2

Datafile fetches from CDN

The snippet makes a request to A vs B's CDN to download the project's datafile. The datafile is a JSON document that contains all the configuration for your project: every experiment, every variation, every metric, every audience, and every targeting rule. The datafile is cached at CDN edge nodes globally, so this request is typically very fast (under 20ms from most locations).
3

Visitor cookie created or read

The snippet checks the visitor's browser for an existing A vs B cookie. If the visitor has been to your site before, the cookie contains their unique visitor ID and all previous variation assignments. If no cookie exists, a new visitor ID is generated and a new cookie is set. This cookie is what ensures the same visitor always sees the same variation (sticky bucketing).
4

Public API (window.avsb) initialized

The snippet initializes the public window.avsb API object. This is the interface your code (and your Project JavaScript) uses to interact with the snippet. Methods like avsb.track.event(), window.avsb.forceVariation(), and window.avsb.getVariation() are now available.
5

Project JavaScript executes

If you have written any Project JavaScript in Project Settings → Snippet, it runs now — after the API is ready but before any experiments are evaluated. This is the right place to put global setup code, helper functions, or calls to window.avsb.forceVariation() for QA purposes. See Project JavaScript for more detail.
6

Each experiment is evaluated in order

The snippet evaluates every running experiment for this project. For each experiment, it checks (in this order):
  1. URL targeting rules— does the current page URL match the experiment's targeting rules? If not, skip.
  2. Audience conditions— does the visitor match any of the experiment's configured audiences? If audiences are configured and none match, skip.
  3. Traffic allocation — is this visitor in the percentage of traffic allocated to this experiment? If not, skip.
  4. Trigger — does the experiment have a custom trigger function? If so, call it. The trigger controls exactly when (and whether) the variation code is injected.
  5. Variation injection— apply the variation's CSS (into <head>) and JavaScript (into <body>).
7

Page is revealed

After all experiments have been evaluated and variations injected, the snippet removes the opacity: 0 style from <html>. The visitor sees the page for the first time — already in the correct variation state.
8

Events are tracked and batched

The snippet sets up event listeners for any metrics configured for running experiments. When a metric event fires (a button click, a pageview, a custom event), the snippet records it. Events are batched and sent to A vs B servers every 2 seconds or when the visitor leaves the page (using the browser's sendBeacon API), whichever comes first.
Everything happens fast
Steps 1 through 7 typically complete in under 100 milliseconds from a fast connection. The visitor experiences no perceptible delay — they just see the page load normally, already in the correct variation.

On SPA navigation

When a visitor navigates within a single-page application, the sequence above runs again — but instead of starting from step 1 (snippet load), it starts from step 5 (Project JavaScript). The visitor's cookie is already set, and the datafile is already cached in memory, so re-evaluation is even faster than the initial load. See SPA Navigation for the full details.