[data-reveal]{opacity:1!important;transform:none!important}
AntelopeJS DMS
DocumentationA/B assignment

A/B assignment

How the Marketing module assigns visitors to the arms of a running split without storing anything per visitor, and the trade-offs that design accepts.

The module assigns A/B arms on the server, from data it already has, and stores nothing per visitor. This page explains that contract and the residual risks it accepts.

Assignment contract

GET /api/marketing/experiments.js?website=<id> answers window.__dmsMarketingAssignments={"<experiment key>":"<variation key>"} for the site's funnels whose split is running. The tracker loads the script lazily, on the first variation() call.

Assignment is a pure function of data already in hand. sha256(visitorId:experimentKey) picks a bucket in the normalized weights (services/experiments/assign.ts). The visitor ID comes from the request's IP and user agent, derived exactly as collect derives it. Nothing is stored per visitor. Results are computed from the recorded exposure events, not from a re-derived assignment, so the analysis survives definition edits and salt rotation.

The endpoint is public and hardened like the other public routes, and no further:

  • Definitions are cached per website ID in a BoundedCache for 30 seconds, negative results included. An unknown ID costs at most one database read per TTL and answers an empty map, never an error that a public page would show.
  • The website parameter goes through queryString() and a length cap before it reaches the cache. A request without it answers 400.
  • The global and per-site kill switches answer the empty map at once.
  • The body is sent with Cache-Control: private, no-store. It is per visitor, so a shared cache would hand the first visitor's buckets to everyone after.

The route has no origin gate, no bot filter and no rate limit. Those guards protect writes and data quality at ingestion, and this read has neither. A bot served an assignment map writes nothing, and its exposures fail at collect's own guards.

Residual risks the design accepts

These trade-offs follow the same reasoning as the collect guards in HTTP API.

The bucket follows the request, not the person. A visitor who changes network or browser is a new visitor and may cross arms. Two visitors behind one NAT with the same user agent land in the same arm. A cookieless identity buys privacy at that cost. Called from a site's server-side renderer, every visitor shares the renderer's identity, so the endpoint is for browsers only.

A flood of distinct IDs costs a read each. The negative cache limits repeats per ID, not new IDs. Past MAX_CACHE_ENTRIES (1000) within the TTL, each new ID is a database read. Collect accepts the same cost, because its rate limiter runs after it resolves the website. The remedy is rate limiting at the deployment level, not a guard written for one route.

The arm that an exposure claims is believed. Its key is not. Collect drops any exposure whose experiment is not running, using the same cached definitions that the assignment script serves. That costs one read per site per TTL, and only on batches that carry an exposure. Nothing re-derives which arm the page applied, which is what lets results survive salt rotation and definition edits. A forged exposure on a running key is a forged custom event under another name. The remedy for both is detection and the per-site purge.

The salt rotates monthly, and assignments with it. On the first of each month every visitor draws again. Sessions are the unit of analysis, and a session exposed to two arms is excluded, so the statistics stay valid. A split that spans months still mixes populations, as A/B tests explains.

Start and stop reach other instances within the cache TTL. The writing instance drops its cache at once. Other instances serve the previous set for up to 30 seconds, as they do for beacons of a deleted site. That window never reaches the numbers. Results are read over the split's own runs (experiment.runs on the funnel row, where a stop closes a run and a resume appends the next). An exposure recorded outside the runs is dropped at read time too, whether it came from a stale instance, a page loaded before the stop or a hand-written dmsMarketing.exposure() call. A resumed split keeps its earlier sessions. The arms are frozen and assignment is a pure function of the visitor hash, so the same visitor draws the same arm across runs, salt rotation aside.

Running experiment keys are public. Anyone with a website ID, which every tracked page prints, can list them. That follows from serving assignments to anonymous visitors. Funnel names and splits that are not running stay behind authentication.