Upgrade guide
@databuddy/sdk 3.5 adds DatabuddyProvider, so you set your client ID and signed-in user once for tracking, identity and flags.
// 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>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
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.
Rename functions
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.
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.
Related
How is this guide?