About five minutes, on the free plan, without a credit card.
1
Install the SDK
Vue uses the OpenPanel web SDK directly. There is no @openpanel/vue package.
npm install @openpanel/web
2
Create a shared instance
Create one OpenPanel instance for the whole app. Setting apiUrl is required, because the SDK otherwise defaults to OpenPanel's own hosted endpoint.
// src/lib/op.ts
import { OpenPanel } from '@openpanel/web';
export const op = new OpenPanel({
clientId: 'YOUR_CLIENT_ID',
apiUrl: 'https://api.privytics.com',
trackScreenViews: true,
trackOutgoingLinks: true,
trackAttributes: true,
});
3
Initialise it on app load
Import the module in your entry point so the instance is created when the app boots. That alone starts automatic screen view tracking.
// src/main.ts
import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import './lib/op'; // initialise Privytics
const app = createApp(App);
app.use(router);
app.mount('#app');
4
Track an event in a component
Import the instance and call track with an event name and an optional properties object. To link events to a logged-in user, call op.identify with a single object that has a profileId, for example op.identify({ profileId: user.id }), when you have a lawful basis for it.
<template>
<button type="button" @click="handleClick">Sign up</button>
</template>
<script setup lang="ts">
import { op } from '../lib/op';
function handleClick() {
op.track('button_clicked', {
button_name: 'signup',
button_location: 'hero',
});
}
</script>
5
Optional: track routes with a Vue Router guard
Use this only if you want route names or params on the event. Set trackScreenViews to false in step 2 when you do, otherwise every navigation is counted twice.
// src/router/index.ts
import { createRouter, createWebHistory } from 'vue-router';
import { op } from '../lib/op';
import routes from './routes';
const router = createRouter({
history: createWebHistory(),
routes,
});
router.afterEach((to) => {
op.track('screen_view', {
path: to.path,
name: String(to.name),
});
});
export default router;