Code Editor

Documents / AB Testing

Variation code editor

Variations are not separate pages you upload. They are snippets that run on top of the live site. In everyday language, the code editor is where you write “change this headline” and “make this button green.” In CROForge that editor is a full-screen route using Monaco (the same engine as VS Code). You edit JS and CSS per variation, switch tabs with vIndex, and preview widths with VIEW_MODE. The shipping UX is code-centric. EDITOR_MODE includes Code and Visual, but Visual may not be fully available yet.

Words used on this page

WordEveryday meaningMeaning in CROForge
Code editorThe screen where you type JS and CSS.Route /workspace/{workspaceId}/ab-test/{experimentId}/edit?vIndex={n}. Saves names and codes onto variations.
JS (JavaScript)Code that changes content and behavior in the browser.The JS tab writes jsCode. Smart Code evals it after injecting CSS. Uncaught errors can break the page.
CSSRules that change appearance.The CSS tab writes cssCode. Smart Code appends a <style> tag in head.
MonacoA professional in-browser code editor (VS Code’s engine).CROForge uses @monaco-editor/react for the JS and CSS tabs.
EDITOR_MODECode versus point-and-click visual editing.Values: Code / Visual. Shipping UX is Code. Visual may not be fully available yet — “Create variations using Code Editor.”
VIEW_MODEHow wide the preview looks (computer, tablet, phone).Values: Desktop / Tablet / Mobile. Preview chrome width hints only; they do not change live assignment.
Editor URLThe page shown beside or behind the editor.Set this to a real targeted page so you edit against the actual DOM and CSS of that surface.
vIndexWhich tab is selected.Query param that selects which variation tab is active in the editor.
FlickerA flash of the original page before the change appears.Late-applied JS/CSS can paint Control first. Keep snippets small, prefer CSS for visuals, and QA on the real URL.
ControlThe original experience.Often protected from delete. Usually empty JS/CSS so the live site is the baseline.

Screenshot

Filename: variation-code-editor.png (Monaco JS/CSS tabs, variation tabs, view mode). Place the file under docs/assets/placeholders/. Paste the screenshot into WordPress after you copy this article; do not add an image tag here.


Where the editor lives

From a campaign, open Edit / the code editor. The route is:

/workspace/{workspaceId}/ab-test/{experimentId}/edit?vIndex={n}

vIndex selects which variation tab is active. The campaign hub itself remains /workspace/{id}/ab-test/{experimentId}.

Features

FeatureWhat it does
Variation tabsSwitch Control and variants without leaving the editor.
JS tabJavaScript applied at runtime (jsCode).
CSS tabStyles injected into <head> as a <style> tag.
Add variationCreates a new blank variant.
Rename / duplicate / deleteManage variants. Control is often protected.
SavePersists codes and names on the experiment.
Editor URL + VIEW_MODEPreview chrome for Desktop, Tablet, or Mobile against the real page.

Product mode enums

EnumValuesMeaning in CROForge
EDITOR_MODECode / VisualCode vs visual editing when visual is available. Treat Code as the supported path.
VIEW_MODEDesktop / Tablet / MobilePreview chrome width hints only.

Writing safe variation JS and CSS

Always check that the element exists. Pages load widgets asynchronously; a missing node should be a no-op, not an exception.

// Prefer defensive DOM access
var el = document.querySelector('h1.hero-title');
if (el) {
  el.textContent = 'New headline';
}
h1.hero-title {
  color: #0a7;
}

What happens at runtime

When a Running campaign assigns this variation, Smart Code:

  1. Adds a marker class on document.head.
  2. Appends a <style> tag with cssCode.
  3. Evals / runs jsCode.
  4. Sends an impression event.

If you edit JS or CSS on a Running campaign, some sticky visitors already saw the old snippet. Prefer pause → edit → resume. Watch for flicker on first paint, and never ship uncaught JS errors.

Related reading