Skip to main content
@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 called Trevo. 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

The key is publishable (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

Before this, users are bucketed on an anonymous id stored in local storage. After it, they are bucketed on your user id — which means 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

Synchronous, no network call, and deterministic — the same identity and key always produce the same variant. Unknown keys return '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

Batched automatically — up to 50 events per request, flushed every couple of seconds and on page unload. 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, so getVariant() returns 'control' until the first fetch lands. Returning visitors read from a warm cache and are correct immediately.
Config is polled every 60 seconds and cached in local storage for 24 hours, so a slow network delays the first visit only. To avoid the flash of control on a first visit entirely, either resolve variants on the server (Next.js) or use the anti-flicker snippet below.

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:
Inline it in a <script> in <head>, before anything renders. It reveals automatically after 1 second by default:
With 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.
optOut() is idempotent and safe to call before init().

API summary