Skip to main content
To add CrispStats to a Nuxt app, add the script to app.head.script in nuxt.config.ts. In a plain Vue app built with Vite, paste the tag into index.html. Vue Router and Nuxt navigate through the History API, so route changes are counted as pageviews with no extra code. You need your site’s public key, which starts with cs_pk_. Find it in your site’s settings under Tracking code. The key is safe to publish.

Nuxt

1

Add the script to nuxt.config.ts

Add an entry to app.head.script. Nuxt renders it into the <head> of every page:
nuxt.config.ts
Replace cs_pk_xxxxxxxx with your public key. If your config already has an app.head block, add the entry to its script array.
2

Turn on more tracking (optional)

Add each option as a key with an empty string value, which switches it on:
nuxt.config.ts
The switches in Settings, Tracking code add data-outbound, data-downloads, data-vitals, data-errors and data-404 to the generated file. Leave Hash routing off: this framework routes with real paths, and data-hash only reads routes written after #. Script attributes lists every attribute the script reads, including data-exclude and data-domains, and what each one does.

Plain Vue

In a Vue app created with Vite, index.html sits at the project root. Add the tag inside <head>:
index.html
Keep the CrispStats tag a classic script with defer: type="module" does not work for it, because the script reads its options from its own tag. If your router uses createWebHashHistory(), add data-hash to the tag. Without it, the part of the URL after # is never sent, so every route is counted as the same page. With createWebHistory() you need nothing extra.

Send custom events

The script installs a global function, window.crispstats. Call it from a component:
UpgradeButton.vue
In a TypeScript project, save crispstats.d.ts from TypeScript where your tsconfig includes it, for example src/crispstats.d.ts in a Vite project or app/crispstats.d.ts in Nuxt 4. It types every method of the global. For calls made before the script loads, run the queue stub there from a client plugin, plugins/crispstats.client.ts. The optional call (?.) keeps the button working when an ad blocker stops the script from loading. You can also track clicks with data-cs-event attributes and no JavaScript, see declarative events.

Confirm it works

Pages on localhost, 127.0.0.1 and file:// are ignored, so a visit to nuxt dev or the Vite dev server is not counted. Deploy, then open your production site in a browser without an ad blocker.
  • In your browser’s developer tools, the Network tab shows a POST request to https://in.crispstats.com/e on each page load and each route change. The collector answers 202.
  • In CrispStats, your site’s Tracking code settings tab shows Receiving events. with the time of the last event.
To see events locally, add "data-debug": "" to the Nuxt entry (or data-debug to the tag) and localhost to data-domains while you develop: every event is logged in the console and nothing is sent. Remove both before you ship. See localhost and testing.

Next steps

Custom events

Track signups, clicks and other actions with properties.

Single-page apps

How client navigation, hash routing and engagement are tracked.

Script attributes

Every attribute the script reads, with examples.
Last modified on November 18, 2026