Batch Events
curl --request POST \
--url https://api.example.com/batch \
--header 'Content-Type: <content-type>' \
--data '
{
"type": "<string>",
"payload": {}
}
'{
"status": "<string>",
"batch": true,
"processed": 123,
"batched": {},
"results": [
{}
]
}Events API
Batch Events
Send multiple events in a single request for improved performance
POST
/
batch
Batch Events
curl --request POST \
--url https://api.example.com/batch \
--header 'Content-Type: <content-type>' \
--data '
{
"type": "<string>",
"payload": {}
}
'{
"status": "<string>",
"batch": true,
"processed": 123,
"batched": {},
"results": [
{}
]
}The batch endpoint allows you to send multiple analytics events in a single HTTP request, improving performance and reducing network overhead. It supports both track events and outgoing link events.
Authentication
Batch requests require a validwebsite_id query parameter. The website must exist and be accessible.
Request
Headers
Must be
application/jsonQuery Parameters
UUID of the website to track events for
Body Parameters
The request body must be an array of event objects (maximum 100 events per batch).Track Event Object
Must be
"track" for analytics eventsEvent data object containing:
eventId(string, optional): Unique identifier for deduplicationname(string, required): Event nameanonymousId(string, required): Anonymous user identifiersessionId(string, required): Session identifiersessionStartTime(number, required): Session start timestamp (Unix ms)timestamp(number, required): Event timestamp (Unix ms)path(string, required): Page path where event occurredtitle(string, required): Page titlereferrer(string, required): Referrer URLscreen_resolution(string, required): Screen resolution (e.g., “1920x1080”)viewport_size(string, required): Viewport size (e.g., “1440x900”)timezone(string, required): User timezonelanguage(string, required): Browser languageconnection_type(string, optional): Connection type (“wifi”, “cellular”, “ethernet”, “unknown”)rtt(number, optional): Round-trip time in millisecondsdownlink(number, optional): Download speed in Mbpsutm_source(string, optional): UTM source parameterutm_medium(string, optional): UTM medium parameterutm_campaign(string, optional): UTM campaign parameterutm_term(string, optional): UTM term parameterutm_content(string, optional): UTM content parameterload_time(number, optional): Page load time in millisecondsdom_ready_time(number, optional): DOM ready time in millisecondsttfb(number, optional): Time to first byte in millisecondstime_on_page(number, optional): Time spent on page in millisecondsscroll_depth(number, optional): Scroll depth percentage (0-100)interaction_count(number, optional): Number of interactionspage_count(number, optional): Pages viewed in session
Outgoing Link Event Object
Must be
"outgoing_link" for link click trackingLink event data object containing:
eventId(string, required): Unique identifieranonymousId(string, optional): Anonymous user identifiersessionId(string, optional): Session identifiertimestamp(number, optional): Event timestamp (Unix ms)href(string, required): Link URLtext(string, optional): Link text contentproperties(object, optional): Additional custom properties
Response
Status of the batch request:
success or errorAlways
true for batch requestsTotal number of events processed
Breakdown of events by type:
track(number): Number of track events processedoutgoing_link(number): Number of outgoing link events processed
Array of result objects for each event:
status(string):successorerrorfor this specific eventtype(string): Event type (trackoroutgoing_link)eventId(string, optional): Event ID if providedmessage(string, optional): Error message if failed
Examples
Mixed Batch Request
curl -X POST 'https://api.databuddy.io/batch?website_id=550e8400-e29b-41d4-a716-446655440000' \
-H "Content-Type: application/json" \
-d '[
{
"type": "track",
"payload": {
"eventId": "evt_123",
"name": "page_view",
"anonymousId": "anon_456",
"sessionId": "sess_789",
"sessionStartTime": 1709251200000,
"timestamp": 1709251200000,
"path": "/dashboard",
"title": "Dashboard",
"referrer": "https://google.com",
"screen_resolution": "1920x1080",
"viewport_size": "1440x900",
"timezone": "America/New_York",
"language": "en-US",
"load_time": 1200,
"ttfb": 250
}
},
{
"type": "outgoing_link",
"payload": {
"eventId": "evt_124",
"anonymousId": "anon_456",
"sessionId": "sess_789",
"timestamp": 1709251210000,
"href": "https://external-site.com",
"text": "Learn More"
}
}
]'
Response
{
"status": "success",
"batch": true,
"processed": 2,
"batched": {
"track": 1,
"outgoing_link": 1
},
"results": [
{
"status": "success",
"type": "track",
"eventId": "evt_123"
},
{
"status": "success",
"type": "outgoing_link",
"eventId": "evt_124"
}
]
}
Track Events Only
curl -X POST 'https://api.databuddy.io/batch?website_id=550e8400-e29b-41d4-a716-446655440000' \
-H "Content-Type: application/json" \
-d '[
{
"type": "track",
"payload": {
"name": "button_click",
"anonymousId": "anon_123",
"sessionId": "sess_456",
"sessionStartTime": 1709251200000,
"timestamp": 1709251205000,
"path": "/pricing",
"title": "Pricing",
"referrer": "",
"screen_resolution": "1366x768",
"viewport_size": "1366x768",
"timezone": "UTC",
"language": "en"
}
},
{
"type": "track",
"payload": {
"name": "form_submit",
"anonymousId": "anon_123",
"sessionId": "sess_456",
"sessionStartTime": 1709251200000,
"timestamp": 1709251220000,
"path": "/contact",
"title": "Contact Us",
"referrer": "/pricing",
"screen_resolution": "1366x768",
"viewport_size": "1366x768",
"timezone": "UTC",
"language": "en"
}
}
]'
Error Responses
Batch Too Large
{
"status": "error",
"message": "Batch too large"
}
Invalid Body Format
{
"status": "error",
"message": "Batch endpoint expects array of events"
}
Partial Success
If some events fail validation, they will be marked as errors in the results array while successful events are still processed:{
"status": "success",
"batch": true,
"processed": 2,
"batched": {
"track": 1,
"outgoing_link": 0
},
"results": [
{
"status": "success",
"type": "track",
"eventId": "evt_123"
},
{
"status": "error",
"message": "Invalid event schema",
"eventType": "track",
"eventId": "evt_124"
}
]
}
Limits
- Maximum batch size: 100 events per request
- Event names: 1-256 characters
- Anonymous ID: max 256 characters
- Session ID: max 256 characters
- Path: max 2048 characters
- Text: max 1024 characters
⌘I