AgentSkillsCN

databuddy-api

通过 Databuddy REST API 实现对分析数据的程序化访问。无论是查询分析数据、构建自定义仪表板、通过 API 发送事件,还是将分析功能集成至后端服务,均可轻松实现。

SKILL.md
--- frontmatter
name: databuddy-api
description: Use the Databuddy REST API for programmatic access to analytics data. Use when querying analytics data, building custom dashboards, sending events via API, or integrating analytics into backend services.
metadata:
  author: databuddy
  version: "2.3"

Databuddy REST API

The Databuddy REST API provides programmatic access to analytics data.

External Documentation

For the most up-to-date documentation, fetch: https://databuddy.cc/llms.txt

When to Use This Skill

Use this skill when:

  • Querying analytics data programmatically
  • Building custom dashboards or reports
  • Sending events via REST API
  • Integrating analytics into backend services
  • Need to access analytics data outside of the SDK

Base URLs

ServiceURLPurpose
Analytics APIhttps://api.databuddy.cc/v1Query analytics data
Event Trackinghttps://basket.databuddy.ccSend custom events

Authentication

API Key

Use your API key in the x-api-key header:

bash
curl -H "x-api-key: dbdy_your_api_key" \
  https://api.databuddy.cc/v1/query/websites

Or use Bearer token format:

bash
curl -H "Authorization: Bearer dbdy_your_api_key" \
  https://api.databuddy.cc/v1/query/websites

Getting an API Key

  1. Go to Dashboard → Organization Settings → API Keys
  2. Click Create API Key
  3. Select required scopes
  4. Optionally restrict to specific websites

API Key Scopes

ScopePermission
read:dataQuery analytics data
write:dataSend custom events
read:websitesList accessible websites
manage:websitesCreate and update websites

Query Endpoints

List Websites

http
GET /v1/query/websites

Response:

json
{
  "success": true,
  "websites": [
    {
      "id": "web_123",
      "name": "My Website",
      "domain": "example.com"
    }
  ]
}

Get Query Types

http
GET /v1/query/types?include_meta=true

Returns available query types and their configurations.

Execute Query

http
POST /v1/query?website_id={id}

Request Body:

json
{
  "parameters": ["summary", "pages", "browser_name"],
  "startDate": "2024-01-01",
  "endDate": "2024-01-31",
  "limit": 100,
  "filters": [
    { "field": "country", "op": "in", "value": ["US", "CA"] }
  ],
  "granularity": "daily"
}

Or use presets:

json
{
  "parameters": ["summary", "pages"],
  "preset": "last_30d",
  "limit": 10
}

Date Presets:

PresetDescription
todayCurrent day
yesterdayPrevious day
last_7dLast 7 days
last_14dLast 14 days
last_30dLast 30 days
last_90dLast 90 days
this_weekCurrent week
last_weekPrevious full week
this_monthCurrent month to date
last_monthPrevious full month
this_yearCurrent year to date

Response:

json
{
  "success": true,
  "data": [
    {
      "parameter": "summary",
      "success": true,
      "data": [
        { "date": "2024-01-01", "pageviews": 1250, "visitors": 890 }
      ]
    },
    {
      "parameter": "pages",
      "success": true,
      "data": [
        { "path": "/", "pageviews": 450, "visitors": 320 }
      ]
    }
  ]
}

Available Query Types

Website Analytics

TypeDescription
summaryOverall website metrics and KPIs
pagesPage views and performance by URL
trafficTraffic sources and referrers
browser_nameBrowser usage breakdown
os_nameOperating system breakdown
device_typesDevice category (mobile/desktop/tablet)
countriesVisitors by country
citiesVisitors by city
errorsJavaScript errors
performanceWeb vitals and load times
sessionsSession-based analytics
custom_eventsCustom event data
profilesUser profile analytics
outbound_linksExternal link clicks
engagementUser engagement metrics

Link Shortener Analytics

Use link_id instead of website_id:

TypeDescription
link_total_clicksTotal click count
link_clicks_by_dayDaily click breakdown
link_top_referrersTop traffic sources
link_top_countriesTop countries
link_top_devicesDevice breakdown
link_top_browsersBrowser breakdown

Filter Operations

OperatorDescriptionExample
eqEquals{ "field": "country", "op": "eq", "value": "US" }
neNot equals{ "field": "device_type", "op": "ne", "value": "bot" }
containsContains substring{ "field": "path", "op": "contains", "value": "/blog" }
starts_withStarts with{ "field": "path", "op": "starts_with", "value": "/docs" }
inValue in array{ "field": "country", "op": "in", "value": ["US", "CA"] }
not_inNot in array{ "field": "browser", "op": "not_in", "value": ["bot"] }

Event Tracking API

Send Single Event

http
POST https://basket.databuddy.cc/?client_id={website_id}

Request Body:

json
{
  "type": "custom",
  "name": "purchase",
  "anonymousId": "anon_user_123",
  "sessionId": "session_456",
  "timestamp": 1704067200000,
  "properties": {
    "value": 99.99,
    "currency": "USD",
    "product_id": "prod_123"
  }
}

Minimal Event:

json
{
  "type": "custom",
  "name": "newsletter_signup",
  "properties": { "source": "footer_form" }
}

Event Fields

FieldTypeRequiredDescription
typestringYesMust be "custom"
namestringYesEvent name (1-128 chars)
anonymousIdstringNoAnonymous user identifier
sessionIdstringNoSession identifier
timestampnumberNoUnix timestamp in ms
propertiesobjectNoCustom properties

Batch Events

http
POST https://basket.databuddy.cc/batch?client_id={website_id}

Request Body:

json
[
  { "type": "custom", "name": "event1", "properties": {...} },
  { "type": "custom", "name": "event2", "properties": {...} }
]

Response:

json
{
  "status": "success",
  "batch": true,
  "processed": 2,
  "results": [
    { "status": "success", "type": "custom", "eventId": "evt_123" },
    { "status": "success", "type": "custom", "eventId": "evt_124" }
  ]
}

Custom Queries

For advanced queries with custom aggregations:

http
POST /v1/query/custom?website_id={id}

Request Body:

json
{
  "query": {
    "table": "events",
    "selects": [
      { "field": "path", "aggregate": "count", "alias": "pageviews" },
      { "field": "anonymous_id", "aggregate": "uniq", "alias": "visitors" }
    ],
    "filters": [
      { "field": "country", "operator": "eq", "value": "US" }
    ],
    "groupBy": ["path"]
  },
  "startDate": "2024-01-01",
  "endDate": "2024-01-31",
  "limit": 100
}

Available Tables

TableDescription
eventsPage views and custom events
sessionsSession-level data
profilesUser profile data
errorsJavaScript errors
performanceWeb vitals metrics

Aggregate Functions

FunctionDescription
countCount rows
uniqCount unique values
sumSum numeric values
avgAverage value
maxMaximum value
minMinimum value

Error Codes

CodeMeaning
AUTH_REQUIREDNo API key or session provided
ACCESS_DENIEDNo access to requested resource
INVALID_API_KEYAPI key invalid or revoked
INSUFFICIENT_SCOPEAPI key lacks required scope
RATE_LIMITEDToo many requests

Rate Limits

  • Standard queries: 200+ requests/minute
  • Custom queries: 30 requests/minute

Health Check

http
GET /health
json
{
  "clickhouse": true,
  "database": true,
  "redis": true,
  "success": true,
  "version": "1.0.0"
}