AI traffic
Base path: /v1/ai-traffic
Authenticated routes require the api-key header. The tracking script and collect beacon are public (no API key).
List sites
GET /v1/ai-traffic/sites
curl https://api.krastie.ai/v1/ai-traffic/sites \
-H "api-key: YOUR_KEY"
{
"sites": [
{
"id": "…",
"siteKey": "ks_…",
"domain": "example.com",
"name": "example.com",
"isActive": true,
"snippet": "<script …>",
"scriptUrl": "https://api.krastie.ai/v1/ai-traffic/t.js",
"createdAt": "…"
}
]
}
Create a site
POST /v1/ai-traffic/sites
| Field | Type | Description |
|---|---|---|
domain | string | Required domain (normalized) |
name | string | Optional display name |
curl https://api.krastie.ai/v1/ai-traffic/sites \
-H "api-key: YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"domain":"example.com","name":"Marketing site"}'
Returns 201 with the site object including siteKey and snippet.
Ensure default site
POST /v1/ai-traffic/sites/ensure
Returns an existing site for the workspace, or creates one from the team/user website when possible. If no domain is available:
{ "site": null, "needsDomain": true }
Get stats
GET /v1/ai-traffic/stats
| Query | Description |
|---|---|
siteKey | Site key to query |
days | Lookback window 1–90 (default 30) |
source | Prefer script to force script-based stats when GA is connected |
curl "https://api.krastie.ai/v1/ai-traffic/stats?siteKey=ks_…&days=30" \
-H "api-key: YOUR_KEY"
When Google Analytics is connected for the workspace, stats may come from GA unless source=script is set.
There is also an alias at GET /v1/ai/generate/ai-traffic.
Tracking script (public)
GET /v1/ai-traffic/t.js
Install the snippet returned when you create a site (includes your data-site / site key). Example pattern:
<script
defer
src="https://api.krastie.ai/v1/ai-traffic/t.js"
data-site="ks_YOUR_SITE_KEY"
></script>
Collect beacon (public)
POST /v1/ai-traffic/collect
Used by the tracking script. Typical body fields:
| Field | Description |
|---|---|
siteKey | Required site key |
path | Page path |
referrer | Document referrer |
title | Page title |
sessionId | Client session id |
userAgent | User agent string |
utmSource / utmMedium / utmCampaign | Campaign params |
sessionDurationMs / scrollDepth | Engagement updates |
CORS allows browser POST from any origin for this endpoint.