Vue.js (Vite / Client-Side)
Add Rybbit analytics to your Vue app
A client-side Vue app built with Vite (npm create vue@latest or npm create vite@latest -- --template vue) serves a single index.html at the project root. Add the snippet there and it loads on every route.
Get your tracking snippet
In your Rybbit dashboard, open Site Settings → Tracking Script and copy your snippet. It looks like this:
<script src="https://app.rybbit.io/api/script.js?siteId=YOUR_SITE_ID" defer></script>YOUR_SITE_ID is the numeric ID of your site. If you self-host Rybbit, app.rybbit.io is the domain of your own instance.
Add the snippet to Vue.js
Open index.html at the root of your project and paste the snippet inside <head>:
<!doctype html>
<html lang="en">
<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.rybbit.io/api/script.js?siteId=YOUR_SITE_ID" defer></script>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>Placing it just before </body> also works, but <head> lets the script start loading sooner.
Verify installation
Open your live site in a new tab and click through a few pages. Within a few seconds the pageviews appear in the Rybbit dashboard.
If nothing shows up:
- View the page source and search for
script.js?siteId=to confirm the snippet is on the page. - Open the browser Network tab and check that
script.jsreturns200and thatPOSTrequests go to/api/track. - Disable ad blockers, or set up a proxy so the script loads from your own domain.
- See the script troubleshooting guide for other common causes.
Track custom events
Call window.rybbit.event() from any component or method:
<template>
<button @click="trackAction">Track action</button>
</template>
<script setup>
function trackAction() {
if (window.rybbit) {
window.rybbit.event("custom_vue_action", { detail: "User performed an action" });
}
}
</script>Troubleshooting
-
Pageviews missing after navigation: Rybbit tracks Vue Router navigations automatically, so test the default first. If a route change is still not recorded, trigger it from an
afterEachguard in your router setup:src/router/index.js import { createRouter, createWebHistory } from "vue-router"; const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes: [/* your routes */], }); router.afterEach(() => { if (window.rybbit) { window.rybbit.pageview(); } }); export default router;
Next steps
- Track custom events such as signups, purchases and button clicks.
- Identify users to connect sessions to accounts.
- Proxy the script through your own domain to bypass ad blockers.
- Script attributes let you skip or mask URLs and tag events.