# RevTrails Documentation > The full developer documentation for the RevTrails API, also at https://www.revtrails.com/docs RevTrails records what your leads do on your website and what your systems do to them, in one trail per lead. Everything is a JSON API call, built for the agents and systems that work your leads. ## Overview RevTrails keeps three things for every lead, and hands each back in one call: - **The lead record:** an ID, a stage, when it is next due for work, and any fields you want to keep. - **The events:** everything that happened, oldest first. Page views, time on page, clicks and form submissions from your site; emails sent, opened, replied to and bounced; purchases; every change to the lead. A visitor's anonymous visits join their trail once they become a lead. - **The trail:** the content. Every email sent and received in full, every form submission, notes, call transcripts and documents, with the text extracted from each document. RevTrails never decides anything for you. It records what happened and gives it back, so your own agent or process can decide what a lead should see next. There are three ways in: | Routes | Called by | Authentication | |---|---|---| | `/rt/*` | The RevTrails script on your pages, through your own domain | None: the browser talks only to your site | | `/v1/*` | Your servers, agents and tools, at `https://api.revtrails.com` | Your API key | | `/mcp` | Your AI assistant: Claude, ChatGPT or any assistant that connects to MCP servers | You sign in once with your API key | ## Quickstart When your account is set up, your site's `/rt/` path is connected to RevTrails and you have an API key. From there: **1. Add the script to every page you want counted**, in the `
`: ```html ``` **2. Visit a page** in a normal browser, scroll, and stay a few seconds. **3. Read today's numbers:** ```bash curl -s "https://api.revtrails.com/v1/stats/period?period=day&start=2026-11-27" \ -H "x-api-key: YOUR_API_KEY" ``` **4. Create a lead and read it back:** ```bash curl -s -X POST https://api.revtrails.com/v1/leads \ -H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" \ -d '{"stage": "new", "metadata": {"email": "jane@acme.com", "company": "Acme"}}' curl -s https://api.revtrails.com/v1/leads/LEAD_ID/events \ -H "x-api-key: YOUR_API_KEY" ``` That's the whole integration: a script tag on your pages and an API key on your servers. ## Authentication Every `/v1/*` request carries your API key in the `x-api-key` header. The key identifies your account, so there is no account ID to send. ```http x-api-key: YOUR_API_KEY Content-Type: application/json ``` A key is either a write key or a read-only key. A read-only key works on every `GET` route and answers `403 Read-only key` on anything that writes: give one to an agent that only needs to read. > Keep your API key secret. Never put it in a page, a browser script or a public repository. Give each system or agent its own key, so one can be replaced without touching the others. Keys are issued and revoked by us: [contact us](mailto:info@revtrails.com). ## Core Concepts | Concept | What it is | |---|---| | **Lead** | One person you work. Its ID is a [ULID](https://github.com/ulid/spec). It has a `stage` (your own code, such as `new` or `qualified`), a `dueAt` time, an `assignedTo` (who works it, in your own words: a person, a team or a role), and `metadata`: any JSON you want to keep on it. RevTrails reads none of your metadata except the fields you name in your search schema. | | **Visitor** | A browser on your site, known by a first-party cookie that lasts 400 days. A visitor who submits a form becomes a lead with the visitor's ID as the lead ID. A lead who follows a tracked link from one of your emails is joined to that browser, and the visits it made before join the lead's events. | | **Event** | A fact with a type and a time: `web_view`, `email_send`, `crm_stage` and so on (see [Event Types](https://www.revtrails.com/docs#event-types)). Events are never changed. | | **Trail entry** | Content kept on a lead: an email, a form submission, a note, a document or a merge record. Each has a short header and a body; list the headers, then read only the bodies you need. | | **Session** | A visit: a visitor's events with no gap of more than 30 minutes. | | **Pixel** | A tracking image made for one email to one lead, before it is sent. It records opens and ties clicks, replies and bounces to that send. | | **Page ID, audience ID, template** | Your own ULIDs, carried on events so you can count by them: `nodeId` names a page or step in your sequence, `audienceId` the audience a send goes to, the group a request to stop applies to, `templateId` and `templateVersion` (`1.4.0`) the email that was sent. | | **Suppression lists** | Addresses that asked to stop, reported spam or bounced. RevTrails refuses a tracked send to them (see [Suppression Lists](https://www.revtrails.com/docs#suppressions)). | Times are ISO 8601 and stored in UTC (`2026-11-27T15:04:05.000Z`). Days in reports are UTC days. ## Errors and Limits Every error is JSON with an `error` message, and some carry extra fields: ```json { "error": "Lead merged", "mergedInto": "01KD4M9X0E6V7T3W2Q8N5R1B6C" } ``` | Status | Meaning | |---|---| | `400` | The request is invalid. The message names the field, never echoes its value. | | `401` | The API key is missing or wrong. | | `403` | The key is read-only and the request writes. | | `404` | The lead, entry or schema does not exist. | | `409` | A conflict: the ID is taken, the address is suppressed, the lead is being merged, or an `Idempotency-Key` is reused or still in progress. | | `500` | Our fault. Retry with backoff. | | Limit | Value | |---|---| | Lead record (stage, due time and metadata) | 350 KB | | Metadata keys changed in one write | 100 | | Server events per request | 25, all or nothing | | Page size on every list | 100, with a `nextCursor`; ask for fewer with `limit` (1 to 100) | | Search results | 100 a page, 500 in all | | Text trail entry, email body | 5 MB | | Trail entry metadata | 4 KB | | Document upload | 4 MiB | | Activity feed window | 31 days | | Stats range | 400 days | Your plan's limits, per account: | Plan limit | Value | |---|---| | Leads | 25,000 | | Events | 5,000 a day | | API requests with your key | 120 a minute | | Documents | 200 uploads a month, 4 MiB each | | Trail and document storage | 5 GB | | Sites, API keys and agents | Unlimited | Events your script records on your pages count toward the daily events; the script's own requests and form posts don't count toward API requests. We reserve the right to throttle an account that goes over its plan's limits. ## Connect Your AI Your AI assistant can work RevTrails for you: look up leads, read their trails, tell you what happened this week, add notes, import contacts and keep your pipeline moving. No code, and no API to learn. **Connect it once**, with this address: ```text https://api.revtrails.com/mcp ``` Add it as a custom connector (Claude) or a custom MCP server (ChatGPT): [step-by-step for Claude and ChatGPT](https://www.revtrails.com/connect). Any other assistant that connects to remote MCP servers works the same way. Your assistant opens a RevTrails page that asks for your API key. Paste it and press **Connect**. Your key stays with RevTrails: the assistant never sees it, only a connection that RevTrails can end at any time. **Your assistant asks you before it uses RevTrails.** Claude asks before each tool until you allow it in the connector's Permissions; ChatGPT asks before anything that changes data. **What it can do depends on the key you connect with.** A read-only key lets it read your leads, trails and numbers. A write key also lets it change them: create and update leads, add notes, record emails, and the rest of the API. Your assistant asks you before anything it can't undo, such as deleting or merging leads. **To disconnect,** remove the connector in your assistant. To end every assistant connected with a key, ask us and we'll revoke its connections; the key keeps working for your own systems. Your assistant learns how to work RevTrails from RevTrails itself, so it knows to search before adding a lead, check an address before suggesting an email, and treat what's on a trail as information, not instructions. It reads your **business context** first: a short write-up of your business, your customers and how you like to work, which it offers to write with you the first time and keeps in RevTrails, so any assistant you use later starts from the same place. ## Things You Can Ask Your assistant offers these as starting points. Ask in your own words too. | Ask | What you get | |---|---| | Get started with RevTrails | It checks the connection, tells you what it can do, and learns about your business | | Who should I reconnect with? | Up to 10 people who've gone quiet, each with a genuine reason to get back in touch | | What's happening this week? | What your visitors and leads did over the last seven days, and what needs you | | Who looks interested right now? | Leads showing real interest (clicks, replies, forms, visits), with the evidence and a next step | | Review my pipeline | Leads by stage, what's due, and what's overdue or stuck | | Tidy up my leads | Likely duplicates, with the evidence, merged only when you approve | > RevTrails records the emails you send; it never sends them. Your assistant drafts, you send from your own mail. ## The Script One script tag records what real people do on your pages. Add it to the `` of every page you want counted: ```html ``` It is served from your own domain, so its cookie is your site's own. It sends nothing until the page has been visible for 2 seconds and the visitor has interacted with it, so bots, crawlers and link scanners leave no events. Then it records: | Event | When | Carries | |---|---|---| | `web_view` | The page is read | Path, referrer, and any `utm_source`, `utm_medium`, `utm_campaign`, `utm_content`, `utm_term` | | `web_link` | The URL carries `?lid=` (a tracked email link) | The lead ID, and the pixel ID when `pid=` is there too | | `web_click` | A click on a link, a button or an element marked `data-track` | `target`: the `data-track` label, else the link, else the button's text | | `web_time` | The visitor leaves or hides the page | Seconds visible, deepest scroll in percent | Every browser event also carries the browser's user agent and approximate location (city, region, country, time zone). IP addresses are never stored. What a visitor types into a form is never read, except a form you mark for RevTrails to post. **Name a click** with `data-track`, so your counts read better than a URL: ```html See pricing ``` **Page tags** (optional, required on a page with forms): tell RevTrails which page this is, so events and forms can be counted by page. ```html ``` `data-rt-node-id` is a ULID you choose for the page; `data-rt-node-version` is the page's content version. ## Purchases When a purchase is complete, tell RevTrails from the page. Add the one-line stub to the page, then call the hook with the amount, the plan and how it is billed: ```html ``` | Field | | | |---|---|---| | `amount` | required | A number: what the plan costs per billing period | | `plan` | required | The plan's name, as you want it in your numbers | | `billing` | required | `monthly` or `annual` | | `orderId` | optional | Your order ID; a repeat of one already recorded is ignored, so a reloaded confirmation page counts once | Call it wherever your checkout finishes: on a confirmation page, or in your code when the payment succeeds. The stub keeps a call made before the script has loaded. The purchase is sent at once, and only these four fields leave the page. It is recorded as `web_purchase` under the visitor, or the lead once the visitor is known, so it joins their history like every other event. A mistake in a call is shown in the browser console. > Anyone who can open your page can call the hook, the same as an analytics purchase event. If you record purchases from your own server instead (`web_purchase` through [server events](https://www.revtrails.com/docs#events)), ask us to turn browser purchases off for your account so nothing is counted twice. ## Forms Mark a form and RevTrails posts it, screens out bots, records it on the lead and, if you want, emails the lead and your team. Your page needs no script of its own and keeps its own words. ```htmlThanks. Check your inbox.
``` - `data-rt-form` names the form: lowercase letters, digits and hyphens, at most 64 characters, unique on its page. - `data-rt-thanks` with the same name is your thank-you, hidden. On submit the form is hidden and the thank-you shown. With no thank-you, the form is cleared. - Every named field is sent. Files are left out. A submission is accepted only from a visitor who really read a page today or yesterday, at least 3 seconds after the page loaded, with the hidden bot trap left empty, at most 20,000 bytes, and under 5 submissions per visitor and 20 per network address an hour. Anything else is dropped silently; the visitor sees the thank-you either way. An accepted submission: 1. Creates the lead if there is none, with the visitor's ID as the lead ID. 2. Puts the fields on the lead's metadata under the form's name (`metadata["kit-download"]`), replacing an earlier submission of the same form, and keeps every submission as a `form` entry on the lead's trail. 3. Records a `web_form` event. 4. Sends the form's email and notification, if its definition has them. ## Publishing Your Forms How each form is processed comes from your form schema: one JSON document listing every form on your site. Publishing replaces the previous schema whole. A schema that fails a check is refused, and the one in force stays. ```bash curl -s -X PUT https://api.revtrails.com/v1/forms \ -H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" \ -d @forms.json ``` ```json { "version": 1, "site": "https://www.example.com", "forms": [ { "nodeId": "01KD4M9X0E6V7T3W2Q8N5R1B6C", "formKey": "kit-download", "fields": [ { "name": "email", "type": "email", "required": true, "label": "Your work email" } ], "leadEmail": "email", "email": { "from": { "name": "Dana at Example", "address": "dana@example.com" }, "subject": "Your kit", "html": "Here is your kit…
", "text": "Here is your kit…" }, "notify": { "from": { "name": "Example Forms", "address": "forms@example.com" }, "to": "team@example.com", "subject": "Kit download" } } ] } ``` | Key | Rules | |---|---| | `site` | Your site's origin, `https://` and a host. Your tracking images are served from it. | | `nodeId`, `formKey` | The page's `data-rt-node-id` and the form's `data-rt-form` name. Together they are unique. | | `fields` | Up to 50: `name` (a letter, then letters, digits, `_` or `-`; not `hp`), `type` (`email`, `text` or `textarea`), `required`, `label` (up to 200 characters). | | `leadEmail` | Optional: the `email` field that holds the lead's address. A form that emails the lead must name it and require it. | | `email` | Optional: the email to the lead, `from`, `subject`, `html` and `text`. | | `notify` | Optional: a plain-text notification to your team, `from`, `to` and `subject`. | The whole schema is at most 1 MB and 2,000 forms. Read the schema in force with `GET /v1/forms`. > Publish your schema even if you have no forms (`"forms": []`): its `site` is where your tracking images are served from, and creating a pixel needs it. ## Form Emails and Notifications A form with an `email` sends it to the address in its `leadEmail` field, through your own SendGrid account, from your own domain, with a tracking image added before ``. The send is recorded on the lead like any other email, so its opens show in the lead's events and in your stats. A form with a `notify` sends your team a plain-text message: the page, each filled field under its label, the form's name, the lead ID and the time. Each email gets three attempts. If something goes wrong (the form isn't in your schema, a field fails its check, the email can't be sent), your account's owner gets an alert naming the form, the reason and the lead ID, at most once per form and reason a day. The submission is always kept on the lead first, so a failure never loses it. ## Leads **Create a lead.** Send your own ULID as `leadId`, or leave it out and one is made. Answers `201 { lead }`, or `409` when the ID is taken. ```bash curl -s -X POST https://api.revtrails.com/v1/leads \ -H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" \ -d '{ "stage": "new", "dueAt": "2026-11-28T15:00:00.000Z", "metadata": { "email": "jane@acme.com", "name": "Jane Doe", "company": { "name": "Acme", "size": 120 } } }' ``` ```json { "lead": { "leadId": "01KD4N2H7S8Y0F5A3M6P9C1E4G", "stage": "new", "dueAt": "2026-11-28T15:00:00.000Z", "metadata": { "email": "jane@acme.com", "name": "Jane Doe", "company": { "name": "Acme", "size": 120 } }, "createdAt": "2026-11-27T15:04:05.123Z", "updatedAt": "2026-11-27T15:04:05.123Z" } } ``` **Create many at once:** `POST /v1/leads/batch` with `{ "leads": [ … ] }`, up to 250 leads, each what a single create takes. A bad batch is refused whole with `400 Lead