Experiments (A/B tests)
lynq.experiment({...}) puts the session in an A/B test: Lynq splits visitors between the variants you name and measures each against your goals. Lynq picks the variant, keeps it for the session, records it once and returns it, so your code can branch on the answer. The results, per variant against any goal, are on the Experiments screen.
Assigning a variant
const hero = lynq.experiment({
name: "pricing-hero",
variants: ["control", "short"],
});
if (hero === "short") document.body.classList.add("hero-short");An array assigns uniformly. An object assigns by weight, for a variant that should see less traffic:
lynq.experiment({
name: "signup-cta",
variants: { control: 60, verb: 20, social: 20 },
});The first call assigns; every later call with the same name returns the same variant, on every page and on every later visit. The browser remembers which variant it was shown for 90 days, so someone who comes back next week sees the same page and the test measures one decision rather than two. A visitor who clears their browser storage enters the test again, as they would anywhere.
Recording your own assignment
When the variant comes from your server, a cookie or a feature flag, record it as is:
lynq.experiment({ name: "pricing-hero", variant: "short" });Reading the assignment
A call with only the name reads the current assignment without changing anything, and returns undefined when the session is not in that experiment:
lynq.experiment({ name: "pricing-hero" }); // "short", or undefinedBefore the script loads
The tag is deferred, so window.lynq is not there at the top of your page. If the variant must be known before first paint, load the tag without defer and call after it, or assign on the server and record the result. A fallback like window.lynq?.experiment({...}) ?? "control" works, but the visitors it falls back on are counted in control by your page and in nothing by Lynq, which tilts the result.
Before first paint
The tag is deferred, so window.lynq is not there at the very top of the page. If a test changes something above the fold, either load the tag without defer (it is a 3 kB file) or decide the variant on your server and record it with the variant form. A fallback such as window.lynq?.experiment({...}) ?? "control" works, but everyone it falls back on is shown control by your page and counted in nothing by Lynq, which tilts the result.
What is stored
In the browser: which variant it was shown, per experiment, for 90 days. That is a variant name, not an identifier; it cannot recognise a person and it is never sent anywhere. lynq.optOut() clears it. Where a browser refuses storage the variant lasts for the visit instead.
Lynq records the experiment’s name, the variant, and the split it was asked for, once per session, and nothing else. Names are up to 64 characters, variants up to 32, and a session can be in at most ten experiments. Call a variant control and Lynq treats it as the baseline; otherwise the first one is.
Reading the result
Every screen is on Experiments, and it can be read whenever you like: the arithmetic is built for that. See how a result is judged.