Frameworks
Nuxt analytics with CrispStats
In a Nuxt app, analytics is one entry in app.head.script in nuxt.config.ts: add the CrispStats script there and deploy. Nuxt renders it into the head of every page, and client-side navigation goes through the History API, so route changes are counted with no module, plugin or middleware.
Updated
Set up CrispStats on Nuxt
- 01
Step 1: Find your public key
In the dashboard, open your site’s Settings and select Tracking code. Your public key starts with
cs_pk_and is safe to publish. - 02
Step 2: Add the script to nuxt.config.ts
Add an entry to
app.head.script. Nuxt’sapp.headsets head tags for the whole app, so the tag is on every page, server-rendered or not. Replace the key and domain with yours. If the config already has anapp.headblock, add the entry to itsscriptarray.Replace the highlighted values with your own.
nuxt.config.tsexport default defineNuxtConfig({app: {head: {script: [{src: "https:// in. crispstats. com/ d. js",defer: true,"data-site": "cs_pk_your_site_key","data-domains": "example.com",},],},},}); - 03
Step 3: Turn on more tracking (optional)
Each option is a key with an empty string value, which switches it on. The switches in Settings, Tracking code add
data-outbound,data-downloads,data-vitals,data-errorsanddata-404. Leave Hash routing off: Nuxt routes with real paths.nuxt.config.tsexport default defineNuxtConfig({app: {head: {script: [{src: "https:// in. crispstats. com/ d. js",defer: true,"data-site": "cs_pk_your_site_key","data-domains": "example.com","data-outbound": "","data-vitals": "","data-errors": "",},],},},}); - 04
Step 4: Send a custom event (optional)
Call the global
window.crispstatsfrom a component. The optional call (?.) keeps the button working when an ad blocker stops the script. In TypeScript, savecrispstats.d.tsfrom the TypeScript page asapp/crispstats.d.tsin Nuxt 4. To keep calls made before the script loads, run the queue stub from a client plugin,plugins/crispstats.client.ts.components/UpgradeButton.vue<script setup lang="ts">function upgrade() {window.crispstats? . ( "upgrade clicked", { from: "settings" });}</script><template><button @click= "upgrade">Upgrade</ button></template> - 05
Step 5: Deploy and open the live site
Pages on
localhostare ignored, so a visit tonuxt devis not counted. Deploy, then open your production site in a browser without an ad blocker.
Check that it works
In your browser’s developer tools, the Network tab shows a POST to https://in.crispstats.com/e on each page load and each route change, and the collector answers 202. In the dashboard, the site’s Tracking code tab shows Receiving events. with the time of the last event, and the visit appears on Realtime. To see events locally, add "data-debug": "" to the entry and localhost to data-domains while you develop: each event is logged in the console and nothing is sent. Remove both before you ship. See localhost and testing.
CrispStats on Nuxt
What you get
- A pageview for the first load and for every
<NuxtLink>,navigateTo()and back-button navigation, with the previous page as referrer. - Entry pages by source, so you see which server-rendered page search and AI assistants such as ChatGPT send people to first.
- A core script of about 2.2 KB gzipped, loaded with
defer, so it never delays the first paint of a server-rendered page. - Optional web vitals (LCP, INP and CLS at p75), JavaScript errors, outbound links, downloads and 404 pages.
- Revenue by source once you pass
crispstats.id()to your checkout: see Stripe revenue attribution.
- A pageview for the first load and for every
Notes and limits
- CrispStats does not publish a Nuxt module. The config entry is the whole install, with nothing to update.
- Write each flag in the config object with an empty string,
"data-vitals": "", as above. Some flags, such asdata-downloads, read their value as a list, so a stray value changes what they do. - Keep
defer: trueand do not settype: "module": the script reads its options from its own tag. - The script only runs in the browser. Server rendering, prerendering and static generation all ship the tag in the HTML, and the script counts the page when a visitor opens it.
- Query strings are cut to UTM and a few other parameters before a URL is compared, so a filter change in the query is not a new pageview. Keep more with
data-keep-params. - To count visitors whose ad blocker stops the collector host, serve the script from your own domain through your host: see proxy by host.
The docs page covers the optional steps this guide leaves out.
Setup questions. Straight answers.
What people ask before they connect it.
No. CrispStats is one entry in app.head.script in nuxt.config.ts. There is no module to install, and route changes are counted without a plugin or route middleware.
The documented install is app.head in nuxt.config.ts, which puts the tag on every page with no code in your components. The tag only needs to be in the head once per page, with defer and its data attributes.
The script ignores localhost and automated browsers on purpose, so development runs stay out of your numbers. Test on a deployed URL, or turn on debug mode to log each event in the console without sending it.
Yes. Server rendering, prerendering and nuxt generate all ship the tag in the HTML of each page, and the script counts the page once a visitor opens it in the browser. Nothing runs on the server.
Yes, when it reaches a new URL: that is a pageview, one event, the same as a full page load. A query change the script ignores adds nothing. Every account starts with a 14-day free trial with every feature and no card; then Starter is $5 a month for 250,000 events.
Not answered here? Write to hello@crispstats.com
Go further
Related
- Vue analytics
Add CrispStats to a Vue app built with Vite by pasting one script tag into index.html.
- Web vitals from real visits
LCP, INP and CLS measured on real visits, by page and device.
- Web analytics for SaaS products
See which channels bring paying customers, where trials stall in the funnel, and how your app performs for real users, from one cookieless script.
- Track visitors from ChatGPT and Perplexity
Visitors sent by ChatGPT, Perplexity and Claude, plus AI crawler hits.
Other integrations
Frameworks
Site builders
Ecommerce platforms
Tag managers
Your traffic, crisp and clear
One script, no cookies, and every feature from the first day. Set up takes about as long as pasting a snippet.