{
  "openapi": "3.1.0",
  "info": {
    "title": "Conversionloop API",
    "version": "1",
    "summary": "Manage projects, data fields, audiences and campaigns, and read results.",
    "description": "The REST API behind the Conversionloop dashboard. Everything you can set up\nin the dashboard, you can automate here.\n\nRequests and responses are JSON. Authenticate with an API token as a bearer\ntoken. Each endpoint lists the scope the token needs.\n",
    "contact": {
      "url": "https://conversionloop.net/"
    }
  },
  "servers": [
    {
      "url": "https://api.conversionloop.net"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Projects",
      "description": "A project is one website: one script tag, one public key, one set of\ncampaigns. Data fields, audiences and campaigns all belong to a project.\n"
    },
    {
      "name": "Data fields",
      "description": "Typed values your site passes to the script with `conversionloop.set()`.\nAudiences can target them, and campaigns can store them with every\nresponse.\n"
    },
    {
      "name": "Audiences",
      "description": "Reusable visitor segments. The script evaluates them in the browser, so\nno visitor data has to leave the page before a campaign shows.\n"
    },
    {
      "name": "Campaigns",
      "description": "A question (or call to action) shown to an audience at a chosen moment.\nNew campaigns start as drafts; set the status to `live` to publish.\n"
    },
    {
      "name": "Insights",
      "description": "Results per project and per campaign, and the raw responses as CSV."
    },
    {
      "name": "Account",
      "description": "Session usage and subscription of the workspace the token belongs to."
    }
  ],
  "paths": {
    "/v1/projects": {
      "get": {
        "tags": [
          "Projects"
        ],
        "operationId": "listProjects",
        "summary": "List projects",
        "description": "All projects of the workspace that are not archived, oldest first.",
        "x-scope": "projects:read",
        "responses": {
          "200": {
            "description": "The projects.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "allOf": [
                          {
                            "$ref": "#/components/schemas/Project"
                          },
                          {
                            "type": "object",
                            "properties": {
                              "_count": {
                                "type": "object",
                                "description": "Number of campaigns, audiences and data fields in the project.",
                                "properties": {
                                  "campaigns": {
                                    "type": "integer"
                                  },
                                  "audiences": {
                                    "type": "integer"
                                  },
                                  "dataFields": {
                                    "type": "integer"
                                  }
                                }
                              }
                            }
                          }
                        ]
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      },
      "post": {
        "tags": [
          "Projects"
        ],
        "operationId": "createProject",
        "summary": "Create a project",
        "description": "Creates a project with a new public key. Campaigns are delivered inside the script unless you set `inlineConfig` to false.",
        "x-scope": "projects:write",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProjectInput"
              },
              "example": {
                "name": "Online shop",
                "domains": [
                  "shop.example.com"
                ],
                "consentMode": "required",
                "consentSignal": "cmpConsentGiven"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The new project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Project"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/v1/projects/{projectId}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/projectId"
        }
      ],
      "get": {
        "tags": [
          "Projects"
        ],
        "operationId": "getProject",
        "summary": "Get a project",
        "x-scope": "projects:read",
        "responses": {
          "200": {
            "description": "The project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Project"
                },
                "example": {
                  "id": "prj_4k9x2m7q1v8b3n6c5z0wd",
                  "workspaceId": "wsp_8h2k4m6p9r1t3v5x7z0bc",
                  "name": "Online shop",
                  "publicKey": "prj_live_0wk048ap7g5r9ba007fs98gj",
                  "domains": [
                    "shop.example.com"
                  ],
                  "consentMode": "required",
                  "consentSignal": "cmpConsentGiven",
                  "sampleRate": 1,
                  "maxConcurrent": 1,
                  "debug": false,
                  "inlineConfig": true,
                  "revision": "7q2m9x4k1v8b",
                  "archivedAt": null,
                  "createdAt": "2026-12-03T09:12:44.120Z",
                  "updatedAt": "2026-12-03T09:30:02.871Z"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "patch": {
        "tags": [
          "Projects"
        ],
        "operationId": "updateProject",
        "summary": "Update a project",
        "description": "Changes only the fields you send. Changes reach visitors within about five minutes.",
        "x-scope": "projects:write",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProjectPatch"
              },
              "example": {
                "domains": [
                  "shop.example.com",
                  "*.example.com"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Project"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "delete": {
        "tags": [
          "Projects"
        ],
        "operationId": "archiveProject",
        "summary": "Archive a project",
        "description": "Archives the project. The script stops serving campaigns for it, and it\nno longer appears in the project list. Collected responses are kept.\n",
        "x-scope": "projects:write",
        "responses": {
          "204": {
            "description": "Archived."
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/projects/{projectId}/rotate-key": {
      "parameters": [
        {
          "$ref": "#/components/parameters/projectId"
        }
      ],
      "post": {
        "tags": [
          "Projects"
        ],
        "operationId": "rotateProjectKey",
        "summary": "Rotate the public key",
        "description": "Issues a new public key. Pages that still use the old script tag stop\nshowing campaigns until you update the tag. Use this if someone embeds\nyour key on sites you do not control.\n",
        "x-scope": "projects:write",
        "responses": {
          "200": {
            "description": "The project with its new `publicKey`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Project"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/projects/{projectId}/snippet": {
      "parameters": [
        {
          "$ref": "#/components/parameters/projectId"
        }
      ],
      "get": {
        "tags": [
          "Projects"
        ],
        "operationId": "getProjectSnippet",
        "summary": "Get the script tag",
        "description": "The script tag to paste into the `<head>` of your pages, matching the project's delivery setting.",
        "x-scope": "projects:read",
        "responses": {
          "200": {
            "description": "The script tag.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "snippet",
                    "publicKey",
                    "inlineConfig"
                  ],
                  "properties": {
                    "snippet": {
                      "type": "string",
                      "description": "The complete `<script>` tag."
                    },
                    "publicKey": {
                      "type": "string"
                    },
                    "inlineConfig": {
                      "type": "boolean",
                      "description": "Whether campaigns are delivered inside the script."
                    }
                  }
                },
                "example": {
                  "snippet": "<script async src=\"https://cdn.conversionloop.net/v1/p/prj_live_0wk048ap7g5r9ba007fs98gj.js\"></script>",
                  "publicKey": "prj_live_0wk048ap7g5r9ba007fs98gj",
                  "inlineConfig": true
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/projects/{projectId}/bundle-size": {
      "parameters": [
        {
          "$ref": "#/components/parameters/projectId"
        }
      ],
      "get": {
        "tags": [
          "Projects"
        ],
        "operationId": "getProjectBundleSize",
        "summary": "Get the script size",
        "description": "Transfer size of both delivery options with the campaigns that are\nlive right now, so you can decide whether to deliver campaigns inside\nthe script. Sizes are in bytes.\n",
        "x-scope": "projects:read",
        "responses": {
          "200": {
            "description": "Sizes in bytes, uncompressed and gzip.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "campaigns": {
                      "type": "integer",
                      "description": "Number of live and scheduled campaigns measured."
                    },
                    "engine": {
                      "description": "The script alone, as loaded when campaigns come from the API. `null` if the script is unavailable.",
                      "anyOf": [
                        {
                          "$ref": "#/components/schemas/Size"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "config": {
                      "description": "The campaign configuration the script loads separately in that case.",
                      "$ref": "#/components/schemas/Size"
                    },
                    "inline": {
                      "description": "The script with campaigns inside. `null` if the script is unavailable.",
                      "anyOf": [
                        {
                          "$ref": "#/components/schemas/Size"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  }
                },
                "example": {
                  "campaigns": 2,
                  "engine": {
                    "raw": 31210,
                    "gzip": 11843
                  },
                  "config": {
                    "raw": 2914,
                    "gzip": 902
                  },
                  "inline": {
                    "raw": 34171,
                    "gzip": 12611
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/projects/{projectId}/data-fields": {
      "parameters": [
        {
          "$ref": "#/components/parameters/projectId"
        }
      ],
      "get": {
        "tags": [
          "Data fields"
        ],
        "operationId": "listDataFields",
        "summary": "List data fields",
        "description": "All data fields of the project, sorted by key.",
        "x-scope": "datafields:read",
        "responses": {
          "200": {
            "description": "The data fields.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/DataField"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "post": {
        "tags": [
          "Data fields"
        ],
        "operationId": "createDataField",
        "summary": "Create a data field",
        "description": "The key must be unique within the project and cannot be changed later.",
        "x-scope": "datafields:write",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DataFieldInput"
              },
              "example": {
                "key": "cart_value",
                "label": "Cart value",
                "type": "number",
                "description": "Gross cart value in EUR."
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The new data field.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DataField"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/v1/projects/{projectId}/data-fields/{dataFieldId}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/projectId"
        },
        {
          "name": "dataFieldId",
          "in": "path",
          "required": true,
          "description": "ID of the data field, starting with `dfl_`.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "patch": {
        "tags": [
          "Data fields"
        ],
        "operationId": "updateDataField",
        "summary": "Update a data field",
        "description": "Changes only the fields you send. The `key` cannot be changed, because campaigns and stored responses refer to it.",
        "x-scope": "datafields:write",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DataFieldPatch"
              },
              "example": {
                "label": "Cart value (gross)"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated data field.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DataField"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "delete": {
        "tags": [
          "Data fields"
        ],
        "operationId": "deleteDataField",
        "summary": "Delete a data field",
        "x-scope": "datafields:write",
        "responses": {
          "204": {
            "description": "Deleted."
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/projects/{projectId}/audiences": {
      "parameters": [
        {
          "$ref": "#/components/parameters/projectId"
        }
      ],
      "get": {
        "tags": [
          "Audiences"
        ],
        "operationId": "listAudiences",
        "summary": "List audiences",
        "description": "All audiences of the project, newest first.",
        "x-scope": "audiences:read",
        "responses": {
          "200": {
            "description": "The audiences.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "allOf": [
                          {
                            "$ref": "#/components/schemas/Audience"
                          },
                          {
                            "type": "object",
                            "properties": {
                              "_count": {
                                "type": "object",
                                "properties": {
                                  "campaigns": {
                                    "type": "integer",
                                    "description": "Number of campaigns using this audience."
                                  }
                                }
                              }
                            }
                          }
                        ]
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "post": {
        "tags": [
          "Audiences"
        ],
        "operationId": "createAudience",
        "summary": "Create an audience",
        "description": "Rules are checked before saving: unknown operators, missing values and\nreferences to audiences that do not exist (or that would form a loop)\nare rejected. See [Audience rules](/audience-rules.html) for all\nconditions.\n",
        "x-scope": "audiences:write",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AudienceInput"
              },
              "example": {
                "name": "Leaving the checkout",
                "rules": {
                  "groups": [
                    {
                      "id": "g1",
                      "match": "all",
                      "conditions": [
                        {
                          "id": "c1",
                          "type": "url",
                          "operator": "contains",
                          "value": "/checkout"
                        },
                        {
                          "id": "c2",
                          "type": "exit_intent",
                          "operator": "is_true"
                        }
                      ]
                    }
                  ]
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The new audience.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Audience"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          }
        }
      }
    },
    "/v1/projects/{projectId}/audiences/{audienceId}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/projectId"
        },
        {
          "$ref": "#/components/parameters/audienceId"
        }
      ],
      "get": {
        "tags": [
          "Audiences"
        ],
        "operationId": "getAudience",
        "summary": "Get an audience",
        "x-scope": "audiences:read",
        "responses": {
          "200": {
            "description": "The audience.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Audience"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "patch": {
        "tags": [
          "Audiences"
        ],
        "operationId": "updateAudience",
        "summary": "Update an audience",
        "description": "Changes only the fields you send. `rules` is replaced as a whole. Live campaigns using the audience pick up the change within about five minutes.",
        "x-scope": "audiences:write",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AudiencePatch"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated audience.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Audience"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          }
        }
      },
      "delete": {
        "tags": [
          "Audiences"
        ],
        "operationId": "deleteAudience",
        "summary": "Delete an audience",
        "description": "Only possible while no campaign uses the audience; otherwise the response is `422`.",
        "x-scope": "audiences:write",
        "responses": {
          "204": {
            "description": "Deleted."
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          }
        }
      }
    },
    "/v1/projects/{projectId}/campaigns": {
      "parameters": [
        {
          "$ref": "#/components/parameters/projectId"
        }
      ],
      "get": {
        "tags": [
          "Campaigns"
        ],
        "operationId": "listCampaigns",
        "summary": "List campaigns",
        "description": "Campaigns of the project, most recently changed first. Archived campaigns are left out unless you ask for them with `status=archived`.",
        "x-scope": "campaigns:read",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "description": "Only campaigns with this status.",
            "schema": {
              "$ref": "#/components/schemas/CampaignStatus"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The campaigns.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "allOf": [
                          {
                            "$ref": "#/components/schemas/Campaign"
                          },
                          {
                            "type": "object",
                            "properties": {
                              "audience": {
                                "description": "Name of the assigned audience, if any.",
                                "anyOf": [
                                  {
                                    "type": "object",
                                    "properties": {
                                      "id": {
                                        "type": "string"
                                      },
                                      "name": {
                                        "type": "string"
                                      }
                                    }
                                  },
                                  {
                                    "type": "null"
                                  }
                                ]
                              }
                            }
                          }
                        ]
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "post": {
        "tags": [
          "Campaigns"
        ],
        "operationId": "createCampaign",
        "summary": "Create a campaign",
        "description": "Creates a draft. Drafts may be incomplete; the checks for going live\nhappen when you [change the status](#operation/setCampaignStatus).\n`appearance` and `delivery` can be empty objects to use the defaults.\n",
        "x-scope": "campaigns:write",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CampaignInput"
              },
              "example": {
                "name": "Why are you leaving the checkout?",
                "slug": "checkout-exit",
                "audienceId": "aud_2m8k4x9q1v7b3n6c5z0wd",
                "dataFieldKeys": [
                  "cart_value"
                ],
                "content": {
                  "kind": "single_choice",
                  "question": "What is stopping you from ordering today?",
                  "options": [
                    {
                      "id": "price",
                      "label": "The price"
                    },
                    {
                      "id": "shipping",
                      "label": "Shipping costs or time"
                    },
                    {
                      "id": "unsure",
                      "label": "Not sure the product fits"
                    },
                    {
                      "id": "other",
                      "label": "Something else",
                      "followUp": "What is it?"
                    }
                  ]
                },
                "appearance": {
                  "position": "bottom_right"
                },
                "delivery": {
                  "delayMs": 500
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The new campaign, with status `draft`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Campaign"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          }
        }
      }
    },
    "/v1/projects/{projectId}/campaigns/{campaignId}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/projectId"
        },
        {
          "$ref": "#/components/parameters/campaignId"
        }
      ],
      "get": {
        "tags": [
          "Campaigns"
        ],
        "operationId": "getCampaign",
        "summary": "Get a campaign",
        "description": "The campaign including its full audience.",
        "x-scope": "campaigns:read",
        "responses": {
          "200": {
            "description": "The campaign.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Campaign"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "audience": {
                          "anyOf": [
                            {
                              "$ref": "#/components/schemas/Audience"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "patch": {
        "tags": [
          "Campaigns"
        ],
        "operationId": "updateCampaign",
        "summary": "Update a campaign",
        "description": "Changes only the fields you send. `content`, `appearance` and\n`delivery` are each replaced as a whole. Changes to a live campaign\nreach visitors within about five minutes.\n",
        "x-scope": "campaigns:write",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CampaignPatch"
              },
              "example": {
                "delivery": {
                  "delayMs": 2000,
                  "trafficShare": 0.5
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated campaign.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Campaign"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          }
        }
      },
      "delete": {
        "tags": [
          "Campaigns"
        ],
        "operationId": "archiveCampaign",
        "summary": "Archive a campaign",
        "description": "Takes the campaign offline and sets its status to `archived`. Its responses stay available in Insights.",
        "x-scope": "campaigns:write",
        "responses": {
          "204": {
            "description": "Archived."
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/projects/{projectId}/campaigns/{campaignId}/status": {
      "parameters": [
        {
          "$ref": "#/components/parameters/projectId"
        },
        {
          "$ref": "#/components/parameters/campaignId"
        }
      ],
      "post": {
        "tags": [
          "Campaigns"
        ],
        "operationId": "setCampaignStatus",
        "summary": "Change the status",
        "description": "Publishes, pauses or archives a campaign. Going `live` or `scheduled`\nrequires an audience and complete content and appearance; `scheduled`\nalso requires `startsAt`. If anything is missing, the response is\n`422` and `details` lists what to fix.\n",
        "x-scope": "campaigns:write",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "status"
                ],
                "properties": {
                  "status": {
                    "$ref": "#/components/schemas/CampaignStatus"
                  }
                }
              },
              "example": {
                "status": "live"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The campaign with its new status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Campaign"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "description": "The campaign cannot go live yet.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": {
                    "code": "unprocessable",
                    "message": "This campaign cannot go live yet.",
                    "details": [
                      "An audience must be assigned."
                    ]
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/projects/{projectId}/insights": {
      "parameters": [
        {
          "$ref": "#/components/parameters/projectId"
        }
      ],
      "get": {
        "tags": [
          "Insights"
        ],
        "operationId": "getProjectInsights",
        "summary": "Results of all campaigns",
        "description": "Impressions, responses, dismissals and conversions per campaign in a time range (default the last 30 days).",
        "x-scope": "insights:read",
        "parameters": [
          {
            "$ref": "#/components/parameters/from"
          },
          {
            "$ref": "#/components/parameters/to"
          },
          {
            "name": "campaignId",
            "in": "query",
            "description": "Only count events of this campaign.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "One entry per campaign of the project, including campaigns without events.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "range": {
                      "$ref": "#/components/schemas/Range"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "campaign": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "string"
                              },
                              "name": {
                                "type": "string"
                              },
                              "slug": {
                                "type": "string"
                              },
                              "status": {
                                "$ref": "#/components/schemas/CampaignStatus"
                              }
                            }
                          },
                          "impressions": {
                            "type": "integer"
                          },
                          "responses": {
                            "type": "integer"
                          },
                          "dismissals": {
                            "type": "integer"
                          },
                          "conversions": {
                            "type": "integer"
                          },
                          "responseRate": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Responses per impression, 0 to 1, rounded to four decimals. `null` without impressions."
                          }
                        }
                      }
                    }
                  }
                },
                "example": {
                  "range": {
                    "from": "2026-11-03T10:00:00.000Z",
                    "to": "2026-12-03T10:00:00.000Z"
                  },
                  "data": [
                    {
                      "campaign": {
                        "id": "cmp_9x2k4m7q1v8b3n6c5z0wd",
                        "name": "Why are you leaving the checkout?",
                        "slug": "checkout-exit",
                        "status": "live"
                      },
                      "impressions": 1840,
                      "responses": 212,
                      "dismissals": 1011,
                      "conversions": 0,
                      "responseRate": 0.1152
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/projects/{projectId}/campaigns/{campaignId}/insights": {
      "parameters": [
        {
          "$ref": "#/components/parameters/projectId"
        },
        {
          "$ref": "#/components/parameters/campaignId"
        }
      ],
      "get": {
        "tags": [
          "Insights"
        ],
        "operationId": "getCampaignInsights",
        "summary": "Results of one campaign",
        "description": "Answer distribution, ratings, free-text answers, a breakdown by device\nand a daily timeline. Covers up to 5,000 responses in the range; for\nall responses use the [CSV export](#operation/exportCampaignResponses).\n",
        "x-scope": "insights:read",
        "parameters": [
          {
            "$ref": "#/components/parameters/from"
          },
          {
            "$ref": "#/components/parameters/to"
          }
        ],
        "responses": {
          "200": {
            "description": "The results.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "range": {
                      "$ref": "#/components/schemas/Range"
                    },
                    "responses": {
                      "type": "integer",
                      "description": "Number of responses evaluated (at most 5",
                      "000).": null
                    },
                    "options": {
                      "type": "array",
                      "description": "How often each answer option was chosen, most chosen first. With multiple choice every chosen option counts.",
                      "items": {
                        "type": "object",
                        "properties": {
                          "optionId": {
                            "type": "string"
                          },
                          "count": {
                            "type": "integer"
                          }
                        }
                      }
                    },
                    "rating": {
                      "type": "object",
                      "properties": {
                        "average": {
                          "type": [
                            "number",
                            "null"
                          ],
                          "description": "Average rating",
                          "two decimals.": null
                        },
                        "distribution": {
                          "type": "object",
                          "description": "Number of responses per rating value.",
                          "additionalProperties": {
                            "type": "integer"
                          }
                        }
                      }
                    },
                    "texts": {
                      "type": "array",
                      "description": "The 200 most recent free-text answers.",
                      "items": {
                        "type": "object",
                        "properties": {
                          "text": {
                            "type": "string"
                          },
                          "at": {
                            "type": "string",
                            "format": "date-time"
                          }
                        }
                      }
                    },
                    "byDevice": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "deviceType": {
                            "type": "string",
                            "enum": [
                              "phone",
                              "tablet",
                              "desktop",
                              "unknown"
                            ]
                          },
                          "type": {
                            "$ref": "#/components/schemas/EventType"
                          },
                          "count": {
                            "type": "integer"
                          }
                        }
                      }
                    },
                    "timeline": {
                      "type": "array",
                      "description": "Events per day and type.",
                      "items": {
                        "type": "object",
                        "properties": {
                          "day": {
                            "type": "string",
                            "format": "date"
                          },
                          "type": {
                            "$ref": "#/components/schemas/EventType"
                          },
                          "count": {
                            "type": "integer"
                          }
                        }
                      }
                    }
                  }
                },
                "example": {
                  "range": {
                    "from": "2026-11-03T10:00:00.000Z",
                    "to": "2026-12-03T10:00:00.000Z"
                  },
                  "responses": 212,
                  "options": [
                    {
                      "optionId": "shipping",
                      "count": 97
                    },
                    {
                      "optionId": "price",
                      "count": 64
                    },
                    {
                      "optionId": "unsure",
                      "count": 38
                    },
                    {
                      "optionId": "other",
                      "count": 13
                    }
                  ],
                  "rating": {
                    "average": null,
                    "distribution": {}
                  },
                  "texts": [
                    {
                      "text": "I could not find the delivery date.",
                      "at": "2026-12-02T16:41:09.000Z"
                    }
                  ],
                  "byDevice": [
                    {
                      "deviceType": "phone",
                      "type": "response",
                      "count": 131
                    },
                    {
                      "deviceType": "desktop",
                      "type": "response",
                      "count": 81
                    }
                  ],
                  "timeline": [
                    {
                      "day": "2026-12-02",
                      "type": "impression",
                      "count": 64
                    },
                    {
                      "day": "2026-12-02",
                      "type": "response",
                      "count": 8
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/projects/{projectId}/campaigns/{campaignId}/responses.csv": {
      "parameters": [
        {
          "$ref": "#/components/parameters/projectId"
        },
        {
          "$ref": "#/components/parameters/campaignId"
        }
      ],
      "get": {
        "tags": [
          "Insights"
        ],
        "operationId": "exportCampaignResponses",
        "summary": "Export responses as CSV",
        "description": "All responses of the campaign, oldest first, up to 50,000 rows. Columns:\n`occurred_at`, `session_id`, `options` (option IDs separated by `|`),\n`rating`, `text`, `device`, `browser`, `os`, `url`, `dwell_ms`,\n`scroll_depth`, `data_fields` (JSON).\n\nCells that start with `=`, `+`, `-` or `@` are prefixed with an\napostrophe, so spreadsheet programs do not run them as formulas.\n",
        "x-scope": "insights:read",
        "responses": {
          "200": {
            "description": "The CSV file.",
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string"
                },
                "example": "occurred_at,session_id,options,rating,text,device,browser,os,url,dwell_ms,scroll_depth,data_fields\n2026-12-02T16:41:09.000Z,s_7f3k9x2m4q,shipping,,I could not find the delivery date.,phone,safari,ios,https://shop.example.com/checkout,48210,62,\"{\"\"cart_value\"\":149.9}\"\n"
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "tags": [
          "Account"
        ],
        "operationId": "getUsage",
        "summary": "Session usage this month",
        "description": "Sessions counted in the current calendar month (UTC) against the quota of the plan. Campaigns keep running above the quota.",
        "x-scope": "insights:read",
        "responses": {
          "200": {
            "description": "The usage.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "sessions": {
                      "type": "integer",
                      "description": "Sessions this month."
                    },
                    "quota": {
                      "type": "integer",
                      "description": "Sessions included in the plan per month."
                    },
                    "ratio": {
                      "type": "number",
                      "description": "`sessions / quota`; above 1 when the quota is exceeded."
                    }
                  }
                },
                "example": {
                  "sessions": 18412,
                  "quota": 100000,
                  "ratio": 0.18412
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/v1/billing/subscription": {
      "get": {
        "tags": [
          "Account"
        ],
        "operationId": "getSubscription",
        "summary": "Get the subscription",
        "description": "Plan, status and current billing period of the workspace. Upgrades and cancellations happen in the dashboard.",
        "x-scope": "billing:read",
        "responses": {
          "200": {
            "description": "The subscription and its plan.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "subscription": {
                      "type": "object",
                      "properties": {
                        "planId": {
                          "type": "string",
                          "enum": [
                            "free",
                            "growth",
                            "scale"
                          ]
                        },
                        "billing": {
                          "type": "string",
                          "enum": [
                            "monthly",
                            "yearly"
                          ]
                        },
                        "status": {
                          "type": "string",
                          "enum": [
                            "trialing",
                            "active",
                            "past_due",
                            "canceled",
                            "paused"
                          ]
                        },
                        "sessionQuota": {
                          "type": "integer"
                        },
                        "trialEndsAt": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "date-time"
                        },
                        "currentPeriodStart": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "currentPeriodEnd": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "cancelAt": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "date-time",
                          "description": "Set after a cancellation; the plan runs until then."
                        }
                      }
                    },
                    "plan": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "name": {
                          "type": "string"
                        },
                        "monthly": {
                          "type": "number",
                          "description": "Price per month in EUR",
                          "excluding VAT.": null
                        },
                        "yearly": {
                          "type": "number",
                          "description": "Price per year in EUR",
                          "excluding VAT.": null
                        },
                        "sessionQuota": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "An API token starting with `cl_sk_`. Create one in the dashboard under Settings → API tokens."
      }
    },
    "parameters": {
      "projectId": {
        "name": "projectId",
        "in": "path",
        "required": true,
        "description": "ID of the project, starting with `prj_` (not the public key).",
        "schema": {
          "type": "string"
        }
      },
      "audienceId": {
        "name": "audienceId",
        "in": "path",
        "required": true,
        "description": "ID of the audience, starting with `aud_`.",
        "schema": {
          "type": "string"
        }
      },
      "campaignId": {
        "name": "campaignId",
        "in": "path",
        "required": true,
        "description": "ID of the campaign, starting with `cmp_`.",
        "schema": {
          "type": "string"
        }
      },
      "from": {
        "name": "from",
        "in": "query",
        "description": "Start of the range, ISO 8601. Default 30 days before `to`.",
        "schema": {
          "type": "string",
          "format": "date-time"
        }
      },
      "to": {
        "name": "to",
        "in": "query",
        "description": "End of the range, ISO 8601. Default now.",
        "schema": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "The request is malformed or fails validation. `details` lists the issues with the path of each field.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "bad_request",
                "message": "Invalid campaign.",
                "details": [
                  {
                    "code": "too_small",
                    "path": [
                      "content",
                      "options"
                    ],
                    "message": "Too small: expected array to have >=2 items"
                  }
                ]
              }
            }
          }
        }
      },
      "Unauthorized": {
        "description": "The token is missing, unknown, expired or revoked.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "unauthorized",
                "message": "Authentication required."
              }
            }
          }
        }
      },
      "Forbidden": {
        "description": "The token lacks the required scope.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "forbidden",
                "message": "This token is missing the \"campaigns:write\" scope."
              }
            }
          }
        }
      },
      "NotFound": {
        "description": "The resource does not exist in the token's workspace.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "not_found",
                "message": "Project not found."
              }
            }
          }
        }
      },
      "Conflict": {
        "description": "A resource with the same key or slug already exists in the project.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "conflict",
                "message": "A campaign with slug \"checkout-exit\" already exists."
              }
            }
          }
        }
      },
      "Unprocessable": {
        "description": "The request is valid but cannot be applied, for example because it refers to something that does not exist.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "unprocessable",
                "message": "Unknown data fields: cart_total."
              }
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "description": "Stable machine-readable code. See [Errors](/basics.html#errors).",
                "enum": [
                  "bad_request",
                  "unauthorized",
                  "forbidden",
                  "not_found",
                  "conflict",
                  "unprocessable",
                  "rate_limited",
                  "internal_error"
                ]
              },
              "message": {
                "type": "string",
                "description": "Human-readable explanation. Wording may change."
              },
              "details": {
                "description": "Additional information",
                "for example validation issues.": null
              }
            }
          }
        }
      },
      "Size": {
        "type": "object",
        "properties": {
          "raw": {
            "type": "integer",
            "description": "Bytes uncompressed."
          },
          "gzip": {
            "type": "integer",
            "description": "Bytes with gzip",
            "as transferred.": null
          }
        }
      },
      "Range": {
        "type": "object",
        "description": "The time range the numbers cover.",
        "properties": {
          "from": {
            "type": "string",
            "format": "date-time"
          },
          "to": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "EventType": {
        "type": "string",
        "enum": [
          "impression",
          "response",
          "dismiss",
          "conversion"
        ]
      },
      "Project": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "ID, starting with `prj_`."
          },
          "workspaceId": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "publicKey": {
            "type": "string",
            "description": "Key in the script tag, starting with `prj_live_`. Not a secret."
          },
          "domains": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Hostnames the script runs on. Empty means any host."
          },
          "consentMode": {
            "type": "string",
            "enum": [
              "not_required",
              "required",
              "cookieless_fallback"
            ]
          },
          "consentSignal": {
            "type": [
              "string",
              "null"
            ]
          },
          "sampleRate": {
            "type": "number"
          },
          "maxConcurrent": {
            "type": "integer"
          },
          "debug": {
            "type": "boolean"
          },
          "inlineConfig": {
            "type": "boolean",
            "description": "Whether campaigns are delivered inside the script."
          },
          "revision": {
            "type": "string",
            "description": "Changes with every change that affects the script."
          },
          "archivedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ProjectInput": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "domains": {
            "type": "array",
            "maxItems": 50,
            "default": [],
            "description": "Hostnames the script may run on, like `example.com` or\n`*.example.com`. A domain also covers its subdomains. On any other\nhost the script stays silent and responses are rejected. Empty\nmeans no restriction: set this before going live.\n",
            "items": {
              "type": "string",
              "example": "shop.example.com"
            }
          },
          "consentMode": {
            "type": "string",
            "enum": [
              "not_required",
              "required",
              "cookieless_fallback"
            ],
            "default": "not_required",
            "description": "`required`: the script does nothing until consent is given.\n`cookieless_fallback`: it runs without storing anything on the\nvisitor's device until consent is given.\n"
          },
          "consentSignal": {
            "type": "string",
            "maxLength": 120,
            "description": "Name of a window event that signals consent, or of a global variable or function that returns true once consent is given."
          },
          "sampleRate": {
            "type": "number",
            "minimum": 0,
            "maximum": 1,
            "default": 1,
            "description": "Share of impressions that are recorded. Responses are always recorded. Lower it on very high traffic."
          },
          "maxConcurrent": {
            "type": "integer",
            "minimum": 1,
            "maximum": 3,
            "default": 1,
            "description": "How many campaigns may be visible at the same time."
          },
          "debug": {
            "type": "boolean",
            "default": false,
            "description": "Log what the script does to the browser console."
          },
          "inlineConfig": {
            "type": "boolean",
            "default": true,
            "description": "Deliver campaigns inside the script instead of loading them with a second request. See [Install the script](/install.html#delivery)."
          }
        }
      },
      "ProjectPatch": {
        "description": "Any fields of `ProjectInput`. Fields you leave out stay unchanged.",
        "allOf": [
          {
            "$ref": "#/components/schemas/ProjectInput"
          }
        ],
        "x-patch": true
      },
      "DataFieldInput": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64,
            "pattern": "^[a-z][a-z0-9_]*$",
            "description": "Name used in `conversionloop.set()` and in audience rules. Lowercase letters, digits and underscores, starting with a letter. Cannot be changed later.",
            "example": "cart_value"
          },
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "description": "Name shown in the dashboard."
          },
          "type": {
            "type": "string",
            "enum": [
              "string",
              "number",
              "boolean",
              "date",
              "enum"
            ],
            "description": "Type of the value. Values that do not match are ignored in comparisons."
          },
          "options": {
            "maxItems": 50,
            "type": "array",
            "items": {
              "type": "string",
              "maxLength": 120
            },
            "description": "Allowed values when `type` is `enum`."
          },
          "source": {
            "default": "client",
            "type": "string",
            "enum": [
              "client",
              "server"
            ],
            "description": "`client`: set in the browser with `conversionloop.set()`. `server`: reserved for values supplied by your backend."
          },
          "collect": {
            "default": true,
            "type": "boolean",
            "description": "Marks the field for storage with responses. Note: the script currently sends every data field you set along with impressions and answers, see [What is sent](/javascript.html#what-is-sent)."
          },
          "description": {
            "type": "string",
            "maxLength": 500,
            "description": "Note for your team."
          }
        },
        "required": [
          "key",
          "label",
          "type"
        ],
        "description": "A typed value your site passes to the script."
      },
      "DataFieldPatch": {
        "description": "Any fields of `DataFieldInput` except `key`. Fields you leave out stay unchanged.",
        "allOf": [
          {
            "$ref": "#/components/schemas/DataFieldInput"
          }
        ],
        "x-patch": true,
        "x-omit": [
          "key"
        ]
      },
      "DataField": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "ID, starting with `dfl_`."
          },
          "projectId": {
            "type": "string"
          },
          "workspaceId": {
            "type": "string"
          },
          "key": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "string",
              "number",
              "boolean",
              "date",
              "enum"
            ]
          },
          "options": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            }
          },
          "source": {
            "type": "string",
            "enum": [
              "client",
              "server"
            ]
          },
          "collect": {
            "type": "boolean"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "AudienceRules": {
        "type": "object",
        "properties": {
          "groups": {
            "minItems": 1,
            "maxItems": 10,
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1,
                  "description": "Any ID",
                  "unique within the audience.": null
                },
                "match": {
                  "default": "all",
                  "type": "string",
                  "enum": [
                    "all",
                    "any"
                  ],
                  "description": "`all`: every condition must match. `any`: one is enough."
                },
                "conditions": {
                  "minItems": 1,
                  "maxItems": 30,
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "minLength": 1,
                        "description": "Any ID",
                        "unique within the audience.": null
                      },
                      "type": {
                        "type": "string",
                        "enum": [
                          "dwell_time",
                          "scroll_depth",
                          "exit_intent",
                          "page_views",
                          "visit_count",
                          "element_seen",
                          "click",
                          "inactivity",
                          "url",
                          "referrer",
                          "utm",
                          "landing_page",
                          "schedule",
                          "device_type",
                          "browser",
                          "os",
                          "viewport",
                          "language",
                          "connection",
                          "prefers_reduced_motion",
                          "cookie",
                          "storage",
                          "data_field",
                          "campaign_state",
                          "audience"
                        ],
                        "description": "What to check. See [Audience rules](/audience-rules.html)."
                      },
                      "operator": {
                        "type": "string",
                        "enum": [
                          "eq",
                          "neq",
                          "gt",
                          "gte",
                          "lt",
                          "lte",
                          "between",
                          "contains",
                          "not_contains",
                          "starts_with",
                          "ends_with",
                          "regex",
                          "in",
                          "not_in",
                          "exists",
                          "not_exists",
                          "is_true",
                          "is_false"
                        ],
                        "description": "How to compare. Which operators are allowed depends on `type`."
                      },
                      "field": {
                        "type": "string",
                        "maxLength": 200,
                        "description": "Name of the cookie, data field, UTM parameter, CSS selector or campaign slug, for types that need one."
                      },
                      "value": {
                        "anyOf": [
                          {
                            "type": "string"
                          },
                          {
                            "type": "number"
                          },
                          {
                            "type": "boolean"
                          },
                          {
                            "type": "array",
                            "items": {
                              "type": [
                                "string",
                                "number"
                              ]
                            }
                          },
                          {
                            "type": "object",
                            "properties": {
                              "from": {
                                "type": "string"
                              },
                              "to": {
                                "type": "string"
                              },
                              "weekdays": {
                                "type": "array",
                                "items": {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 6
                                }
                              },
                              "timeFrom": {
                                "type": "string",
                                "pattern": "^\\d{2}:\\d{2}$"
                              },
                              "timeTo": {
                                "type": "string",
                                "pattern": "^\\d{2}:\\d{2}$"
                              },
                              "timezone": {
                                "default": "visitor",
                                "type": "string",
                                "enum": [
                                  "visitor",
                                  "workspace"
                                ]
                              }
                            }
                          }
                        ],
                        "description": "Value to compare with. Not needed for `exists`, `not_exists`, `is_true` and `is_false`. `between` takes two values as an array."
                      },
                      "include": {
                        "default": true,
                        "type": "boolean",
                        "description": "`false` turns the condition around: visitors who match it are excluded."
                      }
                    },
                    "required": [
                      "id",
                      "type",
                      "operator"
                    ]
                  }
                }
              },
              "required": [
                "id",
                "conditions"
              ]
            },
            "description": "One to ten groups; a visitor must match every group."
          }
        },
        "required": [
          "groups"
        ],
        "description": "Groups of conditions. Conditions inside a group are combined with the\ngroup's `match` (`all` = AND, `any` = OR); groups are always combined\nwith AND. All condition types, operators and values are listed under\n[Audience rules](/audience-rules.html).\n"
      },
      "AudienceInput": {
        "type": "object",
        "required": [
          "name",
          "rules"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "description": {
            "type": "string",
            "maxLength": 1000
          },
          "rules": {
            "$ref": "#/components/schemas/AudienceRules"
          }
        }
      },
      "AudiencePatch": {
        "description": "Any fields of `AudienceInput`. Fields you leave out stay unchanged.",
        "allOf": [
          {
            "$ref": "#/components/schemas/AudienceInput"
          }
        ],
        "x-patch": true
      },
      "Audience": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "ID, starting with `aud_`."
          },
          "projectId": {
            "type": "string"
          },
          "workspaceId": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "rules": {
            "$ref": "#/components/schemas/AudienceRules"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CampaignStatus": {
        "type": "string",
        "enum": [
          "draft",
          "scheduled",
          "live",
          "paused",
          "archived"
        ],
        "description": "`draft`: not shown. `scheduled`: shown between `startsAt` and `endsAt`.\n`live`: shown now (and until `endsAt`, if set). `paused`: not shown,\ncan be resumed. `archived`: not shown, hidden from lists.\n"
      },
      "CampaignContent": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "kind": {
                "type": "string",
                "const": "single_choice"
              },
              "question": {
                "type": "string",
                "minLength": 1,
                "maxLength": 300
              },
              "description": {
                "type": "string",
                "maxLength": 600
              },
              "options": {
                "minItems": 2,
                "maxItems": 10,
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "minLength": 1
                    },
                    "label": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 200
                    },
                    "followUp": {
                      "type": "string",
                      "maxLength": 200
                    },
                    "value": {
                      "type": "string",
                      "maxLength": 200
                    }
                  },
                  "required": [
                    "id",
                    "label"
                  ]
                },
                "description": "Two to ten answers."
              },
              "allowFreeText": {
                "default": false,
                "type": "boolean",
                "description": "Add a free-text field below the options."
              },
              "thanks": {
                "default": "Thank you!",
                "type": "string",
                "maxLength": 300,
                "description": "Shown after the answer."
              }
            },
            "required": [
              "kind",
              "question",
              "options"
            ],
            "title": "Single choice",
            "description": "One answer from a list, optionally with a free-text field."
          },
          {
            "type": "object",
            "properties": {
              "kind": {
                "type": "string",
                "const": "multi_choice"
              },
              "question": {
                "type": "string",
                "minLength": 1,
                "maxLength": 300
              },
              "description": {
                "type": "string",
                "maxLength": 600
              },
              "options": {
                "minItems": 2,
                "maxItems": 12,
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "minLength": 1
                    },
                    "label": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 200
                    },
                    "followUp": {
                      "type": "string",
                      "maxLength": 200
                    },
                    "value": {
                      "type": "string",
                      "maxLength": 200
                    }
                  },
                  "required": [
                    "id",
                    "label"
                  ]
                },
                "description": "Two to twelve answers."
              },
              "maxSelections": {
                "type": "integer",
                "minimum": 1,
                "maximum": 12,
                "description": "Upper limit of answers a visitor can pick."
              },
              "thanks": {
                "default": "Thank you!",
                "type": "string",
                "maxLength": 300,
                "description": "Shown after the answer."
              }
            },
            "required": [
              "kind",
              "question",
              "options"
            ],
            "title": "Multiple choice",
            "description": "Several answers from a list."
          },
          {
            "type": "object",
            "properties": {
              "kind": {
                "type": "string",
                "const": "free_text"
              },
              "question": {
                "type": "string",
                "minLength": 1,
                "maxLength": 300
              },
              "description": {
                "type": "string",
                "maxLength": 600
              },
              "placeholder": {
                "type": "string",
                "maxLength": 160
              },
              "maxLength": {
                "default": 500,
                "type": "integer",
                "minimum": 50,
                "maximum": 2000,
                "description": "Maximum characters of the answer."
              },
              "thanks": {
                "default": "Thank you!",
                "type": "string",
                "maxLength": 300,
                "description": "Shown after the answer."
              }
            },
            "required": [
              "kind",
              "question"
            ],
            "title": "Free text",
            "description": "An open question."
          },
          {
            "type": "object",
            "properties": {
              "kind": {
                "type": "string",
                "const": "rating"
              },
              "question": {
                "type": "string",
                "minLength": 1,
                "maxLength": 300
              },
              "description": {
                "type": "string",
                "maxLength": 600
              },
              "scale": {
                "default": "1-5",
                "type": "string",
                "enum": [
                  "1-5",
                  "1-10",
                  "nps",
                  "emoji"
                ],
                "description": "`1-5`, `1-10`, `nps` (0–10) or `emoji` (five faces)."
              },
              "lowLabel": {
                "type": "string",
                "maxLength": 60,
                "description": "Label at the low end of the scale."
              },
              "highLabel": {
                "type": "string",
                "maxLength": 60,
                "description": "Label at the high end of the scale."
              },
              "followUpQuestion": {
                "type": "string",
                "maxLength": 300,
                "description": "Free-text question shown after the rating."
              },
              "thanks": {
                "default": "Thank you!",
                "type": "string",
                "maxLength": 300,
                "description": "Shown after the answer."
              }
            },
            "required": [
              "kind",
              "question"
            ],
            "title": "Rating",
            "description": "A scale, NPS or emoji rating, optionally with a follow-up question."
          },
          {
            "type": "object",
            "properties": {
              "kind": {
                "type": "string",
                "const": "cta"
              },
              "headline": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              },
              "description": {
                "type": "string",
                "maxLength": 600
              },
              "buttonLabel": {
                "type": "string",
                "minLength": 1,
                "maxLength": 80
              },
              "buttonHref": {
                "type": "string",
                "format": "uri",
                "description": "Where the button leads."
              },
              "countAsConversion": {
                "default": true,
                "type": "boolean",
                "description": "Count a click on the button as a conversion of the campaign."
              }
            },
            "required": [
              "kind",
              "headline",
              "buttonLabel",
              "buttonHref"
            ],
            "title": "Call to action",
            "description": "A message with a button instead of a question."
          }
        ],
        "description": "What the campaign asks. `kind` selects one of five formats."
      },
      "Appearance": {
        "type": "object",
        "properties": {
          "position": {
            "default": "bottom_right",
            "type": "string",
            "enum": [
              "bottom_right",
              "bottom_left",
              "bottom_bar",
              "top_bar",
              "center_modal",
              "inline"
            ],
            "description": "Where the campaign appears. `inline` places it inside an element on your page."
          },
          "anchorSelector": {
            "type": "string",
            "maxLength": 200,
            "description": "CSS selector of the element to place the campaign in, for `inline`."
          },
          "theme": {
            "default": "auto",
            "type": "string",
            "enum": [
              "light",
              "dark",
              "auto"
            ],
            "description": "`auto` follows the visitor's light or dark mode."
          },
          "accentColor": {
            "default": "#0069a9",
            "type": "string",
            "pattern": "^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$",
            "description": "Color of buttons and highlights",
            "as hex.": null
          },
          "textColor": {
            "type": "string",
            "pattern": "^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$",
            "description": "Text color",
            "as hex.": null
          },
          "backgroundColor": {
            "type": "string",
            "pattern": "^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$",
            "description": "Background color",
            "as hex.": null
          },
          "cornerRadius": {
            "default": 14,
            "type": "integer",
            "minimum": 0,
            "maximum": 32,
            "description": "Corner radius in pixels."
          },
          "fontFamily": {
            "type": "string",
            "maxLength": 200,
            "description": "CSS font-family. Default is the font of your page."
          },
          "backdrop": {
            "default": false,
            "type": "boolean",
            "description": "Dim the page behind the campaign. Meant for `center_modal`."
          },
          "animation": {
            "default": "slide",
            "type": "string",
            "enum": [
              "slide",
              "fade",
              "none"
            ],
            "description": "How the campaign appears. Visitors who prefer reduced motion get no animation."
          },
          "showCloseButton": {
            "default": true,
            "type": "boolean",
            "description": "Show a close button. Closing counts as a dismissal."
          },
          "showBranding": {
            "default": true,
            "type": "boolean",
            "description": "Show a small Conversionloop note."
          },
          "customCss": {
            "type": "string",
            "maxLength": 4000,
            "description": "Extra CSS. It applies only inside the campaign (Shadow DOM)",
            "never to your page.": null
          }
        },
        "description": "How the campaign looks. Every field has a default, so `{}` is valid."
      },
      "Delivery": {
        "type": "object",
        "properties": {
          "delayMs": {
            "default": 0,
            "type": "integer",
            "minimum": 0,
            "maximum": 600000,
            "description": "Wait this long (milliseconds) after the audience matches before showing."
          },
          "priority": {
            "default": 50,
            "type": "integer",
            "minimum": 0,
            "maximum": 100,
            "description": "When several campaigns match at once",
            "the higher priority wins.": null
          },
          "frequency": {
            "default": {},
            "type": "object",
            "properties": {
              "maxImpressions": {
                "default": 1,
                "type": "integer",
                "minimum": 1,
                "maximum": 100,
                "description": "How often one visitor sees the campaign at most within `windowDays`."
              },
              "windowDays": {
                "default": 30,
                "type": "integer",
                "minimum": 0,
                "maximum": 365,
                "description": "Time window for `maxImpressions` in days. `0` means forever."
              },
              "hideAfterResponse": {
                "default": true,
                "type": "boolean",
                "description": "Never show again after the visitor answered."
              },
              "reshowAfterDismissDays": {
                "default": 0,
                "type": "integer",
                "minimum": 0,
                "maximum": 365,
                "description": "Show again this many days after the visitor closed it. `0` means never."
              }
            },
            "description": "Limits per visitor, stored on the visitor's device."
          },
          "trafficShare": {
            "default": 1,
            "type": "number",
            "minimum": 0,
            "maximum": 1,
            "description": "Share of matching visitors who see the campaign, 0 to 1. Use it to test on part of your traffic."
          }
        },
        "description": "When and how often the campaign shows. Every field has a default, so `{}` is valid."
      },
      "CampaignInput": {
        "type": "object",
        "required": [
          "name",
          "slug",
          "content",
          "appearance",
          "delivery"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200,
            "description": "Name shown in the dashboard."
          },
          "slug": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80,
            "pattern": "^[a-z0-9][a-z0-9-]*$",
            "description": "Unique within the project. Used by `conversionloop.trigger()` and the `campaign_state` audience condition."
          },
          "goal": {
            "type": "string",
            "maxLength": 1000,
            "description": "What you want to learn. For your team."
          },
          "audienceId": {
            "type": [
              "string",
              "null"
            ],
            "description": "The audience to show the campaign to. Required to go live."
          },
          "dataFieldKeys": {
            "type": "array",
            "maxItems": 50,
            "default": [],
            "items": {
              "type": "string"
            },
            "description": "Data fields this campaign relies on, by key. Unknown keys are rejected with `422`."
          },
          "content": {
            "$ref": "#/components/schemas/CampaignContent"
          },
          "appearance": {
            "$ref": "#/components/schemas/Appearance"
          },
          "delivery": {
            "$ref": "#/components/schemas/Delivery"
          },
          "startsAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Start for `scheduled` campaigns."
          },
          "endsAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "The campaign stops showing after this time."
          }
        }
      },
      "CampaignPatch": {
        "description": "Any fields of `CampaignInput`. Fields you leave out stay unchanged.",
        "allOf": [
          {
            "$ref": "#/components/schemas/CampaignInput"
          }
        ],
        "x-patch": true
      },
      "Campaign": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "ID, starting with `cmp_`."
          },
          "projectId": {
            "type": "string"
          },
          "workspaceId": {
            "type": "string"
          },
          "audienceId": {
            "type": [
              "string",
              "null"
            ]
          },
          "slug": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "goal": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "$ref": "#/components/schemas/CampaignStatus"
          },
          "content": {
            "$ref": "#/components/schemas/CampaignContent"
          },
          "appearance": {
            "$ref": "#/components/schemas/Appearance"
          },
          "delivery": {
            "$ref": "#/components/schemas/Delivery"
          },
          "dataFieldKeys": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "startsAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "endsAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  }
}