SDK reference

Upgrade guide

@databuddy/sdk 3.5 adds DatabuddyProvider, so you set your client ID and signed-in user once for tracking, identity and flags.

app/layout.tsx
// Before
<Databuddy clientId="..." trackErrors trackWebVitals />
<FlagsProvider clientId="..." user={{ userId: user.id, email: user.email }} isPending={isPending}>
  {children}
</FlagsProvider>

// After
<DatabuddyProvider
  clientId="..."
  autocapture={{ errors: true, webVitals: true }}
  user={user ? { id: user.id, traits: { email: user.email } } : null}
  userPending={isPending}
>
  {children}
</DatabuddyProvider>

Nothing breaks when you update. The older components, hooks, options and function names still work, and your editor marks them deprecated. The Node client, server flags, /agents and /mcp are unchanged.

Switch to DatabuddyProvider

Pass the signed-in user, or null when signed out. The provider keeps the profile and flag targeting in step, so you no longer call identify() or clearProfile(). A provider without children only loads tracking, and flags load the first time a component reads one.

disabled on DatabuddyProvider also turns off flags, which then serve their defaults. If you passed disabled to <Databuddy /> only to skip development tracking, flags will serve defaults there after you switch.

Read flags with defineFlag

checkout.tsx
import { defineFlag } from "@databuddy/sdk";
import { useFlag, useFlagDetails } from "@databuddy/sdk/react";

export const newCheckout = defineFlag("new-checkout", { default: false });

export function Checkout() {
  // Before: const flag = useFlag("new-checkout"); flag.on
  const enabled = useFlag(newCheckout);
  const { loading } = useFlagDetails(newCheckout);
  if (loading) return <Skeleton />;
  return enabled ? <NewCheckout /> : <OldCheckout />;
}

Both hook forms read from either provider, so you can switch hooks before or after switching providers.

DeprecatedUse instead
useFlag(key)useFlag(flag) for the value, useFlagDetails(flag) for status and variant
useFlags().isOn(key), getValue(key)useFlag(flag)
useFlags().isReady, lastError, refresh()useFlagsStatus()
useFlags().updateUser()The provider's user prop
defaults={{ key: value }}defineFlag(key, { default: value })
isPendinguserPending
user={{ userId, email, organizationId, teamId, properties }}user={{ id, organizationId, teamId, traits }} with email in traits. Traits are saved on the profile and must be flat values.
skipStorageflags={{ persist: false }}
apiUrl (flags API), environmentflags={{ apiUrl, environment }}
autoFetchNot needed
cacheTtl, staleTime, maxCacheSize, requestTimeoutMsNo provider equivalent; keep FlagsProvider if you tune them

Rename functions

DeprecatedUse instead
clear(), clearProfile()reset(), or reset({ keepVisitor: true }) to keep the visitor
setTraits(traits)identify(id, traits)
getAnonymousId(), getSessionId(), getTrackingIds(), getProfileId()getIds()
getTracker(), isTrackerAvailable()Not needed; calls are queued until the tracker loads
createScript(), createReplayScript(), isScriptInjected(), stopScript()init(options), which returns a function that stops tracking
window.databuddyOptOut(), window.databuddyOptIn()optOut(), optIn()
trackError(error, properties)captureException(error), which reports to the Errors page

getRevenueMetadata() no longer needs the client ID. Declare your events to type-check track().

Rename options

These apply to DatabuddyProvider, <Databuddy />, init(), the Vue component and the Nuxt module (@databuddy/nuxt 3.1.0 or later). When both forms are set, the grouped one wins.

DeprecatedUse instead
trackInteractions, trackAttributes, trackOutgoingLinks, trackErrors, trackWebVitals, trackHashChangesautocapture: { interactions, attributes, outgoingLinks, errors, webVitals, hashChanges }, or true / false for all
batchSize, batchTimeoutbatching: { size, timeoutMs }
enableBatchingbatching: false
enableRetries, maxRetries, initialRetryDelayretries: false or { max, initialDelayMs }
samplingRatesampleRate
skipPatterns, maskPatternsskipPaths, maskPaths

The PostHog adapter's posthog.init() takes both forms too. Its autocapture object takes Databuddy's keys, and PostHog's own autocapture: true is ignored.

How is this guide?