Skip to content

Set up an experiment

POST
/api/v1/analytics/experiments
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.

Idempotency-Key
string
>= 1 characters <= 255 characters

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-1f2d3c4b5a69
Media typeapplication/json
object
siteId
required

The site it tests.

string
/^site_[0-9A-HJKMNP-TV-Z]{26}$/
kind
required
string
Allowed values: content page site
name
required

What it tests, in a few words.

string
<= 80 characters
hypothesis

What it should show and why, in a sentence.

string
<= 500 characters
pages
required

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.

Array<string>
>= 1 items <= 10 items
traffic

The share of visitors in the test, in percent (all when left out); the rest see the control and aren’t counted.

integer
>= 1 <= 100
variants
required

The control first (it changes nothing), then 1 to 3 variants.

Array<object>
>= 2 items <= 4 items
object
name

Such as Control or Shorter form.

string
<= 40 characters
weight

Its share of the test’s visitors, in percent; the weights add up to 100, even when left out.

integer
<= 100
swaps

Content: the changes to the page, in order.

Array<object>
<= 20 items
object
selector
required

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 (+, ~).

string
<= 200 characters
op
required

Text sets its text, html its inner HTML, replace puts HTML in its place, attribute sets one attribute, remove takes it out.

string
Allowed values: text html replace attribute remove
attribute
Any of:
string
<= 64 characters
value
Any of:
string
<= 4000 characters
css

Content: CSS added to the page’s head, such as a button’s colour.

string
<= 8000 characters
path
Any of:
string
<= 201 characters
siteId
Any of:

A site’s id, from sites.workers.list.

string
/^site_[0-9A-HJKMNP-TV-Z]{26}$/
goal
required

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
kind
required
string
Allowed values: lead booking checkout purchase page event scroll
match

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.

string
"" <= 200 characters

Done

Media typeapplication/json
object
id
required
string
siteId
required
string
siteName
required
string | null
hostname
required

The site’s address, its own domain first.

string | null
name
required
string
hypothesis
required
string
kind
required
string
Allowed values: content page site
pages
required
Array<string>
traffic
required
number
variants
required
Array<object>
object
key
required
string
Allowed values: a b c d
name
required
string
weight
required
number
swaps
required
Array<object>
object
selector
required
string
op
required
string
Allowed values: text html replace attribute remove
attribute
string
value
string
css
required
string
path
required
string | null
siteId
required
string | null
siteName
required
string | null
addedAt
required
Any of:
string format: date-time
previewUrl
required

Opens this variant of the first page for whoever follows it, counting nothing.

string | null
goal
required
object
kind
required
string
Allowed values: lead booking checkout purchase page event scroll
match
required
string
status
required
string
Allowed values: draft running paused ended
winner
required
Any of:
string
Allowed values: a b c d
serving
required

Ended with its winner shown to every visitor, until the change is in the site’s code.

boolean
note
required
string
startedAt
required
Any of:
string format: date-time
endedAt
required
Any of:
string format: date-time
createdBy
required
string
createdAt
required
string format: date-time
updatedAt
required
string format: date-time

Example

{
"kind": "content",
"variants": [
{
"key": "a",
"swaps": [
{
"op": "text"
}
]
}
],
"goal": {
"kind": "lead"
},
"status": "draft",
"winner": "a"
}

What was sent isn’t valid (invalid).

Media typeapplication/json
object
error
required
object
code
required
string
Allowed values: invalid unauthorized forbidden not_found conflict too_large rate_limited unavailable internal
message
required
string
details
object
key
additional properties
any

Example

{
"error": {
"code": "invalid"
}
}

No key, or one that’s unknown, off or expired.

Media typeapplication/json
object
error
required
object
code
required
string
Allowed values: invalid unauthorized forbidden not_found conflict too_large rate_limited unavailable internal
message
required
string
details
object
key
additional properties
any

Example

{
"error": {
"code": "invalid"
}
}

The key doesn’t have the permission this needs.

Media typeapplication/json
object
error
required
object
code
required
string
Allowed values: invalid unauthorized forbidden not_found conflict too_large rate_limited unavailable internal
message
required
string
details
object
key
additional properties
any

Example

{
"error": {
"code": "invalid"
}
}

Nothing has that id (not_found).

Media typeapplication/json
object
error
required
object
code
required
string
Allowed values: invalid unauthorized forbidden not_found conflict too_large rate_limited unavailable internal
message
required
string
details
object
key
additional properties
any

Example

{
"error": {
"code": "invalid"
}
}

A request with the same Idempotency-Key is still running (conflict).

Media typeapplication/json
object
error
required
object
code
required
string
Allowed values: invalid unauthorized forbidden not_found conflict too_large rate_limited unavailable internal
message
required
string
details
object
key
additional properties
any

Example

{
"error": {
"code": "invalid"
}
}

The Idempotency-Key was used with a different request.

Media typeapplication/json
object
error
required
object
code
required
string
Allowed values: invalid unauthorized forbidden not_found conflict too_large rate_limited unavailable internal
message
required
string
details
object
key
additional properties
any

Example

{
"error": {
"code": "invalid"
}
}

Over the rate limit; see retry-after.

Media typeapplication/json
object
error
required
object
code
required
string
Allowed values: invalid unauthorized forbidden not_found conflict too_large rate_limited unavailable internal
message
required
string
details
object
key
additional properties
any

Example

{
"error": {
"code": "invalid"
}
}