{
    "openapi": "3.1.0",
    "info": {
        "title": "trackr.link API",
        "version": "1.0.0",
        "summary": "Report payments to trackr.link, send analytics events to it, and post website forms to it.",
        "description": "The Payments API attributes payments from any provider to the visit that led to them, with a site's API token. The collect endpoint records the pageviews, custom events and engagement the tracking script sends. The form endpoint stores what a website's form sends as a lead, emails it to the form's recipients and credits it to the visit that led to it. Coding agents set up sites, goals, funnels and forms over the MCP server at https://app.trackr.link/mcp instead, which this document does not describe.",
        "termsOfService": "https://trackr.link/terms",
        "contact": {
            "name": "trackr.link support",
            "url": "https://trackr.link/contact",
            "email": "support@trackr.link"
        }
    },
    "externalDocs": {
        "description": "trackr.link API reference",
        "url": "https://trackr.link/docs/api"
    },
    "servers": [
        {
            "url": "https://app.trackr.link",
            "description": "trackr.link"
        }
    ],
    "tags": [
        {
            "name": "Payments",
            "description": "Attribute revenue to visits."
        },
        {
            "name": "Tracking",
            "description": "Record pageviews, custom events and engagement."
        },
        {
            "name": "Forms",
            "description": "Receive a website's form submissions as leads."
        }
    ],
    "paths": {
        "/api/payments": {
            "post": {
                "operationId": "recordPayment",
                "tags": [
                    "Payments"
                ],
                "summary": "Record a payment or a refund",
                "description": "Report a payment from any provider. It counts toward the visitor's latest visit in the 24 hours before the payment, so revenue shows per channel, source and campaign. Send the visitor_id the tracking script exposes as window.trackr.visitor to match the payment to its visit. A repeated transaction_id is recorded once, so a retry is safe.",
                "security": [
                    {
                        "siteApiToken": []
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/PaymentRequest"
                            },
                            "example": {
                                "transaction_id": "order_1001",
                                "amount": 49,
                                "currency": "USD",
                                "visitor_id": "9f86d081884c7d659a2feaa0c55ad015"
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "The payment was recorded.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/PaymentRecorded"
                                }
                            }
                        }
                    },
                    "200": {
                        "description": "The transaction was recorded before, or the site is not recording, in which case id and matched_by are null.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/PaymentRecorded"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The bearer token is missing or belongs to no site.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "A field is missing or invalid.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/ValidationError"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/api/collect": {
            "post": {
                "operationId": "collectEvent",
                "tags": [
                    "Tracking"
                ],
                "summary": "Record a pageview, a custom event or engagement time",
                "description": "The endpoint the tracking script sends each hit to. It needs no token: the Origin header, or the Referer header, must be on one of the site's domains. Every hit that passes validation is answered with 202, whether it was stored or dropped, for example as a bot or past the plan's monthly events. The body is JSON, sent as text/plain by the script so the browser sends no preflight request. It may be at most 8 KB.",
                "security": [],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/CollectRequest"
                            },
                            "example": {
                                "s": "abcd1234",
                                "e": "event",
                                "p": "/pricing",
                                "n": "Signup",
                                "d": {
                                    "plan": "free"
                                }
                            }
                        },
                        "text/plain": {
                            "schema": {
                                "$ref": "#/components/schemas/CollectRequest"
                            }
                        }
                    }
                },
                "responses": {
                    "202": {
                        "description": "The hit was accepted. A recorded pageview answers with the visitor id; every other hit has an empty body.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/CollectAccepted"
                                }
                            }
                        }
                    },
                    "413": {
                        "description": "The body is larger than 8 KB."
                    },
                    "422": {
                        "description": "A field is missing or invalid.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/ValidationError"
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "The site sent more than 600 hits in a minute.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/f/{formId}": {
            "servers": [
                {
                    "url": "https://forms.trackr.link",
                    "description": "The forms host"
                }
            ],
            "post": {
                "operationId": "submitForm",
                "tags": [
                    "Forms"
                ],
                "summary": "Send a form submission",
                "description": "The endpoint a website posts its form to, from a plain HTML form, from JavaScript or from a server. It needs no token, sets no cookies and answers any origin. Every field is stored under its own name, in the order sent. A request that accepts application/json gets JSON. Any other gets a 303 redirect, or a page with the status of a refusal. A post whose Origin or Referer is not on the site's domains, or from a bot's user agent, is stored as spam unless the form accepts any domain, and gets the answer of a delivered lead. A visitor can send a form 10 times a minute.",
                "security": [],
                "parameters": [
                    {
                        "name": "formId",
                        "in": "path",
                        "required": true,
                        "description": "The form's id, the last part of its endpoint URL in trackr.link.",
                        "schema": {
                            "type": "string",
                            "pattern": "^[A-Za-z0-9]+$"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/x-www-form-urlencoded": {
                            "schema": {
                                "$ref": "#/components/schemas/FormSubmission"
                            }
                        },
                        "multipart/form-data": {
                            "schema": {
                                "$ref": "#/components/schemas/FormSubmission"
                            }
                        },
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/FormSubmission"
                            },
                            "example": {
                                "name": "Ada Lovelace",
                                "email": "ada@example.com",
                                "message": "Hello"
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "The submission was stored as a lead, held at the plan's lead limit or flagged as spam, or the honeypot dropped it. Each gets the same answer. Only a request that accepts application/json gets it.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/FormAccepted"
                                }
                            }
                        }
                    },
                    "303": {
                        "description": "The answer to a request that does not accept application/json, such as a plain HTML form, when the submission was received. It sends the browser to the form's redirect URL, or to the hosted thank-you page.",
                        "headers": {
                            "Location": {
                                "description": "The form's redirect URL, or the hosted thank-you page.",
                                "schema": {
                                    "type": "string",
                                    "format": "uri"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The form is disabled, or its site's recording is stopped.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/FormRefused"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No form has the id, or the form is deleted."
                    },
                    "422": {
                        "description": "The submission has more than 50 fields, a value over 10,000 characters, or more than 100 KB in all. No field the form stores has a value. The form uses Turnstile, and Cloudflare did not verify the response, there is none, or Cloudflare could not be reached.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/FormRefused"
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "The visitor sent the form 10 times in the last minute.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/FormRefused"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "securitySchemes": {
            "siteApiToken": {
                "type": "http",
                "scheme": "bearer",
                "description": "The API token of one site, created on the site's Revenue settings in trackr.link. It reports payments for that site only."
            }
        },
        "schemas": {
            "PaymentRequest": {
                "type": "object",
                "properties": {
                    "transaction_id": {
                        "type": "string",
                        "maxLength": 255,
                        "description": "Your provider's id for the payment. A repeated id is recorded once."
                    },
                    "amount": {
                        "type": "number",
                        "exclusiveMinimum": 0,
                        "maximum": 999999999999999,
                        "description": "The amount in the currency's main unit, such as 49.00, with up to 4 decimals."
                    },
                    "currency": {
                        "type": "string",
                        "pattern": "^[A-Za-z]{3}$",
                        "description": "The ISO 4217 currency code, such as USD."
                    },
                    "occurred_at": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "format": "date-time",
                        "description": "When the payment happened. Defaults to now."
                    },
                    "visitor_id": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "pattern": "^[0-9a-fA-F]{32}$",
                        "description": "The visitor id the tracking script exposes as window.trackr.visitor. Without it the payment is recorded but matched to no visit."
                    },
                    "email": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "format": "email",
                        "maxLength": 255,
                        "description": "The payer's email address."
                    },
                    "refund": {
                        "type": "boolean",
                        "default": false,
                        "description": "Whether the transaction is a refund."
                    }
                },
                "required": [
                    "transaction_id",
                    "amount",
                    "currency"
                ],
                "additionalProperties": false
            },
            "PaymentRecorded": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": [
                            "integer",
                            "null"
                        ],
                        "description": "The payment's id in trackr.link, or null when the site is not recording."
                    },
                    "matched_by": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "enum": [
                            "api",
                            "unmatched",
                            null
                        ],
                        "description": "How the payment was matched to a visit: api when its visitor_id matched one, unmatched when it matched none."
                    }
                },
                "required": [
                    "id",
                    "matched_by"
                ]
            },
            "CollectRequest": {
                "type": "object",
                "properties": {
                    "s": {
                        "type": "string",
                        "description": "The site id, the data-site value of the site's snippet."
                    },
                    "e": {
                        "type": "string",
                        "enum": [
                            "pageview",
                            "event",
                            "engagement"
                        ],
                        "description": "The kind of hit."
                    },
                    "p": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "The page path. A query string or fragment is dropped."
                    },
                    "h": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "The page's hostname. Defaults to the Origin header's host."
                    },
                    "r": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "The referrer URL."
                    },
                    "q": {
                        "type": [
                            "object",
                            "null"
                        ],
                        "additionalProperties": {
                            "type": "string"
                        },
                        "description": "The page's campaign parameters, such as utm_source, ref and click ids, keyed by name."
                    },
                    "sw": {
                        "type": [
                            "integer",
                            "null"
                        ],
                        "description": "The screen width in pixels."
                    },
                    "l": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "The browser language, such as en-US."
                    },
                    "n": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "The custom event's name. Required when e is event."
                    },
                    "d": {
                        "type": [
                            "object",
                            "null"
                        ],
                        "additionalProperties": {
                            "type": [
                                "string",
                                "number",
                                "boolean"
                            ]
                        },
                        "description": "The custom event's properties. The first 10 are kept."
                    },
                    "v": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": "The engaged seconds. Required when e is engagement."
                    },
                    "w": {
                        "type": [
                            "boolean",
                            "integer",
                            "null"
                        ],
                        "enum": [
                            true,
                            false,
                            1,
                            0,
                            null
                        ],
                        "description": "Whether the browser is driven by automation, from navigator.webdriver, as true or 1. Such hits count as bots."
                    }
                },
                "required": [
                    "s",
                    "e"
                ]
            },
            "FormSubmission": {
                "type": "object",
                "description": "Any fields, each stored under its own name in the order sent. A list of values, such as a group of checkboxes, is stored as one field with its values joined by commas. A submission may hold up to 50 fields, 10,000 characters in a value and 100 KB in all, counted over the fields that are stored. Uploaded files are ignored, and so is the query string.",
                "properties": {
                    "email": {
                        "type": "string",
                        "description": "Matched without regard to case. When it is a valid email address, it is the reply-to of the email to the form's recipients and finds the person's leads."
                    },
                    "name": {
                        "type": "string",
                        "description": "Matched without regard to case. It labels the lead in the inbox and in the subject of the email."
                    },
                    "_gotcha": {
                        "type": "string",
                        "description": "The honeypot, which a person leaves empty. A submission with a value in it is dropped and gets the answer of a delivered lead. Like every field whose name starts with _, it is not stored."
                    },
                    "cf-turnstile-response": {
                        "type": "string",
                        "description": "The response of the Cloudflare Turnstile widget, which a form that uses Turnstile requires. It is not stored."
                    }
                },
                "additionalProperties": {
                    "type": [
                        "string",
                        "number",
                        "boolean",
                        "null",
                        "array"
                    ],
                    "items": {
                        "type": [
                            "string",
                            "number",
                            "boolean",
                            "null"
                        ]
                    },
                    "description": "Any other field. Its name and value are stored as sent."
                }
            },
            "FormAccepted": {
                "type": "object",
                "properties": {
                    "ok": {
                        "type": "boolean",
                        "const": true,
                        "description": "The submission was received."
                    }
                },
                "required": [
                    "ok"
                ]
            },
            "FormRefused": {
                "type": "object",
                "properties": {
                    "ok": {
                        "type": "boolean",
                        "const": false,
                        "description": "The submission was refused, and nothing was stored."
                    },
                    "error": {
                        "type": "string",
                        "description": "Why, and what to do next, written for the person who sent the form."
                    }
                },
                "required": [
                    "ok",
                    "error"
                ]
            },
            "CollectAccepted": {
                "type": "object",
                "description": "Answered to a recorded pageview. Every other hit is answered with an empty body.",
                "properties": {
                    "v": {
                        "type": "string",
                        "pattern": "^[0-9a-f]{32}$",
                        "description": "The visitor id for today, which the tracking script exposes as window.trackr.visitor."
                    }
                },
                "required": [
                    "v"
                ]
            },
            "Error": {
                "type": "object",
                "properties": {
                    "message": {
                        "type": "string",
                        "description": "What went wrong."
                    }
                },
                "required": [
                    "message"
                ]
            },
            "ValidationError": {
                "type": "object",
                "properties": {
                    "message": {
                        "type": "string",
                        "description": "The first error, and how many more there are."
                    },
                    "errors": {
                        "type": "object",
                        "description": "The errors of each field that failed, keyed by the field.",
                        "additionalProperties": {
                            "type": "array",
                            "items": {
                                "type": "string"
                            }
                        }
                    }
                },
                "required": [
                    "message",
                    "errors"
                ]
            }
        }
    }
}