Merchants & developers

Variant builder, visual mutations, and code mode

The builder authors the actual storefront change for a variation. It supports visual mutations, custom CSS/JS, file-based code workspaces, previews, revisions, and generated changes.

Simple terms

The builder is where a treatment variation is made. It can save simple DOM mutations or a richer code workspace.

The builder authors the actual storefront change for a variation. It supports visual mutations, custom CSS/JS, file-based code workspaces, previews, revisions, and generated changes.

Routes

  • /tests/[id]/variations/[varId]

Implementation behavior

  • Visual mutations are saved as structured JSON actions such as text, HTML, style, attribute, remove, insert before, and insert after.
  • The SDK applies mutations idempotently after targeting and assignment succeed.
  • Code mode stores generated workspace files, preview builds, build status, and revision metadata for more complex variants.
  • Selector generation and mutation generation APIs help produce or refine changes from prompts and page context.
  • Revision history lets teams inspect earlier builder states and roll forward from known working versions.

How to use it

  • Start with visual mutations for simple copy, style, layout, or insertion changes.
  • Use code mode when the change needs component logic, assets, or multi-file behavior.
  • Save frequently, preview the forced variation, then run QA before launching traffic.
  • Keep the control variation clean and edit treatment variations only.

When not to use it

  • Do not use code mode for a copy or color change that a structured mutation can handle.
  • Do not edit the control variation as if it were a treatment.
  • Do not launch a generated variant without previewing and saving the final state.

Implementation source

  • The editor route is src/app/(dashboard)/tests/[id]/variations/[varId]/page.tsx.
  • Operator and builder logic lives under src/features/apex-operator plus variation handlers under /api/experiments/[id]/variations/[variationId].
  • Mutation payloads are stored on Variation.mutations; code workspace files, revisions, and builds use the experiment variation workspace APIs.

Data and API

  • Prisma Variation.mutations, variation weight/control fields, code workspace models, preview artifact records, and revision records.
  • APIs: /api/variations/[varId], /api/generate-mutations, /api/generate-selector, /api/experiments/[id]/variations/[variationId]/workspace, /api/experiments/[id]/variations/[variationId]/build, /api/experiments/[id]/variations/[variationId]/files, and /api/experiments/[id]/variations/[variationId]/revisions.
  • SDK mutation engine and preview-session runtime.

Failure modes

  • Change flashes or appears late: tune anti-flicker, selector timing, or target container.
  • Mutation misses element: inspect selector, iframe/shadow DOM boundaries, and dynamic rendering.
  • Code preview fails: review build status, generated files, unsupported browser APIs, and asset paths.