Skip to main content
Once the snippet has loaded, window.abtestly (and its alias window.__abtestly) is available on the page. This is the runtime’s public surface. It is designed to be called from variant JavaScript, from your own scripts, and, for debug, from the DevTools console.
Writing the variant code itself? The dashboard’s variation editor is Monaco (VS Code) with linting and Cmd+S save, and you can attach curated libraries like Splide or GLightbox from a picker instead of pasting <script> tags into every variant.

The methods

trackGoal(key, valueOrOpts?)

Fire a custom goal.
Returns: boolean. true if accepted, false if the visitor was opted-out or the goal key is not one your experiments care about. orderId enables revenue deduplication. If two beacons arrive with the same expId:goalId:orderId, the second is netted server-side so a double-fire from a retry does not double-count revenue.

onApply(experimentIdOrKey, fn)

Register a callback that fires when a specific experiment applies. If the experiment already applied on this pageview, the callback fires immediately.
The callback receives an ApplyContext with the variant key and a route revision.

onCleanup(experimentIdOrKey, fn)

Register a callback that fires when the experiment is torn down, usually on SPA route change to a page the experiment does not match. Cleanups fire in reverse order of registration (LIFO).

waitFor(target, cb, timeoutMs = 5000)

Wait for an element or a predicate. Polls at 50 ms. Fires cb when the condition is met, or times out silently after timeoutMs.

activate(key)

Fire a manual activation trigger. See Activation triggers for when to use this.

dev.apply(experimentId)

Development only. Apply an experiment’s variant to the current pageview without bucketing and without firing a beacon. Useful for prototyping. Do not ship code that calls this.

debug(opts?)

Return a snapshot of what the runtime knows: loaded experiments, the last handful of events (buckets picked, variants applied, beacons sent), and any errors caught. See Dev debugger for the full shape.

Events

abtestly:routechange

Fires on window whenever ABTestly detects an SPA route change and finishes re-evaluating. The detail object includes:
  • url, the new URL
  • activeExperiments, experiment ids currently applied on the new route
  • deactivatedExperiments, experiment ids that were torn down

Runtime bindings inside variant JS

Every variant’s JavaScript runs inside a function that gets a few names passed in as arguments. In addition to the raw code you wrote, you can reference:
  • ABTESTLY_EXP_KEY, the experiment’s short code (e.g. checkout-simplify)
  • ABTESTLY_EXP_ID, the experiment’s UUID
  • ABTESTLY_VARIANT_KEY, the variant’s short key (control, variant-1, …)
These are useful for logging or for keying your own storage per-variant. See runtime bindings for the full list and the exact positions.

Stability

Everything on this page is part of the stable public API. Method signatures do not change without a major version bump; deprecated methods stick around for at least one major cycle after their replacement lands. Internals not documented here, _handlers, _pendingActivations, private queues, are exactly that: internal. If a piece of your code reaches for one of those, expect it to break.

Variation editor (Monaco)

Real editor, real lints. Cmd+S save, fullscreen, theme & font.

Dev libraries

Curated Splide, GLightbox, and friends via a picker.

Dev debugger

Console snapshot of assignments, applies, beacons, errors.

Runtime bindings

ABTESTLY_EXP_KEY and friends inside variant code.