SDK Reference

SDK Overview

The Databuddy SDK provides framework-specific components, helper functions, and a vanilla JavaScript library for tracking analytics events. Choose your preferred integration method.

Installation

bash
# Using bun (recommended)
bun add @databuddy/sdk

# Using npm
npm install @databuddy/sdk

For vanilla JavaScript, no installation needed - load directly from CDN.

Quick Start

Core Features

Import Paths

The SDK is organized into submodules for tree-shaking:

ImportDescription
@databuddy/sdkCore tracker helpers (track, flush, etc.)
@databuddy/sdk/reactReact component and hooks
@databuddy/sdk/vueVue component and composables
@databuddy/sdk/nodeNode.js server-side SDK
@databuddy/ai/vercelAI/LLM observability (separate package)

Example: React/Next.js

tsx
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

tsx
import { Databuddy } from "@databuddy/sdk/node";

const client = new Databuddy({
clientId: process.env.DATABUDDY_CLIENT_ID!,
enableBatching: true
});

await client.track({
name: "api_call",
properties: { endpoint: "/api/users", method: "GET" }
});

await client.flush(); // Important in serverless!

Example: AI/LLM Tracking

tsx
import { createTracker } from "@databuddy/ai/vercel";
import { openai } from "@ai-sdk/openai";
import { generateText } from "ai";

const { track } = createTracker({
apiKey: process.env.DATABUDDY_API_KEY
});

const result = await generateText({
model: track(openai("gpt-4o")),
prompt: "Hello, world!"
});

TypeScript Support

The SDK is fully typed with excellent TypeScript support:

tsx
import { track, type DatabuddyTracker } from "@databuddy/sdk";
import type { DatabuddyConfig } from "@databuddy/sdk/react";
import type { CustomEventInput } from "@databuddy/sdk/node";

How is this guide?