# WordPress analytics with CrispStats

Updated 2026-11-23

WordPress needs one wp_head action to print the CrispStats script tag in the head of every page. Put the action in a small site plugin of your own, so it survives theme updates, and there is no third-party analytics plugin to install or keep updated.

## Steps

### 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 and domain filled in.

### 2. Create a site plugin file

Create the folder `wp-content/plugins/crispstats/` and save this file in it, with your key and domain. A site plugin keeps the tag when you switch or update your theme.

`wp-content/plugins/crispstats/crispstats.php`

```php
<?php
/**
 * Plugin Name: CrispStats
 * Description: Adds the CrispStats tracking script to every page.
 */

add_action('wp_head', function () {
  ?>
  <script
    defer
    data-site="cs_pk_your_site_key"
    data-domains="example.com"
    src="https://in.crispstats.com/d.js"
  ></script>
  <?php
});
```

### 3. Activate the plugin

Open **Plugins** in the WordPress admin and activate **CrispStats**. If you would rather not add a plugin, paste the `add_action` block at the end of your theme's `functions.php` instead, in a child theme so a theme update does not remove it. The file already starts with `<?php`, so do not add a second opening tag.

### 4. Clear the page cache

If you use a caching plugin or a host-level page cache, clear it, so visitors get pages that include the new tag.

## Check that it works

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 is stored, and the visit appears on the **Realtime** screen. If nothing arrives, view the page source and search for `d.js` to confirm the tag is in the head.

## What you get

- Pageviews, unique visitors and sessions for every post and page WordPress renders.
- Where readers come from: search, social, newsletters tagged with UTM parameters, and AI assistants such as ChatGPT and Perplexity.
- Entry and exit pages, countries, devices and browsers, with no cookies and nothing stored on the reader's device.
- Optional outbound link clicks, file downloads and web vitals: turn them on under **Extra events** on the **Tracking code** tab, and the snippet gains `data-outbound`, `data-downloads` and `data-vitals`.
- Goals and funnels from the pages you already have, and form submissions as custom events with `crispstats("signup")` or `data-cs-event` attributes.

## Notes for WordPress

- Keep the tag a classic script with `defer` or `async`. If an optimization plugin rewrites it to `type="module"`, the script cannot read its options and does not track.
- Keep your own visits out of the numbers by setting `localStorage.crispstats_ignore` in your browser, and leave out private paths with `data-exclude`. See [exclude traffic](/docs/tracking/exclude-traffic).
- The `wp_head` action fires where your theme calls `wp_head()` inside `<head>`. A theme that never calls it gets no tag.
- CrispStats does not publish a WordPress plugin. The site plugin above is your own file of a few lines, with nothing to update.
- WordPress sites served by nginx or behind Cloudflare can serve the script from their own domain with one forwarding rule: see [the proxy guide](/docs/tracking/proxy).

Full reference: [WordPress in the docs](https://docs.crispstats.com/install/wordpress)

## Frequently asked questions

### Is there a WordPress analytics plugin for this?

CrispStats does not publish one, and you do not need one. A plugin file of a few lines that you create yourself adds the script to every page, and it has no settings screen, no database tables and no updates to install.

### Will it slow down my WordPress site?

The core script is about 2.2 KB gzipped and loads with defer, so it never blocks the page from rendering. Optional modules add a little more, up to about 3.8 KB with all of them on.

### Does it count logged-in administrators?

It counts every browser that loads the page, including yours. Set the ignore flag in your own browser once, and your visits are left out from then on.

### Do I need a cookie banner for WordPress analytics?

CrispStats sets no cookies and stores nothing on the visitor's device by default, and it never stores IP addresses. WordPress sets its own cookies for logged-in users and commenters, and plugins may add more, so the answer depends on the whole site. This is not legal advice.

### How much does it cost for a blog?

The plugin file is yours, so there is nothing to buy on the WordPress side. 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.

## Related

- [Privacy-friendly analytics for bloggers](/for/bloggers)
- [Do you need a cookie banner for analytics?](/blog/do-you-need-a-cookie-banner-for-analytics)
- [UTM parameters: a practical guide](/blog/utm-parameters-guide)
- [Track visitors from ChatGPT and Perplexity](/features/ai-traffic)
