Documentation Index
Fetch the complete documentation index at: https://mintlify.com/databuddy-analytics/Databuddy/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Custom events allow you to track specific user actions beyond pageviews. Use thetrack() function to capture button clicks, form submissions, purchases, and any other meaningful interactions.
Basic Usage
Tracking Simple Events
React Example
Function Signature
Parameters
The event name. Use snake_case for consistency (e.g.,
button_clicked, purchase_completed).Optional key-value pairs of event data. Supports strings, numbers, booleans, null, and undefined.
The
track() function is safe to call on the server (no-op) or before the tracker loads. Events are automatically batched for efficient delivery.Common Event Examples
E-commerce Events
User Engagement
Navigation Events
Declarative Tracking with Data Attributes
Enable automatic event tracking without JavaScript by addingdata-track attributes to elements. You must enable this feature in your tracker configuration.
Enable Data Attributes
HTML Examples
Property naming: Data attributes are automatically converted from kebab-case to camelCase. For example,
data-button-text becomes { buttonText: "value" } in the tracked event.Best Practices
Use Descriptive Names
Choose event names that clearly describe the action:
purchase_completed instead of purchase, signup_started instead of click.Keep Properties Simple
Use primitive types (strings, numbers, booleans) for properties. Avoid nested objects or arrays.
Be Consistent
Use snake_case for event names and camelCase for property keys throughout your application.
Track Intent, Not Just Actions
Capture why users performed an action, not just what they did. Include context like location, source, or variant.
Event Batching
Events are automatically batched to reduce network overhead. The tracker queues events and sends them in groups. Default Configuration:- Batch size: 10 events
- Batch timeout: 5000ms (5 seconds)
- Batching enabled: Yes
Manual Flush
Force immediate delivery of all queued events:Advanced Usage
Global Event Properties
Set properties that will be attached to all future events:- User plan or tier
- A/B test variants
- Feature flags
- Region or locale
Conditional Tracking
Type-Safe Tracking
Define event types for better autocomplete and type safety:Related Functions
flush()- Force send all queued eventsclear()- Reset tracking sessiontrackError()- Convenience wrapper for error events