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 import | Databuddy 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
| PostHog | In Databuddy |
|---|---|
capture("$pageview"), capture("$pageleave") | Ignored; pageviews and exits are recorded on every route change |
Nested traits, $set_once | Nested 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 browser | Not available; pass display properties to group() |
before_send, property_denylist, mask_all_text, persistence | Rejected by the types, so a migration can't quietly collect more. Use skipPaths, maskPaths, replay: { maskText } and disabled instead. |
opt_out_capturing_by_default | Nothing 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_dnt | No equivalent; call opt_out_capturing() when navigator.doNotTrack === "1" |
| Surveys | Not 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.
Related
How is this guide?