Skip to main content

Overview

Experiments puts each visitor into a variant of an A/B test and keeps it stable — the same visitor always sees the same variant on later visits, without asking the server again. The walkthrough below covers install and setup. For every option, hook, and the experiment:assigned event, open the reference.

Implementation

Install

Your experiment setup lives on Core (it comes from your generated config), so you never pass a separate experiments option to initExperiments. Install once, then pick your setup:
Follow the example below: wrap your app once, then read each visitor’s test variant with useExperiment.
If you used the CLI, the modules import in the example already turns Experiments on — you rarely need extra setup. For optional React details, see experiments() in the reference; for useExperiment and useAssignExperiment, see hooks.
If Experiments is missing from your setup, useExperiment will error. Add the SDK with the CLI so it is included in the generated modules file.

Assign on demand

useExperiment assigns the variant as soon as it renders. To assign at a specific moment instead, use useAssignExperiment:
A later useExperiment({ experimentId: 'exp-hero' }) reads that same assignment back without another request. assignExperiment returns undefined if Experiments isn’t set up, and rejects if the request fails.

Analytics

Experiments never imports Analytics. In non-React code, create an Analytics client yourself and pass it in:
In React, adding both SDKs with the CLI connects Analytics to Experiments for you — no extra steps. When Analytics is on, each new assignment fires one experiment:assigned event — a variant already saved from before doesn’t fire again. If that event fails to send, the assignment is unaffected; it was already saved first.