Browser telemetry SDK for monitoring page views, errors, web vitals, and HTTP requests with OpenTelemetry integration
npx @tessl/cli install tessl/npm-dash0hq--sdk-web@0.18.0Browser telemetry SDK for monitoring page views, errors, web vitals, and HTTP requests with OpenTelemetry integration.
@dash0/sdk-webnpm install @dash0/sdk-webimport { init } from "@dash0/sdk-web";
init({
serviceName: "my-website",
endpoint: {
url: "https://ingress.dash0.com",
authToken: "auth_your_token_here",
},
});Critical: Call init() early in page lifecycle (ideally in <head>) before other SDK functions.
See Quick Start Guide for detailed setup instructions.
The SDK automatically collects:
Sessions are automatically tracked with configurable timeouts:
Send custom events, report errors, and identify users:
import { sendEvent, reportError, identify } from "@dash0/sdk-web";
// Custom events
sendEvent("purchase_completed", {
attributes: { "order.id": "123" },
});
// Error reporting
reportError(error, {
attributes: { "user.id": userId },
});
// User identification
identify("user-123", {
email: "user@example.com",
roles: ["admin"],
});| Function | Purpose | Link |
|---|---|---|
init() | Initialize SDK | Reference |
identify() | Associate user with telemetry | Reference |
sendEvent() | Send custom events | Reference |
reportError() | Manually report errors | Reference |
addSignalAttribute() | Add attributes to all signals | Reference |
removeSignalAttribute() | Remove signal attributes | Reference |
terminateSession() | End current session | Reference |
setActiveLogLevel() | Configure logging verbosity | Reference |
debug() | Inspect SDK configuration | Reference |
import { init, identify, sendEvent } from "@dash0/sdk-web";const { init, identify, sendEvent } = require("@dash0/sdk-web");<script>
(function(d,a,s,h,z,e,r,o){d[a]||((z=d[a]=function(){h.push(arguments);}),(z._t=new Date()),(z._v=1),(h=z._q=[]));})(window,"dash0");
dash0("init", {
serviceName: "my-website",
endpoint: { url: "...", authToken: "..." },
});
</script>
<script defer crossorigin="anonymous" src="https://unpkg.com/@dash0/sdk-web/dist/dash0.iife.js"></script>All types are exported and available:
import type {
AttributeValueType,
AnyValue,
PageViewMeta,
PropagatorConfig,
LogLevel,
} from "@dash0/sdk-web";
// Access function parameter types
import type { init } from "@dash0/sdk-web";
type InitOptions = Parameters<typeof init>[0];Required APIs: fetch, localStorage/sessionStorage, Performance, Promise, URL
Supported: Chrome 90+, Firefox 88+, Safari 14+, Edge 90+, modern mobile browsers
Not Supported: IE11, browsers without Promise/fetch support
See Browser Compatibility for details.
import { init } from "@dash0/sdk-web";
import { useEffect } from "react";
function App() {
useEffect(() => {
init({
serviceName: "my-react-app",
endpoint: { url: "...", authToken: "..." },
});
}, []);
// ...
}import { reportError } from "@dash0/sdk-web";
class ErrorBoundary extends React.Component {
componentDidCatch(error, errorInfo) {
reportError(error, {
componentStack: errorInfo.componentStack,
});
}
}import { identify } from "@dash0/sdk-web";
async function handleLogin(user) {
identify(user.id, {
email: user.email,
roles: user.roles,
});
}See Real-World Scenarios for more patterns.