@trevosdk/browser assigns variants and records events in the browser. It never touches
the DOM — your own code branches on the variant it returns.
Under 10kb gzipped, no dependencies.
Install
Without a bundler
The CDN build exposes a global calledTrevo. Pin the exact version in production —
the floating channels change under you with no deploy on your side.
Use
v0 or latest for prototyping only.
Initialise
tsk_live_…) and belongs in your client bundle. Server keys
(tsk_secret_…) are rejected from browsers.
init() is re-entrant — calling it again reconfigures rather than duplicating.
Options
Identify the user
identify() can change a user’s variant.
Call it as early as you can, and before rendering anything under test.
Anonymous ids are per browser, so the same person on a phone and a laptop is two
participants until they sign in.
On logout:
Read a variant
'control', so this is safe to ship before the
experiment exists.
Each call records an exposure. To read without recording one:
Typed variants
defineExperiment() returns a typed union and turns an unhandled variant into a compile
error — so a variant added in Trevo that your code does not handle fails the build instead
of silently falling through:
Track conversions
trevo.flush() forces a send if you need one.
Limits: event names up to 500 characters, properties up to 8KB serialised.
Waiting for config
On a first visit the SDK has no cached config, sogetVariant() returns 'control' until
the first fetch lands. Returning visitors read from a warm cache and are correct
immediately.
Anti-flicker
Hides the page until variants are resolved, with a safety timeout so a blocked or failed SDK can never leave your page blank:<script> in <head>, before anything renders. It reveals automatically
after 1 second by default:
manualReveal: true, call trevo.reveal() once you have committed the variant.
Server-side bootstrapping is better where you can do it — nothing is hidden and there is
no timeout to tune.
Consent and opt-out
optOut() is idempotent and safe to call before init().