> ## 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.

# Install the CrispStats script on any site

> Install CrispStats with one script tag: find your public key, copy the exact code for your platform from the dashboard, and open the guide for your stack.

You install CrispStats by adding one script tag to every page of your site. There is no npm package to install: frameworks load the same tag in their own way. From there, pageviews, single-page navigation and time on page are tracked. By default no cookie is set and nothing is stored in the browser. This page helps you pick a method, find your public key and open the guide for your stack.

## Choose an install method

| Method | Use it when | Guide |
| - | - | - |
| Script tag | You can edit the HTML `<head>` of your pages, or your platform has a field for custom head code. | [Plain HTML](https://docs.crispstats.com/install/html.md) and the platform guides below |
| Google Tag Manager | Your site already loads tags through a GTM container. | [Google Tag Manager](https://docs.crispstats.com/install/google-tag-manager.md) |
| TypeScript | You want `window.crispstats` typed and safe to call before the script loads. Add it to either method. | [TypeScript](https://docs.crispstats.com/install/typescript.md) |

The script tag is the shortest path. It looks like this:

```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<script
  defer
  data-site="cs_pk_xxxxxxxx"
  data-domains="example.com"
  src="https://in.crispstats.com/d.js"
></script>
```

Replace `cs_pk_xxxxxxxx` with your site's public key and `example.com` with your domain. `data-domains` keeps the script quiet on preview deployments, `workers.dev` copies, staging hosts and scraped copies of your site, so they are not counted. Use a classic script tag with `defer` or `async`. `type="module"` does not work, because the script reads its options from its own tag.

## Find your public key

Every site has a public key that starts with `cs_pk_`. It tells the collector which site an event belongs to. It is safe to publish: all it can do is send events to that site.

You can find it in three places:

* **Settings, Tracking code**: the **Public key** panel shows the key with a copy button, and every snippet on that tab already has the key filled in.
* **The command menu**: the **Copy tracking snippet** action copies the plain script tag for the site you have open.
* **Onboarding**: the **Install the script** step shows the same platform tabs, with the key filled in, right after you add a site.

Owners and admins of the workspace can select **Rotate key** on the Tracking code tab. A new key is issued and the collector stops accepting the old one, within about a minute because it caches site settings for 60 seconds. From then on no visits are counted until you replace the snippet on your site.

## Copy the exact code for your platform

The **Tracking code** tab in your site settings shows the same script, placed where each platform wants it, with tabs for HTML, Next.js, React and Vite, Vue and Nuxt, Astro, SvelteKit, Remix and React Router, WordPress, Webflow, Framer, Shopify and Google Tag Manager. Each tab says where the code goes, writes `data-domains` with your site's domain and additional hostnames, and adds `data-keep-params` and `data-persist` when your settings need them. The switches add an attribute to every tab at once:

| Group | Switch | Attribute |
| - | - | - |
| Extra events | Outbound links | `data-outbound` |
| Extra events | File downloads | `data-downloads` |
| Extra events | Web vitals | `data-vitals` |
| Extra events | JavaScript errors | `data-errors` |
| Extra events | 404 pages | `data-404` |
| How pages are counted | Hash routing | `data-hash` |
| How pages are counted | Manual pageviews | `data-manual` |

No switch is on by default. Leave **Hash routing** off for frameworks that route with real paths (Next.js, Nuxt, SvelteKit, Astro, Remix): it only reads routes written after `#`, such as `/#/pricing`.

The switches only change the snippet you copy. An option starts working once the updated snippet is on your site. [Script attributes](https://docs.crispstats.com/tracking/script-attributes.md) lists every attribute, including the ones that are not switches.

## Platform guides

> [card] [Plain HTML](https://docs.crispstats.com/install/html.md)
>
> Paste the tag in `<head>` on every page.

> [card] [Google Tag Manager](https://docs.crispstats.com/install/google-tag-manager.md)
>
> A Custom HTML tag on All Pages.

> [card] [WordPress](https://docs.crispstats.com/install/wordpress.md)
>
> A `wp_head` action in `functions.php` or a site plugin.

> [card] [Webflow](https://docs.crispstats.com/install/webflow.md)
>
> Site settings, Custom code, Head code.

> [card] [Framer](https://docs.crispstats.com/install/framer.md)
>
> Site settings, General, Custom code.

> [card] [Shopify](https://docs.crispstats.com/install/shopify.md)
>
> `layout/theme.liquid`, above `</head>`.

> [card] [Wix](https://docs.crispstats.com/install/wix.md)
>
> Settings, Custom Code, in the head on all pages.

> [card] [Squarespace](https://docs.crispstats.com/install/squarespace.md)
>
> The Header field of Code Injection.

> [card] [Ghost](https://docs.crispstats.com/install/ghost.md)
>
> Settings, Advanced, Code injection, Site header.

## Framework guides

> [card] [Next.js](https://docs.crispstats.com/install/nextjs.md)
>
> `next/script` in the root layout.

> [card] [React and Vite](https://docs.crispstats.com/install/react-vite.md)
>
> The tag in `index.html`.

> [card] [Vue and Nuxt](https://docs.crispstats.com/install/vue-nuxt.md)
>
> `app.head` in `nuxt.config.ts`.

> [card] [Astro](https://docs.crispstats.com/install/astro.md)
>
> The tag with `is:inline` in your layout.

> [card] [SvelteKit](https://docs.crispstats.com/install/sveltekit.md)
>
> The tag in `src/app.html`.

> [card] [Remix](https://docs.crispstats.com/install/remix.md)
>
> The tag in `app/root.tsx`.

> [card] [Angular](https://docs.crispstats.com/install/angular.md)
>
> The tag in `src/index.html`.

> [card] [Svelte](https://docs.crispstats.com/install/svelte.md)
>
> The tag in `index.html`, for Svelte with Vite.

> [card] [TypeScript](https://docs.crispstats.com/install/typescript.md)
>
> Types for the global and the queue stub.

## Static site guides

> [card] [Gatsby](https://docs.crispstats.com/install/gatsby.md)
>
> `onRenderBody` in `gatsby-ssr.js`.

> [card] [Hugo](https://docs.crispstats.com/install/hugo.md)
>
> Your head partial, overriding the theme's.

> [card] [Jekyll](https://docs.crispstats.com/install/jekyll.md)
>
> `_includes/head.html` in your site.

> [card] [Eleventy](https://docs.crispstats.com/install/eleventy.md)
>
> The base layout in `_includes`.

> [card] [Docusaurus](https://docs.crispstats.com/install/docusaurus.md)
>
> The `scripts` array in `docusaurus.config.js`.

## Server framework guides

> [card] [Laravel](https://docs.crispstats.com/install/laravel.md)
>
> Your Blade layout.

> [card] [Ruby on Rails](https://docs.crispstats.com/install/rails.md)
>
> `application.html.erb`. Turbo is tracked.

> [card] [Django](https://docs.crispstats.com/install/django.md)
>
> `base.html`.

> [card] [Flask](https://docs.crispstats.com/install/flask.md)
>
> Your base Jinja template.

## Switching from another tool

Only Plausible history can be [imported](https://docs.crispstats.com/switch/import-from-plausible.md); from other tools, run both side by side for a while. The switching guides map events and goals across: [Google Analytics 4](https://docs.crispstats.com/switch/google-analytics.md), [Plausible](https://docs.crispstats.com/switch/plausible.md), [Umami](https://docs.crispstats.com/switch/umami.md) and [Fathom](https://docs.crispstats.com/switch/fathom.md).

## Confirm the install

Open **Settings, Tracking code**. The status row at the top checks every few seconds and shows **Receiving events.** once the first event from your site has been stored. Visits from `localhost`, `*.localhost`, `127.x.x.x`, `[::1]`, `file://` and automated browsers are ignored, so open your deployed site in a normal browser window. To test before you ship, see [localhost and testing](https://docs.crispstats.com/tracking/localhost-and-testing.md). If nothing arrives, work through [troubleshooting](https://docs.crispstats.com/help/troubleshooting.md).

## Next steps

> [card] [Install on a plain HTML site](https://docs.crispstats.com/install/html.md)
>
> The full procedure, with optional modules and the install check.

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

> [card] [Serve the script from your domain](https://docs.crispstats.com/tracking/proxy.md)
>
> Count visitors whose ad blocker stops analytics hosts.


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