Skip to main content
Before starting: Get your API key from the Settings page

Step 1 — Install the SDK

npm install analytiq

Step 2 — Initialize in src/main.js (One-time setup)

Open src/main.js. This is the only file you need to change for the core setup. Add the init() call before you mount the app.
src/main.js
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import { init, track } from 'analytiq'

// Initialize the SDK once before mounting the app
init(import.meta.env.VITE_ANALYTIQ_KEY)

// Optional: Track page views on every Vue Router navigation
router.afterEach((to) => {
  track('page_view', { path: to.path })
})

const app = createApp(App)
app.use(router)
app.mount('#app')
Add your API key to .env:
VITE_ANALYTIQ_KEY=pk_live_your_actual_key_here
That’s the core setup! You can now track events from anywhere in your app.

What the SDK handles automatically

ActionWhat happens
App initializesinit() runs once, anonymous tracking begins
User goes offlineEvents saved to localStorage, retried on reconnect

Step 3 — Identify users and reset on logout

Vue doesn’t use hooks, so you call identify() and reset() directly. The best place is your Pinia store or auth composable:

Step 4 — Track Custom Events

For specific actions (button clicks, purchases, etc.), import track() in any component:
src/components/PricingCard.vue
<script setup>
import { track } from 'analytiq'

function handleUpgrade(plan) {
  track('upgrade_clicked', { plan: plan.name, price: plan.price })
  // your existing upgrade logic...
}
</script>

<template>
  <button @click="handleUpgrade(plan)">Upgrade to {{ plan.name }}</button>
</template>

Step 5 — Verify it’s working

  1. Run: npm run dev
  2. Open your browser, Press F12 and go to Console
  3. You should see:
[analytiq] Initialized successfully. {host: "...", userId: null}
[analytiq] Auto page view tracking enabled.
  1. Navigate between pages in your app
  2. Go to your Analytiq DashboardEventspage_view events appear within 10 seconds.