This quickstart adds Trace to a Vue 3 app with @trace-id/sdk-vue. You install a plugin once, identify the visitor in a component, and send the eventId to your backend for verification. It works the same in Nuxt.
Before you start
You need a running Trace server and a public key (pk_...) whose allowed origins include your app. The quick start guide covers both.
- 1
Install the SDK
npm install @trace-id/sdk-vuepnpm add @trace-id/sdk-vueyarn add @trace-id/sdk-vuebun add @trace-id/sdk-vue - 2
Install the plugin
TypeScript// main.ts import { createApp } from 'vue'; import { createIdentify } from '@trace-id/sdk-vue'; import App from './App.vue'; createApp(App) .use(createIdentify({ apiKey: import.meta.env.VITE_TRACE_PUBLIC_KEY, endpoint: import.meta.env.VITE_TRACE_ENDPOINT })) .mount('#app');In Nuxt, do the same in a client-only plugin (
plugins/trace.client.ts) withnuxtApp.vueApp.use(createIdentify({ ... })). - 3
Identify on submit
useVisitorDatareturns refs:data,error,isLoading, and agetDatafunction.Vue<!-- SignupForm.vue --> <script setup lang="ts"> import { ref } from 'vue'; import { useVisitorData } from '@trace-id/sdk-vue'; const email = ref(''); const { getData, isLoading } = useVisitorData({ immediate: false }); async function submit() { const result = await getData({ tags: { action: 'signup' } }); // null if Trace is unavailable await fetch('/api/signup', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: email.value, eventId: result?.eventId }), }); } </script> <template> <form @submit.prevent="submit"> <input v-model="email" type="email" required /> <button :disabled="isLoading">Create account</button> </form> </template>getDatanever throws. On failure it resolvesnulland setserrorto anIdentifyErrorwith acode. - 4
Verify on your server