Vue.js (Vite / Client-Side)
Add OnyxMetric analytics to your Vue app
A client-side Vue app from Vite (npm create vue@latest, or the vue template of npm create vite@latest) has one index.html at the root. Add the tag there and it loads on every route.
Copy your tracking snippet
In OnyxMetric, open your site's Site Settings and copy the tracking script. It looks like this:
<script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>YOUR_SITE_ID is the numeric ID of your site.
Add the snippet to Vue.js (Vite / Client-Side)
Open index.html and add the tag inside <head>:
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>My Vue App</title>
<script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>
</head>Before </body> also works, but <head> starts loading sooner.
Check that it works
Load your live site and click through a few pages. Pageviews show up in the OnyxMetric dashboard within seconds.
If nothing arrives:
- View the page source and search for
script.js?siteId=to confirm the tag is present. - In the browser's Network tab, check that
script.jsreturns200and that requests go to/api/track. - Turn off ad blockers, or proxy the script through your own domain.
- Read script troubleshooting for other causes.
Track custom events
<template>
<button @click="trackAction">Track action</button>
</template>
<script setup>
function trackAction() {
window.onyx?.event("custom_vue_action", { detail: "User performed an action" });
}
</script>Troubleshooting
-
Missing pageviews after navigation: Vue Router navigation is tracked automatically, so test that first. If a route change is still missed, add an
afterEachguard:src/router/index.js router.afterEach(() => { window.onyx?.pageview(); });
Next steps
- Track custom events such as signups, purchases, and clicks.
- Identify users to tie sessions to accounts.
- Proxy the script through your own domain to get past ad blockers.
- Script attributes let you skip or mask URLs and tag events.