Accounts
The Accounts page groups users by the workspace or company they work in, and shows each account's activity, plan and billing.
<DatabuddyProvider
user={user ? { id: user.id, traits: { email: user.email } } : null}
groups={{ workspace: session?.activeWorkspaceId ?? null }}
>
{children}
</DatabuddyProvider>Users you identify with an email trait are also grouped by their work email domain with no setup. Personal addresses and your own team's domain are left out.
Put users in an account
Later events carry group_workspace: <key>. A visitor is in one account of each type, and the SDK remembers it across visits until reset() or optOut(). Types use lowercase letters, digits and underscores; email_domain is reserved, and keys over 256 characters are skipped with a warning. getGroups() returns the visitor's accounts to send to your server.
When the workspace is in the URL, such as /w/[workspaceId], pass it on the first render. Every tab shares the remembered account, so a key that arrives late sends the first pageview to whichever workspace another tab used last.
Name the account and say how it pays
The browser can send display traits. Anyone can send requests with your client ID, so billing, dates and usage are accepted only from your server with an API key.
group("workspace", workspace.id, { name: workspace.name, domain: workspace.domain });await databuddy.group({
groupType: "workspace",
groupKey: workspace.id,
traits: { billing_plan: "pro", billing_status: "active", billing_mrr: 49, billing_currency: "USD" },
});The browser's group() leaves server-only traits out with a warning. What each trait does is listed under the Node SDK's group(). Always send billing_currency with billing_mrr, or MRR shows as a plain number and isn't added up.
Billing from Stripe
Put databuddy_group_<type> in the subscription's metadata, or in subscription_data.metadata with Checkout, and Stripe keeps that account's plan, status, MRR, currency, trial end and customer current.
await stripe.subscriptions.create({
customer,
items: [{ price: priceId }],
metadata: { databuddy_group_workspace: workspace.id },
});getRevenueMetadata() also returns these keys, but a buyer can edit what their browser sends. Take only the visit IDs from the checkout request, as in Payments.
Target flags at accounts
Flags see the visitor's accounts as group_<type> properties, so a rule like group_workspace equals ws_123 targets everyone in that workspace. To roll out by account, choose its type under Accounts in the flag's Bucket by. On the server, pass groups in the user context, and pass the same groups to evaluateFlags() as to the provider.
Send what each kind of product needs
await databuddy.group({
groupType: "workspace",
groupKey: workspace.id,
traits: { plan_usage: usage.thisPeriod, plan_limit: plan.includedUnits, usage_30d: usage.last30Days, last_active_at: lastRequestAt },
});Related
How is this guide?