SDK reference

Vue

Add the <Databuddy> component once, and it records pageviews and identifies the signed-in user.

bun add @databuddy/sdk
App.vue
<script setup lang="ts">
import { Databuddy } from "@databuddy/sdk/vue";

const clientId = import.meta.env.VITE_DATABUDDY_CLIENT_ID;
const { user, workspace, isLoading } = useSession();
</script>

<template>
  <Databuddy
    :client-id="clientId"
    :autocapture="{ webVitals: true, errors: true }"
    :user="user ? { id: user.id, traits: { email: user.email } } : null"
    :user-pending="isLoading"
    :groups="{ workspace: isLoading ? undefined : (workspace?.id ?? null) }"
  />
  <RouterView />
</template>

Using Nuxt? The @databuddy/nuxt module needs no app.vue changes.

Track events

SignupButton.vue
<script setup lang="ts">
import { track } from "@databuddy/sdk";
</script>

<template>
  <button @click="track('signup_clicked', { source: 'header' })">Sign up</button>
</template>

Every function, such as identify, group, reset and getIds, imports from @databuddy/sdk; see Track events.

Component props

Props use kebab-case in templates: clientId becomes :client-id, sampleRate becomes :sample-rate.

PropTypeDefaultWhat it does
client-idstringYour website's client ID
userDatabuddyUser | nullThe signed-in user, or null when signed out. Omit it to call identify() yourself.
user-pendingbooleanfalseThe user is loading; identity and accounts wait
groupsRecord<string, string | null | undefined>The visitor's accounts. A key joins, null leaves, undefined keeps the remembered one.
disabledbooleanfalseSends nothing

Every other option, such as autocapture, batching, skip-paths, mask-paths and replay, is in the configuration reference.

Read feature flags

main.ts
import { createFlagsPlugin } from "@databuddy/sdk/vue";
import { createApp } from "vue";
import App from "./App.vue";

createApp(App)
  .use(createFlagsPlugin({ clientId: import.meta.env.VITE_DATABUDDY_CLIENT_ID }))
  .mount("#app");
Nav.vue
<script setup lang="ts">
import { useFlag } from "@databuddy/sdk/vue";

const { on: newNav, loading } = useFlag("new-nav");
</script>

<template>
  <Skeleton v-if="loading" />
  <NewNav v-else-if="newNav" />
  <OldNav v-else />
</template>

useFlag(key) returns { on, loading, state } as computed refs; in script code, read .value. The plugin needs Vue 3.5 or later. Its options are on Feature flags.

How is this guide?