Skip to content

Tracking snippet

The Shuttlebase snippet is a single JavaScript file built for your account. It serves variants, tracks visitor behavior, and reports results. This page explains how it works under the hood.

Each account gets its own JavaScript bundle, served from Shuttlebase’s global CDN. The bundle contains everything the snippet needs to run without extra network round trips:

  • Your project ID and account currency
  • Allowed and excluded domains
  • Audiences, targets, and metrics
  • Active experiments with their variant code
  • Consent settings and the snippet version

The minified core code weighs roughly 14KB. The exact size of your bundle varies because it includes the code for your account’s experiments.

The snippet is an async, self-executing script. It runs as soon as it loads and does not wait for other scripts.

Two safeguards make it resilient to load timing:

  • A double-load guard. If the snippet tag appears twice on a page, the second copy detects the first and exits instead of running again.
  • A pre-load event queue. Code on your page can push events before the snippet finishes loading. The snippet drains the queue once it initializes. See Events for the custom event format.

Heavier diagnostic work waits until the DOM has loaded, so the snippet does not compete with your page for early resources.

Variant changes are implemented using JavaScript. The snippet applies them at initialization, as soon as it decides which variant a visitor belongs to. It then watches the page with a MutationObserver and re-applies variant changes when the DOM mutates, with throttling to limit the cost. This keeps variants intact on pages that render or update content after load, including single-page applications.

The snippet does not hide the page while variants load, to prevent impacting load times. Shuttlebase verifies that variants execute correctly through diagnostic events, and live error monitoring flags variants that fail in production.

Two URL parameters let you preview experiments on your live site without affecting real visitors:

  • ?msai_preview= loads a specific variant for preview.
  • ?msai_deployed_only= loads the site with only deployed winners applied and no running experiments.

Events sent during preview carry a preview flag, so preview sessions do not pollute experiment results. For how previews fit into experiment QA, see Variants and QA.