Skip to main content

List all websites

curl -X GET https://analytics.example.com/api/websites \
  -H "Authorization: Bearer spk_selfhosted_abc123..."
data
array
Array of website objects
pagination
object

Query Parameters

limit
integer
default:"20"
Number of websites to return (1-100)
cursor
string
Website ID to paginate from (from previous response’s pagination.cursor)

Response Example

{
  "data": [
    {
      "id": "site_a1b2c3d4e5",
      "tenant_id": null,
      "name": "My Blog",
      "domain": "example.com",
      "timezone": "UTC",
      "share_id": null,
      "created_at": "2026-03-01T10:00:00Z",
      "updated_at": "2026-03-01T10:00:00Z"
    }
  ],
  "pagination": {
    "total": 1,
    "limit": 20,
    "cursor": null,
    "has_more": false
  }
}

Create a website

curl -X POST https://analytics.example.com/api/websites \
  -H "Authorization: Bearer spk_selfhosted_abc123..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "My Blog",
    "domain": "example.com",
    "timezone": "America/New_York"
  }'

Request Body

name
string
required
Website display name (must not be empty)
domain
string
required
Website domain. Must be:
  • A valid hostname without scheme, port, path, or credentials
  • A registrable domain (not a public suffix like .com)
  • Lowercase, normalized automatically
Valid: example.com, blog.example.com, localhost, 192.168.1.1
Invalid: https://example.com, example.com:3000, com, co.uk
timezone
string
default:"UTC"
IANA timezone identifier (e.g., America/New_York, Europe/London)

Response (201 Created)

data
object

Response Example

{
  "data": {
    "id": "site_a1b2c3d4e5",
    "tenant_id": null,
    "name": "My Blog",
    "domain": "example.com",
    "timezone": "America/New_York",
    "tracking_snippet": "<script defer src=\"https://analytics.example.com/s.js\" data-website-id=\"site_a1b2c3d4e5\"></script>",
    "created_at": "2026-03-01T10:00:00Z"
  }
}

Get a website

curl -X GET https://analytics.example.com/api/websites/site_a1b2c3d4e5 \
  -H "Authorization: Bearer spk_selfhosted_abc123..."

Path Parameters

id
string
required
Website ID (format: site_*)

Response (200 OK)

data
object
Website object (same structure as in list endpoint)

Response Example

{
  "data": {
    "id": "site_a1b2c3d4e5",
    "tenant_id": null,
    "name": "My Blog",
    "domain": "example.com",
    "timezone": "America/New_York",
    "share_id": null,
    "created_at": "2026-03-01T10:00:00Z",
    "updated_at": "2026-03-01T10:00:00Z"
  }
}

Error Responses

404 Not Found
{
  "error": {
    "code": "not_found",
    "message": "Website not found"
  }
}

Update a website

curl -X PUT https://analytics.example.com/api/websites/site_a1b2c3d4e5 \
  -H "Authorization: Bearer spk_selfhosted_abc123..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "My Updated Blog",
    "timezone": "UTC"
  }'

Path Parameters

id
string
required
Website ID (format: site_*)

Request Body

All fields are optional. Only provided fields will be updated.
name
string
New website display name
domain
string
New domain (must pass same validation as create endpoint)
timezone
string
New IANA timezone identifier

Response (200 OK)

data
object

Response Example

{
  "data": {
    "id": "site_a1b2c3d4e5",
    "name": "My Updated Blog",
    "domain": "example.com",
    "timezone": "UTC",
    "updated_at": "2026-03-02T14:30:00Z"
  }
}

Error Responses

404 Not Found
Website does not exist
400 Bad Request
Invalid domain format (same validation as create endpoint)

Delete a website

This permanently deletes the website and all associated analytics data (events, sessions, goals). This action cannot be undone.
curl -X DELETE https://analytics.example.com/api/websites/site_a1b2c3d4e5 \
  -H "Authorization: Bearer spk_selfhosted_abc123..."

Path Parameters

id
string
required
Website ID (format: site_*)

Response (204 No Content)

Empty response body on successful deletion.

Error Responses

404 Not Found
{
  "error": {
    "code": "not_found",
    "message": "Website not found"
  }
}

Website ID Format

All website IDs follow the format:
site_<10 random alphanumeric chars>
Example: site_a1b2c3d4e5, site_x9y8z7w6v5 This ID is used:
  • In API endpoints as the :id path parameter
  • In the tracking snippet as data-website-id
  • In query endpoints to scope analytics data

Build docs developers (and LLMs) love