Sites API
Add, change and remove sites, goals and chart notes from your own code, for agencies and platforms with many sites.
The Sites API sets up tracking from your own code. It suits agencies and platforms that add a site for every new customer, and deploy scripts that leave a note on the chart when a release goes out. It needs a key with the Manage sites permission (sites:write); see API keys.
A key with only this permission can read sites, goals and notes, but not stats. Add Read stats to the same key if it needs both.
Add a site
POST https://api.traffic.cx/v1/sites
bash
curl -X POST https://api.traffic.cx/v1/sites \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "domain": "shop.example.com", "name": "Example shop", "timezone": "Europe/Berlin", "currency": "EUR" }'| Field | Required | Meaning |
|---|---|---|
domain | yes | The site's domain, without https:// or a path |
name | no | A label for the dashboard. Default: the domain |
timezone | no | An IANA timezone such as Europe/Berlin. Default: UTC |
currency | no | Three-letter ISO code for revenue. Default: USD |
The answer, 201, includes the new site's id (tcx_…). Put it in the tracking snippet from Install & verify. The site is added to the key's team, and counts towards the team's plan like any other.
Read and change a site
GET /v1/siteslists the team's sites.GET /v1/sites/{site}answers one site's settings.PATCH /v1/sites/{site}changes any ofname,domain,timezone,currency,identity_mode(cookielessorcookie),include_subdomains,allowed_hostnames,allow_datacenter,revenue_lookback_daysandfeatures. Send only the fields you change.
bash
curl -X PATCH https://api.traffic.cx/v1/sites/tcx_yoursite \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "include_subdomains": true }'Remove a site
DELETE /v1/sites/{site} removes the site from the team's dashboards, and visits to it are no longer collected, just as when you delete a site in Settings.
Goals
| Request | Does |
|---|---|
GET /v1/sites/{site}/goals | Lists the goals |
POST /v1/sites/{site}/goals | Adds one |
PATCH /v1/sites/{site}/goals/{id} | Changes one |
DELETE /v1/sites/{site}/goals/{id} | Removes one |
A goal has a kind and a match:
"kind": "event"counts a custom event by name, for example"match": "signup"."kind": "pageview"counts visits to a page, for example"match": "/pricing"or"/blog/**"."kind": "scroll"counts visits that scroll a page pastscrollpercent (default 50).
name is optional; by default the goal is named after what it matches.
bash
curl -X POST https://api.traffic.cx/v1/sites/tcx_yoursite/goals \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "kind": "event", "match": "signup", "name": "Signed up" }'Chart notes
Notes mark a moment on the dashboard's chart: a launch, a campaign or an outage. Each has an at time (ISO 8601) and a text.
bash
curl -X POST https://api.traffic.cx/v1/sites/tcx_yoursite/annotations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "at": "2026-10-16T09:00:00Z", "text": "Released v2.4" }'GET, PATCH and DELETE work as for goals, at /v1/sites/{site}/annotations and /v1/sites/{site}/annotations/{id}. Notes added with a key show no author.
Verify and troubleshoot
- Create a key with only Manage sites and add a test site. Check that it appears in the dashboard's site list.
- Add an event goal and a note, then open the site's dashboard and find both.
- Remove the test site.
409 means a limit was reached, such as the number of sites a team can have, or a domain that is already tracked. 404 means the site isn't one of the key's team's.
The routes and permission checks are covered by local tests. No request in this guide has been sent to a real customer account as part of publication.