API Reference
Event Tracking
Track custom events programmatically using the Basket API. This is useful for server-side tracking, mobile apps, or custom integrations.
Base URL
https://basket.databuddy.ccAuthentication
You can authenticate requests using either:
# With API Key
POST /track
Authorization: Bearer your_api_key
# With Client ID
POST /track?website_id={website_id}Track Events
The primary endpoint for sending custom events.
POST /trackSingle Event
{
"name": "purchase",
"properties": {
"value": 99.99,
"currency": "USD",
"product_id": "prod_123"
},
"anonymousId": "anon_user_123",
"sessionId": "session_456",
"timestamp": 1704067200000
}Batch Events
Send an array of events in a single request:
[
{
"name": "page_view",
"properties": { "page": "/pricing" },
"timestamp": 1704067200000
},
{
"name": "purchase",
"properties": { "value": 99.99 },
"timestamp": 1704067260000
}
]Response
{
"status": "success",
"type": "custom_event",
"count": 1
}Event Fields
Server-Side Examples
Node.js / TypeScript
async function trackEvent(
name: string,
properties?: Record<string, unknown>
) {
const response = await fetch('https://basket.databuddy.cc/track', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer your_api_key'
},
body: JSON.stringify({
name,
properties,
timestamp: Date.now()
})
});
return response.json();
}
// Usage
await trackEvent('purchase', {
value: 99.99,
currency: 'USD',
product_id: 'prod_123'
});Python
import requests
import time
def track_event(name: str, properties: dict = None):
response = requests.post(
"https://basket.databuddy.cc/track",
headers={
"Content-Type": "application/json",
"Authorization": "Bearer your_api_key"
},
json={
"name": name,
"properties": properties or {},
"timestamp": int(time.time() * 1000)
}
)
return response.json()
# Usage
track_event("purchase", {
"value": 99.99,
"currency": "USD",
"product_id": "prod_123"
})cURL
curl -X POST https://basket.databuddy.cc/track \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your_api_key" \
-d '{
"name": "purchase",
"properties": {
"value": 99.99,
"currency": "USD"
}
}'Common Event Examples
E-commerce Purchase
{
"name": "purchase",
"properties": {
"order_id": "order_123",
"value": 149.99,
"currency": "USD",
"items": [
{"sku": "SKU-001", "name": "Product A", "quantity": 2, "price": 49.99},
{"sku": "SKU-002", "name": "Product B", "quantity": 1, "price": 50.01}
]
}
}User Signup
{
"name": "signup",
"properties": {
"method": "email",
"plan": "free",
"referrer": "google"
}
}Feature Usage
{
"name": "feature_used",
"namespace": "dashboard",
"properties": {
"feature": "export_csv",
"format": "xlsx"
}
}Subscription Event
{
"name": "subscription_started",
"properties": {
"plan": "pro",
"billing_cycle": "annual",
"mrr": 99
}
}Additional Endpoints
These endpoints are used by the JavaScript tracker SDK and are documented here for completeness. The client_id query value is your Databuddy Client ID.
Web Vitals
Track Core Web Vitals metrics.
POST /vitals?client_id={client_id}[
{
"timestamp": 1704067200000,
"path": "https://example.com/page",
"metricName": "LCP",
"metricValue": 2500
}
]Error Tracking
Track JavaScript errors.
POST /errors?client_id={client_id}[
{
"timestamp": 1704067200000,
"path": "https://example.com/app",
"message": "Cannot read property 'id' of undefined",
"filename": "https://example.com/app.js",
"lineno": 42,
"colno": 15,
"stack": "TypeError: ...",
"errorType": "TypeError"
}
]Error Responses
{
"status": "error",
"message": "Description of the error"
}Best Practices
How is this guide?