The custom events API allows you to send application-specific events with optional data and attributes. These events can represent user actions, business metrics, or any significant occurrence in your application.
Critical Custom Event Behavior:
init() may be queued or droppedSends a custom event with optional data and attributes.
/**
* Sends a custom event
* @param name - Event name (cannot be an internal event name)
* @param opts - Additional event details (optional)
* @throws No errors thrown; invalid events may be dropped with warning
*/
function sendEvent(name: string, opts?: EventOptions): void;
interface EventOptions {
/** Human readable title for the event (short sentence summary) */
title?: string;
/** Event timestamp (defaults to current time) */
timestamp?: number | Date;
/** Event body/data */
data?: AttributeValueType | AnyValue;
/** Event attributes */
attributes?: Record<string, AttributeValueType | AnyValue>;
/** Log severity level */
severity?: LOG_SEVERITY_TEXT;
}
type LOG_SEVERITY_TEXT =
| "UNSPECIFIED"
| "TRACE"
| "DEBUG"
| "INFO"
| "WARN"
| "ERROR"
| "FATAL";Usage Examples:
import { sendEvent } from "@dash0/sdk-web";
// Simple event
sendEvent("user_action");
// Event with data
sendEvent("button_clicked", {
data: "submit_form",
});
// Event with attributes and severity
sendEvent("purchase_completed", {
title: "User completed purchase",
data: { orderId: "order-123", amount: 99.99 },
attributes: {
"order.id": "order-123",
"order.amount": 99.99,
"order.currency": "USD",
},
severity: "INFO",
});
// Event with custom timestamp
sendEvent("scheduled_task", {
timestamp: new Date("2024-01-15T10:00:00Z"),
data: "backup_completed",
});For IIFE (script tag) usage:
dash0("sendEvent", "user_action");
dash0("sendEvent", "purchase_completed", {
data: { orderId: "order-123" },
severity: "INFO",
});Critical Behavior:
Important: The event name cannot be any of the internal event names used by the SDK:
browser.page_viewbrowser.navigation_timingbrowser.web_vitalbrowser.errorIf you attempt to use an internal event name, the SDK will log a warning and drop the event.
Critical Behavior:
browser.page_view_custom) are allowedbrowser. are not automatically blocked; only exact matches are blockedThe event title is transmitted via the dash0.web.event.title attribute. The event name is transmitted via the event.name attribute.
Critical Behavior:
event.name is always included (set to the provided name)dash0.web.event.title is only included if title is providedopts.attributes are merged with these standard attributesopts.attributes and standard attributes are resolved in favor of standard attributesTrack user interactions and behaviors:
import { sendEvent } from "@dash0/sdk-web";
// Button clicks
sendEvent("checkout_button_clicked", {
title: "User clicked checkout button",
attributes: {
"button.id": "checkout-btn",
"page.url": window.location.href,
},
severity: "INFO",
});
// Form submissions
sendEvent("form_submitted", {
title: "Contact form submitted",
attributes: {
"form.id": "contact-form",
"form.fields": 5,
},
});
// Navigation events
sendEvent("tab_switched", {
attributes: {
"tab.from": "overview",
"tab.to": "details",
},
});Track business-critical events:
// Purchase events
sendEvent("purchase", {
title: "Purchase completed",
data: {
orderId: "ORD-12345",
amount: 149.99,
currency: "USD",
},
attributes: {
"transaction.id": "TXN-67890",
"payment.method": "credit_card",
"cart.items": 3,
},
severity: "INFO",
});
// Subscription events
sendEvent("subscription_upgraded", {
title: "User upgraded subscription",
attributes: {
"subscription.from": "basic",
"subscription.to": "premium",
"subscription.price": 29.99,
},
});
// Feature usage
sendEvent("feature_used", {
attributes: {
"feature.name": "advanced_search",
"feature.category": "search",
},
});Track significant application state changes:
// Mode changes
sendEvent("dark_mode_enabled", {
attributes: {
"theme.previous": "light",
"theme.current": "dark",
},
});
// Settings changes
sendEvent("settings_updated", {
data: {
notifications: true,
autoSave: false,
},
attributes: {
"settings.category": "preferences",
},
});Track multi-step workflows:
// Workflow start
sendEvent("onboarding_started", {
title: "User started onboarding",
attributes: {
"workflow.id": "onboarding-2024",
"workflow.step": 1,
},
});
// Workflow progress
sendEvent("onboarding_step_completed", {
attributes: {
"workflow.id": "onboarding-2024",
"workflow.step": 2,
"workflow.total_steps": 5,
},
});
// Workflow completion
sendEvent("onboarding_completed", {
title: "User completed onboarding",
attributes: {
"workflow.id": "onboarding-2024",
"workflow.duration_seconds": 180,
},
});Use custom events for application-specific errors and warnings:
// Application warnings
sendEvent("quota_warning", {
title: "User approaching storage quota",
attributes: {
"quota.used_bytes": 950000000,
"quota.total_bytes": 1000000000,
"quota.percentage": 95,
},
severity: "WARN",
});
// Validation errors
sendEvent("validation_error", {
title: "Form validation failed",
data: {
field: "email",
error: "Invalid email format",
},
attributes: {
"form.id": "registration",
},
severity: "ERROR",
});Track custom performance markers:
// Custom timing events
const startTime = Date.now();
// ... perform operation ...
sendEvent("operation_completed", {
title: "Data processing completed",
attributes: {
"operation.name": "process_large_dataset",
"operation.duration_ms": Date.now() - startTime,
"operation.records": 10000,
},
});The timestamp parameter accepts either:
If not provided, the current time is used.
// Using Date object
sendEvent("scheduled_event", {
timestamp: new Date(),
});
// Using Unix timestamp
sendEvent("scheduled_event", {
timestamp: Date.now(),
});
// Using specific date
sendEvent("scheduled_event", {
timestamp: new Date("2024-01-15T10:00:00Z"),
});Critical Behavior:
Events can have different severity levels to indicate their importance:
UNSPECIFIED - No severity specifiedTRACE - Fine-grained debugging informationDEBUG - Debug informationINFO - Informational messages (default for most events)WARN - Warning messagesERROR - Error messagesFATAL - Fatal error messagessendEvent("system_check", { severity: "INFO" });
sendEvent("deprecated_api_used", { severity: "WARN" });
sendEvent("critical_failure", { severity: "ERROR" });Critical Behavior:
UNSPECIFIEDbrowser.page_view, etc.) causes event to be droppedsendEvent() is called before init(), events may be queued or droppedinit() is called multiple times, events are sent to all configured endpointsUNSPECIFIED"info" is not the same as "INFO"UNSPECIFIEDopts.attributes and standard attributes are resolved in favor of standard attributes