Before you start
Create a free Cool Analytics account and add your site. You'll get a site ID — replace YOUR_SITE_ID in the code below with it. The dashboard shows the snippet with your ID already filled in.
Install on Nuxt
- 1Open nuxt.config.ts.
- 2Add the script under app.head.script as shown — note that data-site is passed as an attribute.
- 3Restart the dev server or redeploy. NuxtLink navigation is tracked automatically.
export default defineNuxtConfig({
app: {
head: {
script: [
{ src: "https://coolanalytics.dev/hb.js", defer: true, "data-site": "YOUR_SITE_ID" },
],
},
},
});Check that it works
Open your live site in a new tab, then open your Cool Analytics dashboard. Your visit appears on the live map within seconds — with the page you're on, where you came from and your browser.
Nothing showing up? Make sure you're looking at the published site (not a preview or editor), that an ad blocker isn't blocking the script, and that you're not testing on localhost.
Track signups, purchases and clicks
Pageviews, sources, countries and outbound link clicks are tracked automatically. For the moments that matter to you, send a custom event. Events named like a signup show up as signups, and events with an amount show up as revenue — on the live map and per traffic source.
// anywhere in your Nuxt site's browser code
window.hb?.track("signup");
// with an amount, it shows up as revenue
window.hb?.track("purchase", { amount: 49 });Nuxt tips
- Client-side route changes are tracked automatically — the script listens to the browser history, so there's no router hook to wire up.
- Prefer the config over useHead() in a component: the config applies to every route and can't be accidentally removed with a layout change.
- Visits from localhost are ignored so your own development doesn't count. To test locally, add data-dev="1" to the script tag for a moment — then remove it.
Want to keep your own visits out of the stats? Open your site once with #hb-ignore at the end of the URL. That browser is excluded until you visit with #hb-track.
Nuxt analytics FAQ
Does it work with Nuxt static generation (nuxi generate)?+
Yes. The head config is written into every generated HTML file.
Does it work with Nuxt 3 and Nuxt 4?+
Yes, app.head in nuxt.config.ts works the same in both.
How do I track events in Nuxt?+
From any component, call window.hb?.track('signup'). On the server there's no window, so only call it in client-side handlers.