Skip to content
Frameworks

Vue.js analytics with Vue Router support

2 min read · Updated · By the Reveata team

Short answerPaste the Reveata snippet before the closing head tag of your Vue app's index.html. With createWebHistory every route change is a pageview automatically; with createWebHashHistory add data-hash="true". Goals and checkout ids come from your script setup blocks.

A Vue app built with Vite is served from one index.html, and Vue Router changes pages in the browser. Reveata needs one tag in that file and, for hash routing, one attribute.

What you get

  • Every route counted as a pageview, with no router hooks.
  • Goals from templates (an attribute) or from code.
  • Revenue attribution by sending the visitor id with the checkout request.
  • Development visits left out: the Vite server on localhost is ignored unless you allow it.

How to install it

Open index.html next to vite.config.ts (projects made with the older Vue CLI keep it in public/index.html) and paste the snippet before </head>. Then choose by router mode:

Vue Router mode URLs look like What to add
createWebHistory() /settings Nothing
createWebHashHistory() /#/settings data-hash="true" on the tag

Without data-hash in hash mode, every route has the path /, so only the first page is counted. The two modes are explained in Vue Router's history mode guide (opens in a new tab). For Nuxt, see Nuxt analytics.

Goals in templates and code

In a template, add the attribute: <button data-reveata-goal="signup">. Templates can't reach window, so to send a goal from code, call the script in <script setup>:

js
function onSignup() {
  window.reveata?.('goal', 'signup');
}

Linking payments to visits

Connect your payment provider in Reveata (connect a payment provider), then send window.reveata.metadata() with the request that creates the checkout. Your server puts reveata_visitor_id and reveata_session_id into the checkout's metadata or custom data, and the payment is credited to the visit. Links to Stripe Payment Links need no code at all (Stripe Payment Links analytics).

Frequently asked questions

Do I need a Vue plugin?

No. The script follows the History API itself, so there is nothing to register in your app.

Why does only my home page show up?

You are probably using hash history. Add data-hash="true" to the tag.

Can I test on my machine?

Add data-allow-localhost="true" while testing and remove it before you deploy, so development visits don't reach your numbers.

See it with your own numbersReveata ties every visit and sale to the source that brought it. Add your website in a minute.
Get started
Was this page useful?
IntegrationNuxt analytics with ReveataAdd the Reveata script to app.head in your Nuxt config, either as a plain script entry or built with the @reveata/next/snippet helper, which has no React or Next dependency. Route changes are tracked by the script, and goals use window.reveata or trackGoal.IntegrationAngular analytics with ReveataPaste the Reveata snippet before the closing head tag of src/index.html. ng build keeps it in the built page, server-side rendering included, and the Angular Router's History API navigation is counted automatically. HashLocationStrategy needs data-hash="true".IntegrationAstro analytics with revenue attributionPaste the Reveata snippet with is:inline into the Astro layout that renders the head of every page. Astro then leaves the tag as written, view transitions are tracked, and payment links or checkouts started from your pages are credited to the visit behind them.IntegrationDjango analytics with revenue attributionPaste the Reveata snippet before the closing head tag of the base template your Django templates extend. Every page is tracked, the Django admin is not, and two hidden form fields let your checkout view put the visitor id into the payment's metadata.IntegrationDocusaurus analytics for documentation sitesAdd the Reveata script to the scripts array in docusaurus.config.js, or build the entry with @reveata/next/snippet. Page changes inside the docs are tracked by the script, so every page a reader opens is counted.IntegrationExpress.js analytics with a first-party proxyPaste the Reveata snippet into the layout, static HTML or front-end index.html your Express app serves. Two Express routes can serve the script from your own domain with your proxy secret, and your checkout route can copy the visitor id into the checkout metadata.