viakite
Dashboard

SDKs/Frameworks/Vue and Nuxt

Vue and Nuxt

Vue 3 and Nuxt

For Vue 3 and Nuxt, add the <Analytics /> component from @viakite/sdk/vue once, in your root component. It starts tracking when it mounts in the browser and counts every Vue Router or Nuxt route change as a page view.

Install

terminal
1npm install @viakite/sdk
terminal
1pnpm add @viakite/sdk
terminal
1yarn add @viakite/sdk

It needs Vue 3.3 or later. Vue is a peer dependency, so the package adds no second copy.

Vue 3

Add it to src/App.vue:

src/App.vue
1<script setup lang="ts">
2import { Analytics } from "@viakite/sdk/vue";
3</script>
4
5<template>
6 <RouterView />
7 <Analytics project="pk_live_us_…" />
8</template>

It renders nothing. When it mounts, it calls init() with its props.

Nuxt

Add it to app.vue, with <NuxtPage /> in place of <RouterView />:

app.vue
1<script setup lang="ts">
2import { Analytics } from "@viakite/sdk/vue";
3</script>
4
5<template>
6 <NuxtLayout>
7 <NuxtPage />
8 </NuxtLayout>
9 <Analytics project="pk_live_us_…" />
10</template>

It starts on mount, which happens only in the browser, so server rendering is safe. No Nuxt module or plugin is needed.

How it behaves

  • Once per page load. Props that change after it mounts are ignored, and a second component does nothing.
  • Route changes are followed through the browser's history, which Vue Router and Nuxt use: one page view per new path, none when only the query changes. With createWebHashHistory, add hash.
  • Flags that are on by default (outbound, downloads, autoPageviews) stay on when you leave them out.

Send events

Import track, identify and reset from @viakite/sdk in any component:

src/components/SignupButton.vue
1<script setup lang="ts">
2import { track } from "@viakite/sdk";
3</script>
4
5<template>
6 <button @click="track('Signup', { plan: 'pro' })">Start free</button>
7</template>

Calls made before <Analytics /> has mounted are kept and sent once it does. In Nuxt, call them from code that runs in the browser (an event handler or onMounted); on the server they do nothing.

Options

Every option of init() is a prop. Write a value that isn't text with a colon:

src/App.vue
1<Analytics
2 project="pk_live_us_…"
3 title
4 :params="['plan', 'coupon']"
5 :outbound="false"
6/>

In Nuxt, keep the key in runtime config: :project="useRuntimeConfig().public.viakiteKey". Nothing is sent from localhost; add debug to see events in the console, or localhost to send them. All props: Options.

Next steps