SDK Reference
SDK Overview
The Databuddy SDK provides framework-specific components, helper functions, server-side tracking, and a vanilla JavaScript library for tracking analytics events. Choose your preferred integration method.
Installation
# Using bun (recommended)
bun add @databuddy/sdk
# Using npm
npm install @databuddy/sdkFor vanilla JavaScript, no installation needed - load directly from CDN.
Quick Start
Core Features
Import Paths
The SDK is organized into submodules for tree-shaking:
Example: React/Next.js
import { Databuddy } from "@databuddy/sdk/react";
import { track } from "@databuddy/sdk";
// In your root layout
export default function RootLayout({ children }) {
return (
<html>
<body>
<Databuddy
clientId={process.env.NEXT_PUBLIC_DATABUDDY_CLIENT_ID!}
trackWebVitals
trackErrors
/>
{children}
</body>
</html>
);
}
// In any component
function SignupButton() {
return (
<button onClick={() => track("signup_clicked", { source: "header" })}>
Sign Up
</button>
);
}Example: Node.js
import { Databuddy } from "@databuddy/sdk/node";
const client = new Databuddy({
apiKey: process.env.DATABUDDY_API_KEY!,
websiteId: process.env.DATABUDDY_WEBSITE_ID,
enableBatching: true
});
await client.track({
name: "api_call",
properties: { endpoint: "/api/users", method: "GET" }
});
await client.flush(); // Important in serverless!TypeScript Support
The SDK is fully typed with excellent TypeScript support:
import { track, type DatabuddyTracker } from "@databuddy/sdk";
import type { DatabuddyConfig } from "@databuddy/sdk/react";
import type { CustomEventInput } from "@databuddy/sdk/node";Related Documentation
How is this guide?