SDK reference

Migrate from PostHog

Swap three imports, and your existing PostHog calls for events, identify and flags send to Databuddy instead.

bun remove posthog-js posthog-node
bun add @databuddy/sdk
PostHog importDatabuddy import
posthog-js@databuddy/sdk/posthog
posthog-js/react@databuddy/sdk/posthog/react
posthog-node@databuddy/sdk/posthog/node

Change the imports

analytics.ts
import posthog from "@databuddy/sdk/posthog";

posthog.init(process.env.NEXT_PUBLIC_DATABUDDY_CLIENT_ID!, {
  capture_exceptions: true,
  capture_performance: true,
});

posthog.identify(user.id, { email: user.email, plan: user.plan });
posthog.capture("checkout_completed", { total: 49 });

posthog.onFeatureFlags(() => {
  if (posthog.isFeatureEnabled("new-checkout")) showNewCheckout();
});

Pass your Databuddy client ID where PostHog took a project token. capture_exceptions and capture_performance turn on errors and Web Vitals, and the second argument also takes any Databuddy option. Transport options such as api_host are ignored. onFeatureFlags() runs again after identify() or group() re-evaluates flags.

Check what behaves differently

PostHogIn Databuddy
capture("$pageview"), capture("$pageleave")Ignored; pageviews and exits are recorded on every route change
Nested traits, $set_onceNested objects and arrays are dropped; $set_once is ignored
group(type, key, props)Puts later events and flags in that account, remembered until resetGroups() or reset(). Billing traits are left out; send them with the server's groupIdentify().
captureException(error)Reports to the Errors page, even with capture_exceptions off. Its second argument isn't kept.
alias, startSessionRecording()Warn and return. Use Databuddy's replay option for recordings.
groupIdentify in the browserNot available; pass display properties to group()
before_send, property_denylist, mask_all_text, persistenceRejected by the types, so a migration can't quietly collect more. Use skipPaths, maskPaths, replay: { maskText } and disabled instead.
opt_out_capturing_by_defaultNothing is tracked until opt_in_capturing(); calls made meanwhile are applied once they opt in
opt_out_capturing()Works like optOut(), which also stops your server's events that carry the browser's anonymous ID
respect_dntNo equivalent; call opt_out_capturing() when navigator.doNotTrack === "1"
SurveysNot available

To keep your history, upload a PostHog batch export under Data import in website settings. Databuddy rebuilds pageviews and sessions from $pageview events. See Data import.

How is this guide?