SDK reference

Identify users

Pass your user's ID once they sign in, and their visits join one profile with their name and email.

app/providers.tsx
"use client";

import { DatabuddyProvider } from "@databuddy/sdk/react";

export function Providers({ children }: { children: React.ReactNode }) {
  const { data: session, isPending } = authClient.useSession();
  const user = session?.user;

  return (
    <DatabuddyProvider
      user={user ? { id: user.id, traits: { email: user.email, name: user.name } } : null}
      userPending={isPending}
    >
      {children}
    </DatabuddyProvider>
  );
}

The provider identifies the user when they sign in or their traits change, and resets when they sign out or another user signs in.

Pass a stable ID from your database, at most 128 characters, never an email. Identifying users processes personal data, so you need a lawful basis and a line in your privacy policy.

  1. Anonymous visitor
  2. identify(id)
  3. Profile with name and email
  4. Same person on every device

Set traits

Traits are flat values: strings, numbers, booleans or null. Update them by calling identify() again, and remove one by setting it to null. With the provider, change traits instead.

identify(user.id, { plan: "enterprise", trial_ends_at: null });
TraitShown as
usernameThe display name
nameThe display name when there's no username
emailUnder the name, lowercased
Anything elseOn the user's profile, for filtering and segments
LimitValue
Keys50
Size2,048 characters as JSON
Profile ID128 characters. <, >, ', " and & are removed, so keep them out of IDs

Display names and emails are encrypted at rest.

Attribute revenue to the user

With the Stripe integration, put the user ID in payment metadata:

await stripe.paymentIntents.create({ amount, currency, metadata: { databuddy_profile_id: user.id } });

Group users by company

Users identified with an email are grouped by their work email domain on the Accounts page, with the company's name and logo when they can be found. To group them by your own workspaces, with plan and billing, see Accounts.

How is this guide?