BETA
Skip to content

Sites

Create, retrieve, update, and delete analytics sites. Each site represents a domain you want to track.

Base URL: https://app.krafter.dev/api/v1/analytics

Site Object

json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "domain": "example.com",
  "name": "My Website",
  "site_key": "sk_abc123def456",
  "public_stats": false,
  "created_at": "2025-01-15T10:00:00Z"
}
FieldTypeDescription
idstringUnique identifier (UUID).
domainstringThe domain being tracked.
namestringDisplay name for the site.
site_keystringPublic site key used in the tracker script. Starts with sk_.
public_statsbooleanWhether the stats dashboard is publicly accessible.
created_atstringISO 8601 timestamp of when the site was created.

List Sites

Retrieve all analytics sites for your team.

GET /analytics/sites

Required scope: analytics:read

Example Request

bash
curl https://app.krafter.dev/api/v1/analytics/sites \
  -H "Authorization: Bearer YOUR_API_TOKEN"

Example Response

json
{
  "data": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "domain": "example.com",
      "name": "My Website",
      "site_key": "sk_abc123def456",
      "public_stats": false,
      "created_at": "2025-01-15T10:00:00Z"
    },
    {
      "id": "660f9511-f39c-52e5-b827-557766551111",
      "domain": "blog.example.com",
      "name": "Company Blog",
      "site_key": "sk_def456ghi789",
      "public_stats": true,
      "created_at": "2025-02-01T14:30:00Z"
    }
  ]
}

Create Site

Create a new analytics site. A site_key is auto-generated and returned in the response.

POST /analytics/sites

Required scope: analytics:write

Request Body

FieldTypeRequiredDescription
domainstringYesDomain to track. Must be alphanumeric with dots (e.g., example.com).
namestringYesDisplay name for the site.

Example Request

bash
curl -X POST https://app.krafter.dev/api/v1/analytics/sites \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "domain": "example.com",
    "name": "My Website"
  }'

Example Response

json
// 201 Created
{
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "domain": "example.com",
    "name": "My Website",
    "site_key": "sk_abc123def456",
    "public_stats": false,
    "created_at": "2025-01-15T10:00:00Z"
  }
}

WARNING

The site_key is generated automatically and cannot be changed. Store it securely -- you will need it for the tracker script and API queries.

Validation Errors

json
// 422 Unprocessable Entity
{
  "error": {
    "message": "Validation failed",
    "details": {
      "domain": ["must contain only alphanumeric characters and dots"]
    }
  }
}

Get Site

Retrieve a single site by its site key.

GET /analytics/sites/:key

Required scope: analytics:read

Example Request

bash
curl https://app.krafter.dev/api/v1/analytics/sites/sk_abc123def456 \
  -H "Authorization: Bearer YOUR_API_TOKEN"

Example Response

json
{
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "domain": "example.com",
    "name": "My Website",
    "site_key": "sk_abc123def456",
    "public_stats": false,
    "created_at": "2025-01-15T10:00:00Z"
  }
}

Update Site

Update a site's name or domain.

PATCH /analytics/sites/:key

Required scope: analytics:write

Request Body

FieldTypeRequiredDescription
namestringNoNew display name.
domainstringNoNew domain. Must be alphanumeric with dots.

Example Request

bash
curl -X PATCH https://app.krafter.dev/api/v1/analytics/sites/sk_abc123def456 \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Main Website"
  }'

Example Response

json
{
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "domain": "example.com",
    "name": "Main Website",
    "site_key": "sk_abc123def456",
    "public_stats": false,
    "created_at": "2025-01-15T10:00:00Z"
  }
}

Delete Site

Delete a site and all associated analytics data. This action is irreversible.

DELETE /analytics/sites/:key

Required scope: analytics:write

Example Request

bash
curl -X DELETE https://app.krafter.dev/api/v1/analytics/sites/sk_abc123def456 \
  -H "Authorization: Bearer YOUR_API_TOKEN"

Example Response

json
// 200 OK
{
  "data": {
    "deleted": true
  }
}

WARNING

Deleting a site permanently removes all analytics data, including page views, events, goals, and statistics. This cannot be undone.

Scopes

ScopeEndpoints
analytics:readGET /analytics/sites, GET /analytics/sites/:key
analytics:writePOST /analytics/sites, PATCH /analytics/sites/:key, DELETE /analytics/sites/:key

Built by Krafter Studio