SDK reference
Vue
Add the <Databuddy> component once, and it records pageviews and identifies the signed-in user.
bun add @databuddy/sdk<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>Track events
<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.
Every other option, such as autocapture, batching, skip-paths, mask-paths and replay, is in the configuration reference.
Read feature flags
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");<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.
Related
How is this guide?