Skip to content
measure

Add privacy-first analytics to your Nuxt 3 app

Set up Measure in Nuxt 3 — no cookies, one small script, works with Nuxt routing, useHead and SSR. No modules to install.

Guides3 min readBy Measure team

Nuxt 3 makes it easy to build fast, SEO-friendly Vue applications. But most analytics solutions undo that work — a typical cookie-based tool loads a heavy JavaScript bundle, sets cookies, and comes with a consent banner that hurts Core Web Vitals.

Measure is one small script (about 2.5KB unminified) with no cookies, so there’s no cookie banner needed for it. It counts humans, AI agents and bots separately, and it has an MCP server so your AI coding tools can query your traffic directly. Here’s the Nuxt 3 setup.

Use Nuxt’s useHead composable to add the script to every page:

Vue
<!-- app.vue -->
<script setup>
const config = useRuntimeConfig()

useHead({
  script: [
    {
      defer: true,
      src: `https://lets.measure.events/api/script/${config.public.measureTrackingId}`
    }
  ]
})
</script>

<template>
  <NuxtPage />
</template>

Add your tracking ID to nuxt.config.ts:

TypeScript
// nuxt.config.ts
export default defineNuxtConfig({
  runtimeConfig: {
    public: {
      measureTrackingId: 'YOUR_TRACKING_ID'
    }
  }
})

That’s the whole client-side setup. The script tracks the first page load, then hooks the browser’s history API, so every Nuxt route change (pushState) and back/forward navigation (popstate) is counted as a pageview automatically. It also records time on page. You don’t need a router afterEach hook.

Option 2: nuxt.config.ts app.head

If you’d rather keep it out of your components entirely:

TypeScript
// nuxt.config.ts
export default defineNuxtConfig({
  app: {
    head: {
      script: [
        { defer: true, src: 'https://lets.measure.events/api/script/YOUR_TRACKING_ID' }
      ]
    }
  }
})

Tracking conversions

The script doesn’t expose a JavaScript API for custom events — it’s pageviews only, by design. Two ways to track the things that matter:

Use a path. Send people to a real page after the action — /thanks, /welcome, /checkout/complete — and that path’s pageviews are your conversion count.

Send it from the server. For things like completed payments, post an event to the REST API from a Nitro server route. Keep the API key (it starts with mk_) on the server:

TypeScript
// server/utils/measure.ts
export async function recordMeasureEvent(path: string) {
  await $fetch('https://lets.measure.events/api/v1/events', {
    method: 'POST',
    headers: { Authorization: `Bearer ${process.env.MEASURE_API_KEY}` },
    body: { site_key: process.env.MEASURE_TRACKING_ID, path }
  })
}

// e.g. in server/api/stripe-webhook.post.ts
// await recordMeasureEvent('/events/subscription-started')

Static generation (nuxi generate)

If you’re using nuxi generate for static site generation, the tracking script works perfectly. Each generated HTML page includes the script tag, and page loads are tracked automatically. Navigation between pre-rendered pages goes through the client router, which the script already follows.

Why not a typical analytics module?

The usual Nuxt analytics modules add a heavy third-party payload to every page. They need cookie consent management (usually another module). And they give you a dashboard you have to visit manually.

Measure is a small script, uses no cookies, and the MCP server means your AI tools can answer questions like “which blog posts got the most traffic this week?” without you opening a browser tab.

For Nuxt developers shipping production apps where performance and privacy matter, that’s a meaningful difference.

Nuxt Content integration

If you’re using @nuxt/content for a blog or docs site, Measure automatically tracks every content page. No additional configuration needed beyond the base setup. The tracking script captures the rendered URL, which includes your content routes.

To see which content pages perform best, use the Measure dashboard or ask via MCP:

Code
"What are my top blog posts by pageviews this week?"

Getting started

  1. Sign up at lets.measure.events — $29/month covers 40 sites, with a 14-day trial
  2. Add the script with useHead (or app.head) and your tracking ID
  3. Optional: connect the MCP server (https://lets.measure.events/mcp) for AI-powered analytics

Setup time: under 5 minutes. No npm packages to install. No build step impact.

Let your agent read the numbers.

$29 a month covers 40 sites, then $0.50 a site. 14-day trial.