Introducing our new Monitoring feature Learn more

Documentation

AI traffic

Manage AI traffic sites, fetch stats, and install the public tracking snippet.

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

FieldTypeDescription
domainstringRequired domain (normalized)
namestringOptional 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

QueryDescription
siteKeySite key to query
daysLookback window 1–90 (default 30)
sourcePrefer 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:

FieldDescription
siteKeyRequired site key
pathPage path
referrerDocument referrer
titlePage title
sessionIdClient session id
userAgentUser agent string
utmSource / utmMedium / utmCampaignCampaign params
sessionDurationMs / scrollDepthEngagement updates

CORS allows browser POST from any origin for this endpoint.