> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crispstats.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> CrispStats is a hosted, privacy-first web analytics product. It has no self-hosted edition, no session replay, no heatmaps, no A/B testing, no mobile SDKs and no data import except a site's history from a Plausible export (Settings, Import and export).
> The script global is crispstats(...), site keys start with cs_pk_ and secret API keys start with cs_sk_. The script is served from https://in.crispstats.com/d.js and the REST API lives at https://crispstats.com/api/v1.
> There is no npm package to install. Integrations copy the script tag, the queue stub, crispstats.d.ts and proxy code from these docs or from Settings, Tracking code in the dashboard. A first-party proxy forwards one path of the site to https://in.crispstats.com/p/ and forwards only content-type, user-agent, accept-language, referer, origin, if-none-match and x-forwarded-for, never cookies.

# Add CrispStats to a Vue or Nuxt app

> Install CrispStats in a Nuxt app through app.head.script in nuxt.config.ts, or in a plain Vue app through index.html. Vue Router navigation is tracked for you.

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:

```ts nuxt.config.ts theme={"theme":{"light":"github-light","dark":"github-dark"}}
export default defineNuxtConfig({
  app: {
    head: {
      script: [
        {
          src: "https://in.crispstats.com/d.js",
          defer: true,
          "data-site": "cs_pk_xxxxxxxx",
          "data-domains": "example.com",
        },
      ],
    },
  },
});
```

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:

```ts nuxt.config.ts theme={"theme":{"light":"github-light","dark":"github-dark"}}
export default defineNuxtConfig({
  app: {
    head: {
      script: [
        {
          src: "https://in.crispstats.com/d.js",
          defer: true,
          "data-site": "cs_pk_xxxxxxxx",
          "data-domains": "example.com",
          "data-outbound": "",
          "data-vitals": "",
          "data-errors": "",
        },
      ],
    },
  },
});
```

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](https://docs.crispstats.com/tracking/script-attributes.md) 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>`:

```html index.html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>My app</title>
    <script
      defer
      data-site="cs_pk_xxxxxxxx"
      data-domains="example.com"
      src="https://in.crispstats.com/d.js"
    ></script>
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="/src/main.ts"></script>
  </body>
</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:

```vue UpgradeButton.vue theme={"theme":{"light":"github-light","dark":"github-dark"}}
<script setup lang="ts">
function upgrade() {
  window.crispstats?.("upgrade clicked", { from: "settings" });
}
</script>

<template>
  <button @click="upgrade">Upgrade</button>
</template>
```

In a TypeScript project, save `crispstats.d.ts` from [TypeScript](https://docs.crispstats.com/install/typescript.md) 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](https://docs.crispstats.com/track/declarative-events.md).

## 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](https://docs.crispstats.com/tracking/localhost-and-testing.md).

## Next steps

> [card] [Custom events](https://docs.crispstats.com/track/custom-events.md)
>
> Track signups, clicks and other actions with properties.

> [card] [Single-page apps](https://docs.crispstats.com/tracking/single-page-apps.md)
>
> How client navigation, hash routing and engagement are tracked.

> [card] [Script attributes](https://docs.crispstats.com/tracking/script-attributes.md)
>
> Every attribute the script reads, with examples.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.