Get started with Dash0 Web SDK in minutes.
npm 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() as early as possible in your page lifecycle, ideally in the <head> section or immediately after opening <body>.
Recommended (in <head>):
<!DOCTYPE html>
<html>
<head>
<script>
// Initialize SDK early
import { init } from "@dash0/sdk-web";
init({
serviceName: "my-website",
endpoint: {
url: "https://ingress.dash0.com",
authToken: "auth_your_token_here",
},
});
</script>
</head>
<body>
<!-- Your app -->
</body>
</html>React:
import { useEffect } from "react";
import { init } from "@dash0/sdk-web";
function App() {
useEffect(() => {
init({
serviceName: "my-react-app",
endpoint: {
url: "https://ingress.dash0.com",
authToken: "auth_your_token_here",
},
});
}, []);
return <div>Your app</div>;
}Next.js (in _app.tsx or _app.js):
import { useEffect } from "react";
import { init } from "@dash0/sdk-web";
export default function App({ Component, pageProps }) {
useEffect(() => {
init({
serviceName: "my-nextjs-app",
endpoint: {
url: "https://ingress.dash0.com",
authToken: "auth_your_token_here",
},
});
}, []);
return <Component {...pageProps} />;
}If you're not using a bundler:
<script>
// Queue function - must be defined before SDK loads
(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");
// Queue initialization
dash0("init", {
serviceName: "my-website",
endpoint: {
url: "https://ingress.dash0.com",
authToken: "auth_your_token_here",
},
});
</script>
<script defer crossorigin="anonymous" src="https://unpkg.com/@dash0/sdk-web/dist/dash0.iife.js"></script>After initialization, check the browser console for SDK logs (if log level is set to debug):
import { setActiveLogLevel, debug } from "@dash0/sdk-web";
// Enable debug logging
setActiveLogLevel("debug");
// Inspect configuration
debug();init() is called before other SDK functionsserviceName and endpoint are providedSee Edge Cases for more troubleshooting.