{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/sending-dev/json-schema/sending-dev-automation-stats-schema.json",
  "title": "AutomationStats",
  "x-generated": "2026-11-24",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/sending-dev-openapi.json#/components/schemas/AutomationStats",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "name": {
      "type": "string"
    },
    "status": {
      "type": "string"
    },
    "since": {
      "type": [
        "string",
        "null"
      ],
      "description": "Window applied to sent messages; null = all time."
    },
    "attribution": {
      "type": "string",
      "enum": [
        "first",
        "last"
      ]
    },
    "enrollments": {
      "type": "object",
      "properties": {
        "total": {
          "type": "integer"
        },
        "byStatus": {
          "type": "object",
          "additionalProperties": {
            "type": "integer"
          }
        }
      },
      "required": [
        "total",
        "byStatus"
      ],
      "description": "Real enrollments: test runs do not count in the funnel."
    },
    "metrics": {
      "type": "object",
      "properties": {
        "sent": {
          "type": "integer"
        },
        "delivered": {
          "type": "integer"
        },
        "emailDelivered": {
          "type": "integer"
        },
        "queued": {
          "type": "integer"
        },
        "failed": {
          "type": "integer"
        },
        "openedHuman": {
          "type": "integer"
        },
        "openedAny": {
          "type": "integer"
        },
        "machineOpens": {
          "type": "integer"
        },
        "clicked": {
          "type": "integer"
        },
        "contentClicks": {
          "type": "integer"
        },
        "hardBounces": {
          "type": "integer"
        },
        "softBounces": {
          "type": "integer"
        },
        "unsubscribed": {
          "type": "integer"
        },
        "complained": {
          "type": "integer"
        },
        "openRate": {
          "type": [
            "number",
            "null"
          ]
        },
        "clickRate": {
          "type": [
            "number",
            "null"
          ]
        },
        "contentClickRate": {
          "type": [
            "number",
            "null"
          ]
        },
        "clickToOpenRate": {
          "type": [
            "number",
            "null"
          ]
        },
        "unsubscribeRate": {
          "type": [
            "number",
            "null"
          ]
        },
        "bounceRate": {
          "type": [
            "number",
            "null"
          ]
        },
        "complaintRate": {
          "type": [
            "number",
            "null"
          ]
        },
        "deliveryRate": {
          "type": [
            "number",
            "null"
          ]
        },
        "readingEnvironment": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "label": {
                "type": "string"
              },
              "n": {
                "type": "integer"
              },
              "pct": {
                "type": "number"
              }
            },
            "required": [
              "label",
              "n",
              "pct"
            ]
          }
        },
        "topClients": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "client": {
                "type": "string"
              },
              "n": {
                "type": "integer"
              },
              "pct": {
                "type": "number"
              }
            },
            "required": [
              "client",
              "n",
              "pct"
            ]
          }
        }
      },
      "required": [
        "sent",
        "delivered",
        "emailDelivered",
        "queued",
        "failed",
        "openedHuman",
        "openedAny",
        "machineOpens",
        "clicked",
        "contentClicks",
        "hardBounces",
        "softBounces",
        "unsubscribed",
        "complained",
        "openRate",
        "clickRate",
        "contentClickRate",
        "clickToOpenRate",
        "unsubscribeRate",
        "bounceRate",
        "complaintRate",
        "deliveryRate",
        "readingEnvironment",
        "topClients"
      ],
      "description": "Email totals of the automation; environment and client from human opens only."
    },
    "nodes": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/AutomationStatsNode"
      }
    },
    "links": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/LinkStat"
      },
      "description": "The most clicked links across the whole automation."
    },
    "conversions": {
      "$ref": "#/$defs/EntityConversions"
    },
    "revenue": {
      "$ref": "#/$defs/RevenueReport"
    },
    "stuck": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "enrollmentId": {
            "type": "string",
            "format": "uuid"
          },
          "contactId": {
            "type": "string",
            "format": "uuid"
          },
          "nodeId": {
            "type": "string"
          },
          "nodeType": {
            "type": [
              "string",
              "null"
            ]
          },
          "since": {
            "type": "string"
          },
          "minutesStuck": {
            "type": "integer"
          }
        },
        "required": [
          "enrollmentId",
          "contactId",
          "nodeId",
          "nodeType",
          "since",
          "minutesStuck"
        ]
      },
      "description": "Enrollments stuck on a node that is not waiting for anything."
    },
    "lastTestRun": {
      "description": "Latest test run, with the outcome of every step."
    }
  },
  "required": [
    "id",
    "name",
    "status",
    "since",
    "attribution",
    "enrollments",
    "metrics",
    "nodes",
    "links",
    "conversions",
    "revenue",
    "stuck"
  ],
  "$defs": {
    "AutomationNodeEmailMetrics": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "subject": {
          "type": [
            "string",
            "null"
          ]
        },
        "sent": {
          "type": "integer"
        },
        "delivered": {
          "type": "integer"
        },
        "emailDelivered": {
          "type": "integer"
        },
        "queued": {
          "type": "integer"
        },
        "failed": {
          "type": "integer"
        },
        "openedHuman": {
          "type": "integer"
        },
        "openedAny": {
          "type": "integer"
        },
        "machineOpens": {
          "type": "integer"
        },
        "clicked": {
          "type": "integer"
        },
        "contentClicks": {
          "type": "integer"
        },
        "hardBounces": {
          "type": "integer"
        },
        "softBounces": {
          "type": "integer"
        },
        "unsubscribed": {
          "type": "integer"
        },
        "complained": {
          "type": "integer"
        },
        "openRate": {
          "type": [
            "number",
            "null"
          ]
        },
        "clickRate": {
          "type": [
            "number",
            "null"
          ]
        },
        "contentClickRate": {
          "type": [
            "number",
            "null"
          ]
        },
        "clickToOpenRate": {
          "type": [
            "number",
            "null"
          ]
        },
        "unsubscribeRate": {
          "type": [
            "number",
            "null"
          ]
        },
        "bounceRate": {
          "type": [
            "number",
            "null"
          ]
        },
        "complaintRate": {
          "type": [
            "number",
            "null"
          ]
        }
      },
      "required": [
        "subject",
        "sent",
        "delivered",
        "emailDelivered",
        "queued",
        "failed",
        "openedHuman",
        "openedAny",
        "machineOpens",
        "clicked",
        "contentClicks",
        "hardBounces",
        "softBounces",
        "unsubscribed",
        "complained",
        "openRate",
        "clickRate",
        "contentClickRate",
        "clickToOpenRate",
        "unsubscribeRate",
        "bounceRate",
        "complaintRate"
      ],
      "description": "Only for nodes that sent at least one message."
    },
    "AutomationStatsNode": {
      "type": "object",
      "properties": {
        "nodeId": {
          "type": "string"
        },
        "nodeType": {
          "type": "string"
        },
        "done": {
          "type": "integer"
        },
        "skipped": {
          "type": "integer"
        },
        "failed": {
          "type": "integer"
        },
        "metrics": {
          "$ref": "#/$defs/AutomationNodeEmailMetrics"
        },
        "links": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/LinkStat"
          },
          "description": "The 5 most clicked links in the node's message, with role."
        },
        "conversions": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "conversions": {
              "type": "integer"
            },
            "contacts": {
              "type": "integer"
            },
            "revenueCents": {
              "type": "integer"
            }
          },
          "required": [
            "conversions",
            "contacts",
            "revenueCents"
          ],
          "description": "Conversions attributed to a click on this node."
        },
        "revenue": {
          "allOf": [
            {
              "$ref": "#/$defs/RevenueSummary"
            },
            {
              "type": [
                "object",
                "null"
              ],
              "description": "Orders attributed to this node's messages; only for nodes that sent. The rule is in the top-level `revenue.attribution`."
            }
          ]
        }
      },
      "required": [
        "nodeId",
        "nodeType",
        "done",
        "skipped",
        "failed",
        "metrics",
        "links",
        "conversions",
        "revenue"
      ]
    },
    "ConversionRow": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "name": {
          "type": "string"
        },
        "source": {
          "type": "string"
        },
        "valueCents": {
          "type": "integer"
        },
        "currency": {
          "type": "string"
        },
        "occurredAt": {
          "type": "string",
          "format": "date-time"
        },
        "contactId": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid"
        },
        "contactEmail": {
          "type": [
            "string",
            "null"
          ]
        },
        "touchUrl": {
          "type": [
            "string",
            "null"
          ],
          "description": "Clicked link (canonical) it is attributed to."
        },
        "touchAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "nodeId": {
          "type": [
            "string",
            "null"
          ]
        },
        "secondsFromTouch": {
          "type": [
            "integer",
            "null"
          ]
        }
      },
      "required": [
        "id",
        "name",
        "source",
        "valueCents",
        "currency",
        "occurredAt",
        "contactId",
        "contactEmail",
        "touchUrl",
        "touchAt",
        "nodeId",
        "secondsFromTouch"
      ]
    },
    "EntityConversions": {
      "type": "object",
      "properties": {
        "attribution": {
          "type": "string",
          "enum": [
            "first",
            "last"
          ]
        },
        "lookbackDays": {
          "type": "integer"
        },
        "total": {
          "type": "integer"
        },
        "contacts": {
          "type": "integer"
        },
        "revenueCents": {
          "type": "integer"
        },
        "currency": {
          "type": [
            "string",
            "null"
          ],
          "description": "`null` with mixed currencies: the total cannot be summed."
        },
        "byName": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "conversions": {
                "type": "integer"
              },
              "revenueCents": {
                "type": "integer"
              }
            },
            "required": [
              "name",
              "conversions",
              "revenueCents"
            ]
          }
        },
        "byLink": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "url": {
                "type": "string"
              },
              "conversions": {
                "type": "integer"
              },
              "contacts": {
                "type": "integer"
              },
              "revenueCents": {
                "type": "integer"
              }
            },
            "required": [
              "url",
              "conversions",
              "contacts",
              "revenueCents"
            ]
          }
        },
        "recent": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/ConversionRow"
          },
          "description": "The latest 50."
        }
      },
      "required": [
        "attribution",
        "lookbackDays",
        "total",
        "contacts",
        "revenueCents",
        "currency",
        "byName",
        "byLink",
        "recent"
      ]
    },
    "LinkStat": {
      "type": "object",
      "properties": {
        "url": {
          "type": "string",
          "description": "The most clicked raw variant, the recognizable one."
        },
        "canonicalUrl": {
          "type": "string"
        },
        "role": {
          "type": [
            "string",
            "null"
          ],
          "description": "logo | image | cta | text | social | video | chrome, or null if not classified."
        },
        "isContent": {
          "type": "boolean"
        },
        "uniqueClicks": {
          "type": "integer",
          "description": "Distinct messages with a human click."
        },
        "totalClicks": {
          "type": "integer"
        },
        "machineClicks": {
          "type": "integer",
          "description": "Scanner and proxy clicks: reported, not counted."
        },
        "firstClickAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "lastClickAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "share": {
          "type": [
            "number",
            "null"
          ],
          "description": "Share 0-100 of the scope's unique human clicks."
        }
      },
      "required": [
        "url",
        "canonicalUrl",
        "role",
        "isContent",
        "uniqueClicks",
        "totalClicks",
        "machineClicks",
        "firstClickAt",
        "lastClickAt",
        "share"
      ]
    },
    "RevenueReport": {
      "allOf": [
        {
          "$ref": "#/$defs/RevenueSummary"
        },
        {
          "type": "object",
          "properties": {
            "attribution": {
              "type": "object",
              "properties": {
                "model": {
                  "type": "string",
                  "enum": [
                    "last_content_click"
                  ]
                },
                "windowDays": {
                  "type": "integer",
                  "description": "Workspace attribution window: the last content click within these days before the order."
                }
              },
              "required": [
                "model",
                "windowDays"
              ]
            }
          },
          "required": [
            "attribution"
          ]
        }
      ],
      "description": "Store and API orders attributed to the messages: the last click on the content (not the logo, never an open) within `attribution.windowDays` days before the order. Test runs and cancelled orders excluded."
    },
    "RevenueSummary": {
      "type": "object",
      "properties": {
        "orders": {
          "type": "integer",
          "description": "Attributed orders, cancelled excluded. A count across all currencies."
        },
        "revenue": {
          "type": [
            "number",
            "null"
          ],
          "description": "Gross total of the attributed orders; `null` with more than one currency (never summed)."
        },
        "refunded": {
          "type": [
            "number",
            "null"
          ],
          "description": "Refunds on those orders, declared apart and never subtracted from `revenue`."
        },
        "currency": {
          "type": [
            "string",
            "null"
          ],
          "description": "The only currency involved; `null` with zero orders or more than one currency."
        },
        "averageOrderValue": {
          "type": [
            "number",
            "null"
          ]
        },
        "revenuePerRecipient": {
          "type": [
            "number",
            "null"
          ],
          "description": "`revenue` / `delivered`; `null` with no orders, no deliveries or more than one currency."
        },
        "byCurrency": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "currency": {
                "type": "string"
              },
              "revenue": {
                "type": "number"
              },
              "refunded": {
                "type": "number"
              },
              "orders": {
                "type": "integer"
              },
              "averageOrderValue": {
                "type": [
                  "number",
                  "null"
                ]
              }
            },
            "required": [
              "currency",
              "revenue",
              "refunded",
              "orders",
              "averageOrderValue"
            ]
          },
          "description": "One row per currency, highest revenue first: the numbers to read when there is more than one."
        }
      },
      "required": [
        "orders",
        "revenue",
        "refunded",
        "currency",
        "averageOrderValue",
        "revenuePerRecipient",
        "byCurrency"
      ]
    }
  }
}