> ## 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 CrispStats on WordPress

> Add the CrispStats script to every WordPress page with a wp_head action, either in your theme's functions.php or in a small site plugin of your own.

To install CrispStats on WordPress, print the script tag in `<head>` with a `wp_head` action. You can add the action to your theme's `functions.php` or to a small site plugin. Both load the same tag on every page WordPress renders, with no WordPress plugin from CrispStats needed.

## Add the script

**1. Copy the WordPress snippet**

In the dashboard, open your site's **Settings**, select **Tracking code** and choose the **WordPress** tab. It has your public key filled in:

```php functions.php theme={"theme":{"light":"github-light","dark":"github-dark"}}
// In your theme's functions.php, or a small site plugin.
add_action('wp_head', function () {
  ?>
  <script
    defer
    data-site="cs_pk_xxxxxxxx"
    data-domains="example.com"
    src="https://in.crispstats.com/d.js"
  ></script>
  <?php
});
```

**2. Add it to your site**

Choose one place for the code.

> [tab] Site plugin
>
> A site plugin keeps the tag when you switch or update your theme. Create the file `wp-content/plugins/crispstats/crispstats.php`:
>
> ```php wp-content/plugins/crispstats/crispstats.php theme={"theme":{"light":"github-light","dark":"github-dark"}}
> <?php
> /**
>  * Plugin Name: CrispStats
>  * Description: Adds the CrispStats tracking script to every page.
>  */
>
> add_action('wp_head', function () {
>   ?>
>   <script
>     defer
>     data-site="cs_pk_xxxxxxxx"
>     data-domains="example.com"
>     src="https://in.crispstats.com/d.js"
>   ></script>
>   <?php
> });
> ```
>
> Then open **Plugins** in the WordPress admin and activate **CrispStats**.

> [tab] functions.php
>
> Open your theme's `functions.php` (in a child theme if you use one, so a theme update does not remove it) and paste the snippet at the end of the file. The file already starts with `<?php`, so do not add another opening tag above the snippet. If the file ends with a closing `?>` tag, paste the snippet above that line.

**3. Clear caches and open your site**

If you use a page cache, clear it so visitors get pages with the tag. Then open your live site while signed out, or in a private window. The status row on the **Tracking code** tab shows **Receiving events.** once the first event has been stored.

## Add optional modules

The switches under **Extra events** on the **Tracking code** tab add attributes to the tag in the WordPress snippet. With outbound links, downloads and web vitals on, it looks like this:

```php functions.php theme={"theme":{"light":"github-light","dark":"github-dark"}}
add_action('wp_head', function () {
  ?>
  <script
    defer
    data-site="cs_pk_xxxxxxxx"
    data-domains="example.com"
    data-outbound
    data-downloads
    data-vitals
    src="https://in.crispstats.com/d.js"
  ></script>
  <?php
});
```

To keep your own visits out of the numbers, set `localStorage.crispstats_ignore` in your browser, or add `data-exclude` for paths you do not want tracked. See [exclude traffic](https://docs.crispstats.com/tracking/exclude-traffic.md).

> [!NOTE]
>
> Keep the tag a classic script with `defer` or `async`. If an optimization plugin changes it to `type="module"`, the script cannot read its options and does not track.

## Check that it works

* Open your site while signed out, or in a private window, with the browser's developer tools on the **Network** tab. You should see `d.js` load from `in.crispstats.com` and a `POST` to `https://in.crispstats.com/e` that gets `202`.
* Open the page source and search for `in.crispstats.com/d.js`. If it is missing, the page cache still serves an old copy, or the theme does not call `wp_head()`.
* Open `https://in.crispstats.com/check?k=cs_pk_xxxxxxxx` with your key. `"site": "known"` means the key is right. The visit appears in **Realtime** within seconds.

If an optimization plugin combines, delays or rewrites scripts, exclude `in.crispstats.com/d.js` from it. The tag has to stay a classic script with its `data-` attributes intact.

## How page changes are counted

A WordPress site does a full page load per page, so the script counts one pageview per page. The admin area does not get the tag: `wp_head` runs for the pages your theme renders, not for `/wp-admin`. If a theme or plugin changes pages without a reload and updates the URL through the History API, the script counts each new URL too.

## Send custom events

* **Clicks on a button or link**: in the block editor, edit the block as HTML (or use a Custom HTML block) and add `data-cs-event`:

  ```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
  <a href="/contact" data-cs-event="contact click" data-cs-prop-place="pricing">Talk to us</a>
  ```

* **Form submissions**: send the form to a thank-you page and add a [goal](https://docs.crispstats.com/dashboard/goals.md) with a **Page visit** rule for that path.

* **From PHP**: actions that happen on the server, such as an order in a webhook, can be sent as [server-side events](https://docs.crispstats.com/track/server-side-events.md) with a secret key. Never print that key in a page.

## FAQ

> [accordion] Is there a CrispStats WordPress plugin?
>
> No. The `wp_head` action, in your theme or a small site plugin of your own, is the whole install.

> [accordion] Will my own visits as an admin be counted?
>
> Visits to `/wp-admin` are not tracked, because the tag is not there. Your visits to the public site are counted unless you exclude your browser with `localStorage.crispstats_ignore`. See [exclude traffic](https://docs.crispstats.com/tracking/exclude-traffic.md#exclude-your-own-browser).

> [accordion] Can I record WooCommerce orders?
>
> There is no WooCommerce integration. Report orders from your server with the [payment API](https://docs.crispstats.com/revenue/payment-api.md), with the visitor id you saved at checkout.

## Next steps

> [card] [Exclude traffic](https://docs.crispstats.com/tracking/exclude-traffic.md)
>
> Leave out your own browser and private paths.

> [card] [Script attributes](https://docs.crispstats.com/tracking/script-attributes.md)
>
> Every option the script tag accepts.

> [card] [Track custom events](https://docs.crispstats.com/track/custom-events.md)
>
> Send form submissions and other actions.


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