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 in a session assigns; every later call with the same name returns the same variant, on every page the session visits. A session is one visit in one tab, so a person who comes back tomorrow may be assigned again. If a visitor must keep a variant across visits, assign it yourself and record it, below.
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.
What is stored
One row per session per experiment: the experiment’s name and the variant. Nothing else. Names are up to 64 characters, variants up to 32, and a session can be in at most ten experiments. Call it control and Lynq treats that variant as the baseline; otherwise the first variant is.