The names
Legacy aliases exist for backwards compatibility (
EXP_ID,
VARIANT_KEY), do not rely on them for new code.
The order
If you inspect the compiled variant function, the parameters land at specific positions. The exp key isarguments[4]. This ordering is
stable, a new binding at a later position does not shift existing
ones.
Rule of thumb: reference the bindings by name, not by position.
The names are stable public API; the positions are an implementation
detail.
Using them
Inside variant JS:Why the key and not just the UUID
The UUID is stable but not human-readable. The key is short, human-readable, and immutable, cloning an experiment mints a new key so referencing by key does not silently target the wrong test. If your goal is “log which variant applied”, the key is what a human reading logs wants to see. If your goal is “call an internal API that stores per-experiment state”, either works, the UUID is a slightly better primary key because it is opaque and cannot be confused with anything else.What is not in scope
this. The variant function’sthisis set to the runtime’s internal apply context, notwindow. Reach forwindowexplicitly if you need it.- Any DOM helper. Use
document.querySelector,abtestly.waitFor, or your own libraries, the runtime does not inject jQuery-shaped shortcuts into scope. - A framework’s runtime. React, Vue, and friends are not auto-imported. If your variant needs a framework, load it via Dev libraries or from the page itself.
onApply callback signature
If you use abtestly.onApply(...), the callback receives an
ApplyContext object with:
experimentIdandexperimentKey, same as the bindings above.variantKey, same as the binding.routeRevision, a monotonic counter that ticks on every SPA route change. Compare against it inside an async apply to detect supersession:
Stability
The three canonical names,ABTESTLY_EXP_ID, ABTESTLY_EXP_KEY,
ABTESTLY_VARIANT_KEY, are stable public API. They do not change
without a major version bump. Legacy aliases stay for at least one
major version.