/Docs

Snippet Installation

The A vs B snippet is a small JavaScript file that powers everything — experiment targeting, variation injection, and event tracking. This section covers how to install it on any type of website, from a plain HTML file to a complex single-page application.

How the snippet works

When a visitor loads your website, the snippet runs automatically. It fetches your project's experiment configuration from A vs B's CDN, evaluates which experiments the visitor qualifies for, assigns them to a variation, and injects that variation's CSS and JavaScript into the page. All of this happens in milliseconds, before the visitor sees the page.

The snippet also listens for events (button clicks, pageviews, custom events) and sends that data back to A vs B so you can see results in your dashboard.

Installation guides