Install on Vue
View as MarkdownAdd Reveata to a Vue app built with Vite, with Vue Router in history or hash mode.
On this page
A Vue app built with Vite is served from the index.html at the root of the project, so the snippet goes there once. For Nuxt, see Install on Nuxt.
Copy the snippet from your Reveata dashboard (it contains your website’s tracking id):
<script
defer
data-website-id="ws_your_tracking_id"
src="https://reveata.com/js/script.js"
></script>Add it to your app
Open index.html (next to vite.config.ts) and paste the snippet before </head>:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>My app</title>
<script defer data-website-id="ws_your_tracking_id" src="https://reveata.com/js/script.js"></script>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>Projects made with the older Vue CLI keep this file in public/index.html.
Vue Router
createWebHistory()(URLs like/settings): nothing to add. The script follows the History API, so every route change is a pageview.createWebHashHistory()(URLs like/#/settings): adddata-hash="true"to the tag. Without it every route has the path/, so only the first page is counted.
Check it works
Open your deployed app in a private window, then check that the visit appears in your Reveata dashboard. If it doesn’t, follow Verify your installation. Visits to the Vite development server on localhost are ignored unless you add data-allow-localhost="true".
Goals
In a template, add the attribute to the element:
<template>
<button data-reveata-goal="start_trial" data-reveata-goal-plan="pro">Start free trial</button>
</template>Templates can’t reach window, so to send a goal from code, call the script in your <script setup> block:
<script setup lang="ts">
function startTrial() {
(window as any).reveata?.('goal', 'start_trial', { plan: 'pro' });
}
</script>
<template>
<button @click="startTrial">Start free trial</button>
</template>See Custom goals.
Revenue
Connect your payment provider in Reveata: see Connect a payment provider. Send window.reveata.metadata() to your server with the request that creates the checkout.