Content management systems
WordPress analytics with CrispStats
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.
Updated
Set up CrispStats on WordPress
- 01
Step 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.
- 02
Step 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.Replace the highlighted values with your own.
wp-content/plugins/crispstats/crispstats.php<?php/*** Plugin Name: CrispStats* Description: Adds the CrispStats tracking script to every page.*/add_action('wp_head', function () {?><scriptdeferdata-site="cs_pk_your_site_key"data-domains="example.com"src="https:/ / in. crispstats. com/ d. js"></script><?php}); - 03
Step 3: Activate the plugin
Open Plugins in the WordPress admin and activate CrispStats. If you would rather not add a plugin, paste the
add_actionblock at the end of your theme’sfunctions.phpinstead, 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. - 04
Step 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.
CrispStats on WordPress
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-downloadsanddata-vitals. - Goals and funnels from the pages you already have, and form submissions as custom events with
crispstats("signup")ordata-cs-eventattributes.
Notes and limits
- Keep the tag a classic script with
deferorasync. If an optimization plugin rewrites it totype="module", the script cannot read its options and does not track. - Keep your own visits out of the numbers by setting
localStorage.crispstats_ignorein your browser, and leave out private paths withdata-exclude. See exclude traffic. - The
wp_headaction fires where your theme callswp_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.
- Keep the tag a classic script with
The docs page covers the optional steps this guide leaves out.
Setup questions. Straight answers.
What people ask before they connect it.
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.
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.
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.
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.
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.
Not answered here? Write to hello@crispstats.com
Go further
Related
- Privacy-friendly analytics for bloggers
See which posts get read to the end, where readers come from, including AI assistants, and keep your site free of analytics cookies.
- Do you need a cookie banner for analytics?
When analytics needs consent: what the device storage rule covers, where GDPR comes in, and a checklist.
- UTM parameters: a practical guide
What the five UTM parameters do, a naming convention you can copy, the mistakes that split your reports, and how the medium decides the channel.
- Track visitors from ChatGPT and Perplexity
Visitors sent by ChatGPT, Perplexity and Claude, plus AI crawler hits.
Other integrations
Content management systems
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.