Dashtics
Home › Installation › Agent API

Agent API

Let an AI agent or a script add a site to Dashtics and install the tracking script for you. One call returns the site's tracking code, a ready-to-paste HTML element and the Content Security Policy instructions.

1

Create an API key

Go to Profile → API keys and create a key. It looks like dk_live_… and is shown only once. Send it as a bearer token; sites created with a key belong to you. Revoke a key at any time on the same page.

HTTP header
Authorization: Bearer dk_live_…
2

Add a site

domain is required (a hostname; https:// and paths are stripped). name defaults to the domain and timezone to Europe/Amsterdam (any IANA name). The call is idempotent: if you already have a site with this domain you get it back with 200 and "created": false, a new site returns 201.

curl
curl -X POST https://stats.dashtics.eu/api/agent/sites \
  -H "Authorization: Bearer $DASHTICS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"domain": "example.com", "name": "Example", "timezone": "Europe/Amsterdam"}'
Response 201
{
  "created": true,
  "site": { "id": "…", "name": "Example", "domain": "example.com",
            "timezone": "Europe/Amsterdam", "token": "tk_…", "created_at": "…" },
  "tracking": {
    "script_url": "https://stats.dashtics.eu/static/script.js",
    "html": "<script src=\"https://stats.dashtics.eu/static/script.js\" data-site=\"tk_…\" async></script>",
    "placement": "Add this element once in the <head> of every page, before </head>."
  },
  "csp": {
    "applies_if": "The site sends a Content-Security-Policy header …",
    "origin": "https://stats.dashtics.eu",
    "directives": { "script-src": "https://stats.dashtics.eu", "connect-src": "https://stats.dashtics.eu" },
    "nginx": "add_header Content-Security-Policy \"script-src 'self' https://stats.dashtics.eu; connect-src 'self' https://stats.dashtics.eu\" always;",
    "apache": "Header always set Content-Security-Policy \"…\"",
    "instructions": "If the site already sends a Content-Security-Policy, add the origin to its existing script-src and connect-src …",
    "docs_url": "https://stats.dashtics.eu/docs/installation#csp"
  }
}

tracking.html is a complete element with HTML-escaped attribute values; insert it as-is. Errors return JSON with an error field: 400 invalid JSON, 401 missing, invalid or revoked key, 422 invalid domain or timezone.

3

Verify the installation

After deploying the snippet, open a page of the site in a browser and check the status. installed becomes true once the first event arrives.

curl
curl https://stats.dashtics.eu/api/agent/sites/tk_…/status \
  -H "Authorization: Bearer $DASHTICS_API_KEY"

# { "token": "tk_…", "domain": "example.com", "installed": true,
#   "events_total": 12, "events_last_24h": 12, "checked_at": "…", "hint": "…" }

GET https://stats.dashtics.eu/api/agent/sites lists your sites with the same tracking and csp blocks.

4

Create funnels

A funnel needs a name and 2 to 20 steps. A step is a page ("type": "url", the default) or a custom event ("type": "event", the name used in analytics.track()). URL values can be a path like /pricing, which is expanded to the site's domain; a page also matches with a query string, hash or subpath. Creating a funnel with an existing name returns that funnel with "created": false.

curl
curl -X POST https://stats.dashtics.eu/api/agent/sites/tk_…/funnels \
  -H "Authorization: Bearer $DASHTICS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "Signup", "steps": [
        {"name": "Home",      "value": "/"},
        {"name": "Pricing",   "value": "/pricing"},
        {"name": "Signed up", "type": "event", "value": "signup"}]}'

# 201 { "created": true, "funnel": { "id": "…", "name": "Signup", "steps": [...],
#       "dashboard_url": "https://stats.dashtics.eu/sites/…/funnels/…" } }

GET https://stats.dashtics.eu/api/agent/sites/tk_…/funnels lists the site's funnels with their steps.

Instructions for the agent

  1. Call POST /api/agent/sites with the site's domain.
  2. Insert tracking.html exactly once in the <head> of every page, typically in the shared layout or base template.
  3. Check whether the site sends a Content-Security-Policy header. If it does, add csp.origin to its existing script-src and connect-src; do not add a second CSP header. If the server is nginx without a CSP, csp.nginx is a working header line. See Content Security Policy.
  4. Deploy, load a page, then call GET /api/agent/sites/{token}/status until installed is true.