Getting Started
This guide takes you from a new Databuddy account to your first tracked page view.
Try Databuddy with Leap
Let Leap generate a complete application that uses Databuddy for analytics.
Examples:
1
Create Your Account
2
Install the SDK
Choose the install method for your app:
Install the official Databuddy SDK:
# Using bun (recommended)
bun add @databuddy/sdk
# Using npm
npm install @databuddy/sdk
# Using yarn
yarn add @databuddy/sdkFor any website, use the script tag method:
<script
src="https://cdn.databuddy.cc/databuddy.js"
data-client-id="your-client-id"
data-track-performance
async
></script>3
Add Tracking
Add the <Databuddy /> component once in your root layout:
import { Databuddy } from "@databuddy/sdk/react";
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<head />
<body>
<Databuddy
clientId={process.env.NEXT_PUBLIC_DATABUDDY_CLIENT_ID!}
trackPerformance
trackWebVitals
trackErrors
/>
{children}
</body>
</html>
);
}Environment Variables:
NEXT_PUBLIC_DATABUDDY_CLIENT_ID=your-client-idAdd the script to your HTML before the closing </body> tag:
<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
</head>
<body>
<!-- Your content -->
<!-- Databuddy Analytics -->
<script
src="https://cdn.databuddy.cc/databuddy.js"
data-client-id="your-client-id"
data-track-performance
data-track-web-vitals
data-track-errors
async
></script>
</body>
</html>4
Verify Installation
Check that page tracking works:
Track Your First Custom Event
"use client";
import { track } from "@databuddy/sdk";
export function SignupButton() {
return (
<button
onClick={() =>
track("signup_clicked", {
location: "header",
plan: "free",
})
}
type="button"
>
Sign up
</button>
);
}<script>
function trackSignupClick() {
db.track("signup_clicked", {
location: "header",
plan: "free",
});
}
</script>
<button onclick="trackSignupClick()">Sign up</button>What's Next?
Troubleshooting
Not seeing data in your dashboard?
How is this guide?