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 theexperiment:assigned
event, open the reference.
Implementation
Install
experiments option to initExperiments. Install once, then pick your setup:
- React
- JavaScript
- Server
Follow the example below: wrap your app once, then read each visitor’s test variant with If you used the CLI, the A later
useExperiment.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.Assign on demand
useExperiment assigns the variant as soon as it renders. To assign at a specific moment instead, use useAssignExperiment: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: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.
