Set up an experiment
const url = 'https://digize.com/api/v1/analytics/experiments';const options = { method: 'POST', headers: { 'Idempotency-Key': '5f1c2a8e-3b7d-4c55-9a0e-1f2d3c4b5a69', 'x-api-key': '<x-api-key>', 'Content-Type': 'application/json' }, body: '{"siteId":"example","kind":"content","name":"example","hypothesis":"example","pages":["example"],"traffic":1,"variants":[{"name":"example","weight":1,"swaps":[{"selector":"example","op":"text","attribute":"example","value":"example"}],"css":"example","path":"example","siteId":"example"}],"goal":{"kind":"lead","match":""}}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://digize.com/api/v1/analytics/experiments \ --header 'Content-Type: application/json' \ --header 'Idempotency-Key: 5f1c2a8e-3b7d-4c55-9a0e-1f2d3c4b5a69' \ --header 'x-api-key: <x-api-key>' \ --data '{ "siteId": "example", "kind": "content", "name": "example", "hypothesis": "example", "pages": [ "example" ], "traffic": 1, "variants": [ { "name": "example", "weight": 1, "swaps": [ { "selector": "example", "op": "text", "attribute": "example", "value": "example" } ], "css": "example", "path": "example", "siteId": "example" } ], "goal": { "kind": "lead", "match": "" } }'Sets up an A/B test on a site as a draft, which only previews until it’s started. Its kind is what every variant changes: content swaps parts of the page’s HTML (headlines, buttons, forms, images) and may add CSS; page shows another path of the same site in the page’s place; site shows another of the workspace’s sites. Each variant’s previewUrl shows it before it starts. Needs sites:write as well.
Needs the analytics:write permission.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Header Parameters
Section titled “Header Parameters”Makes the request safe to send again: for 24 hours the same key and request answer the first response without repeating the change.
Example
5f1c2a8e-3b7d-4c55-9a0e-1f2d3c4b5a69Request Bodyrequired
Section titled “Request Bodyrequired”object
The site it tests.
What it tests, in a few words.
What it should show and why, in a sentence.
The pages it runs on: paths such as / or /pricing, * at the end for every page under one. A site experiment takes every request of a visitor in it once they’ve seen one of these.
The share of visitors in the test, in percent (all when left out); the rest see the control and aren’t counted.
The control first (it changes nothing), then 1 to 3 variants.
object
Such as Control or Shorter form.
Its share of the test’s visitors, in percent; the weights add up to 100, even when left out.
Content: the changes to the page, in order.
object
A CSS selector HTMLRewriter takes: best a slot the site marked, [data-digize-slot=“hero-title”], else an #id or a tag the page has one of (analytics.experiments.elements lists them). No sibling selectors (+, ~).
Text sets its text, html its inner HTML, replace puts HTML in its place, attribute sets one attribute, remove takes it out.
Content: CSS added to the page’s head, such as a button’s colour.
What counts as converting for a visitor after they saw a variant, on any of the workspace’s sites: a form sent (lead), a booking, a checkout started, an order paid (purchase, with its revenue), a page reached, a tracker event, or scrolling a tested page down so far (scroll).
object
Lead: a form’s name (its _form field), or empty for any form; page: a path, * at the end for every page under it; event: a tracker event’s name; scroll: how far down one of the tested pages, in percent: 25, 50, 75, 90 or 100. Empty for booking, checkout and purchase.
Responses
Section titled “Responses”Done
object
The site’s address, its own domain first.
object
object
Opens this variant of the first page for whoever follows it, counting nothing.
object
Ended with its winner shown to every visitor, until the change is in the site’s code.
Example
{ "kind": "content", "variants": [ { "key": "a", "swaps": [ { "op": "text" } ] } ], "goal": { "kind": "lead" }, "status": "draft", "winner": "a"}What was sent isn’t valid (invalid).
object
object
object
Example
{ "error": { "code": "invalid" }}No key, or one that’s unknown, off or expired.
object
object
object
Example
{ "error": { "code": "invalid" }}The key doesn’t have the permission this needs.
object
object
object
Example
{ "error": { "code": "invalid" }}Nothing has that id (not_found).
object
object
object
Example
{ "error": { "code": "invalid" }}A request with the same Idempotency-Key is still running (conflict).
object
object
object
Example
{ "error": { "code": "invalid" }}The Idempotency-Key was used with a different request.
object
object
object
Example
{ "error": { "code": "invalid" }}Over the rate limit; see retry-after.
object
object
object
Example
{ "error": { "code": "invalid" }}