How to add privacy-friendly analytics to WordPress without a plugin
- Administrator rights on your WordPress site
- A child theme, or 10 minutes to create one
- A recent backup of your site
Which page do you need?
- Still choosing a tool? Read The best Google Analytics alternatives for WordPress in 2026, which compares nine options with prices checked on 24 November 2026.
- Happy to use a plugin? The Countnest plugin is the quickest route: upload a zip, paste two values, done. See when the plugin is the easier route below.
- Want no extra plugin? This guide is for you: one script line, added from a child theme, with a way to keep your own visits out.
Definitions
- Privacy-friendly analytics means visit statistics that are collected without building profiles of people. Countnest, for example, never saves IP addresses and stores nothing on visitors' devices.
- Hosted analytics means a small script sends each visit to the vendor's servers, which store it and draw the reports. Nothing is stored in your WordPress database, so you need no plugin to collect the numbers.
- The
<head>is the invisible top part of every HTML page, where scripts and settings for the browser go. It is not the same as the visible header with your logo and menu. - Child theme means a small theme that builds on your current (parent) theme. The WordPress Theme Handbook recommends it because your changes survive updates of the parent theme.
- functions.php is a PHP file in a theme that runs on every page load. A child theme's functions.php is loaded in addition to the parent's, immediately before it.
- wp_head is the WordPress action hook that fires inside the
<head>of front-end pages. Code attached to it can print a script tag there. - Block theme and classic theme. A block theme is edited in the Site Editor (Appearance, Editor) with blocks. A classic theme uses PHP template files such as header.php and usually the Customizer (Appearance, Customize).
WordPress today, in numbers
On 25 November 2026, W3Techs reported WordPress on 38.4% of all websites, a 57.3% share of sites that use a known content management system, and version 7 on 71.0% of WordPress sites. The latest release on WordPress.org was WordPress 7.1.5, released on 18 November 2026. The code in this guide uses functions that have been in WordPress since version 5.7 (wp_print_script_tag, March 2021) and 6.3 (the defer strategy for wp_enqueue_script).
Which method fits your site?
| Method | Plugin? | Works with | Good to know |
|---|---|---|---|
Child theme functions.php with wp_head (this guide) | No | Block and classic themes | Survives theme updates; one place for the code |
| Child theme header.php (classic themes only) | No | Classic themes | You copy the parent's header.php, so later fixes to it in the parent do not reach your copy |
| A theme setting for header scripts | No | Only themes that offer one | Not part of WordPress itself: the Customizer options WordPress documents (Site Identity, Colors, Menus, Widgets, Homepage Settings, Additional CSS and others) include no field for head code, and block themes hide the Customizer |
| Editing the parent theme directly | No | Any | Not recommended: the next theme update removes your code |
| A must-use plugin file in wp-content/mu-plugins | It is a plugin, just always on | Any | Cannot be turned off from wp-admin; useful when you have no child theme and file access |
| A code-snippet plugin (for example WPCode or Code Snippets) | Yes | Any | Easy, but it is a plugin; WPCode had 3+ million and Code Snippets 1+ million active installations on 25 November 2026 |
| The Countnest plugin (zip) | Yes | Any | Adds the script, AI and search crawler logging, and one-click fixes; see below |
What you keep and what you give up without the plugin
- You keep every visitor report: visits, pages, sources and UTM campaigns, AI traffic by assistant, countries and devices, goals, funnels, revenue events and Search Console data. They all come from the script.
- You give up two things that need code running on your server: the log of AI and search crawlers such as GPTBot and Googlebot (the Bot logging check stays empty), and the one-click apply of fixes from your weekly Action plan.
- You gain one plugin less, full control of where the tag goes, and a simple way to skip logged-in users, which neither the plugin nor the script does on its own.
Part 1: get your Countnest snippet (5 minutes)
Step 1: Create your Countnest account
Open the signup page. It is titled Start your 30-day free trial. Fill in Company or site name, Email and Password (at least 8 characters), tick the box to agree to the Terms and the Data Processing Agreement, and click Create account. No card is asked for, and the trial includes Growth plan features.
Step 2: Add your WordPress site
In the Add a site card, type a Name and your Domain, for example
example.com, and click Add site. Countnest counts visits only from the domain you enter, with or withoutwww. If you also want a subdomain such asshop.example.comcounted, type*.example.cominstead. A local or staging copy on another domain is not counted, which keeps test visits out.Step 3: Copy your snippet
Countnest shows a card called Paste this in the <head> of every page with your personal snippet:
<script defer src="https://countnest.com/c.js" data-site="YOUR-SITE-ID"></script>You only need two parts of it: the address
https://countnest.com/c.jsand your site ID, the value ofdata-site. Leave this tab open. You can find both again later under Install in the top menu, where Copy Site ID copies the ID.
Sample data in the Countnest dashboard (light theme).
Part 2: make sure you have a child theme (10 minutes, once)
Step 4: Check whether your theme is already a child theme
Go to Appearance, Themes and note the active theme. A child theme's style.css always has a
Template:line naming its parent theme's folder, so you can check in the Theme File Editor, which WordPress lists under Tools for block themes and under Appearance for classic themes. If your theme is already a child theme (many premium themes ship one, and some hosts set one up), skip to Part 3. If the editor is missing, your host orDISALLOW_FILE_EDITin wp-config.php has turned it off; then use SFTP or your host's file manager for the next steps.Step 5: Create and activate a child theme
On your computer, make a folder named after your theme plus
-child, for exampletwentytwentyfive-child. Put a file calledstyle.cssin it with this header, whereTemplatemust match the parent theme's folder name exactly:/* Theme Name: Twenty Twenty-Five Child Template: twentytwentyfive */Add an empty file called
functions.phpthat starts with<?phpon the first line. Zip the folder, upload it under Appearance, Themes, Add New and click Activate. Your site looks the same, because the child theme uses everything from its parent. For block themes, the free Create Block Theme plugin from WordPress.org can also do this with its Create Child Theme button; the child theme stays in your themes folder if you remove that plugin afterwards. Take a backup before you switch themes.
Part 3: add the script without a plugin (5 minutes)
Step 6: Add the tracker to your child theme's functions.php
Open the child theme's functions.php in the Theme File Editor (or over SFTP) and add this below the opening
<?phpline. ReplaceYOUR-SITE-IDwith your own site ID:<?php // Countnest analytics: adds the tracker to the <head> of every front-end page. add_action( 'wp_head', function () { wp_print_script_tag( array( 'defer' => true, 'src' => 'https://countnest.com/c.js', 'data-site' => 'YOUR-SITE-ID', ) ); } );The
wp_headhook fires inside the<head>of every front-end page, andwp_print_script_tag()prints a script tag from the attributes you give it, writingdeferas a plain attribute because its value istrue. Do not add a second<?phpif the file already has one. Click Update File and wait for the message that the file was edited successfully. The WordPress documentation warns that the editor makes no backup, so if a typo breaks the site, fix or remove the file over SFTP.Step 7: Or use the enqueue API, or header.php on a classic theme
If you prefer WordPress's script queue, this does the same job.
wp_enqueue_script()with thedeferstrategy (WordPress 6.3 and later) prints the tag in the head,nullas the version keeps WordPress from adding a?ver=query string, and thescript_loader_tagfilter adds your site ID:add_action( 'wp_enqueue_scripts', function () { wp_enqueue_script( 'countnest', 'https://countnest.com/c.js', array(), null, array( 'strategy' => 'defer' ) ); } ); add_filter( 'script_loader_tag', function ( $tag, $handle ) { return 'countnest' === $handle ? str_replace( ' src=', ' data-site="YOUR-SITE-ID" src=', $tag ) : $tag; }, 10, 2 );On a classic theme, a third way is to copy the parent's
header.phpinto your child theme and paste the snippet just before the closing</head>tag. It works, but your copy no longer receives the parent theme's later changes to that file, so we suggest functions.php. On a block theme, the Site Editor's header is a template part made of blocks, the visible header at the top of your pages, so it is not the place for this tag.Step 8: Keep your own visits out (optional)
Countnest has no setting that ignores your own visits, and neither the Countnest plugin nor the script skips logged-in users. Without a plugin, you can do it yourself: WordPress's
is_user_logged_in()returns true for logged-in visitors, so this version prints nothing for you, your editors or logged-in customers:add_action( 'wp_head', function () { if ( is_user_logged_in() ) { return; // you and other logged-in users are not counted } wp_print_script_tag( array( 'defer' => true, 'src' => 'https://countnest.com/c.js', 'data-site' => 'YOUR-SITE-ID', ) ); } );If you run a shop or a membership site where customers log in and you do want them counted, use
if ( current_user_can( 'edit_posts' ) )instead, which only skips people who can write posts (contributors, authors, editors and administrators); subscribers are still counted. Another way that needs no code: Countnest does not count browsers that send Global Privacy Control or Do Not Track, so turning on Global Privacy Control in the browser you work in also keeps you out.Step 9: Clear your caches and keep the script unchanged
Caching plugins such as WP Super Cache or W3 Total Cache serve stored copies of your pages, so empty the page cache (and your host's or CDN's cache) after you save, or visitors keep getting pages without the script. If your optimisation plugin delays JavaScript until the first click or scroll, for example WP Rocket's Delay JavaScript execution, add
countnest.com/c.jsto its Excluded JavaScript Files. Otherwise visitors who read a page and leave without touching it are never counted. Do not let a plugin combine, inline or rewrite the tag either: the script reads its owndata-siteattribute to know which site the visit belongs to. And if you useis_user_logged_in(), check that your cache never serves a page made for a logged-in user to everyone (WP Super Cache, for example, has a setting not to cache pages for known users).
Part 4: check that it works (3 minutes)
Step 10: Check that the first visit arrives
Open your site in a private window, so you are logged out and see the cached page your visitors get. Back in Countnest, the card Waiting for your first visit… checks every few seconds and changes to ✅ First visit received. Click Open dashboard. If nothing arrives within a minute, see troubleshooting below.

Sample data in the Countnest dashboard (light theme). Step 11: Look at the page source and the Install page
In the private window, open the page source (Ctrl+U, or Cmd+Option+U on a Mac) and search for
countnest.com/c.js. You should see one tag with yourdata-sitevalue, inside the<head>. The free third-party tracker checker shows the same from outside: it should list Countnest. Later, Install in the top menu has a Check installation button: Tracker gets a tick once pageviews are stored. Bot logging stays waiting with a script-only install, because crawler visits can only be logged by code on your server, such as the Countnest plugin.
Sample data in the Countnest dashboard (light theme). Step 12: Watch Live now on the Overview
Open the Overview tab. Live now counts visits active in the last 5 minutes, and the Visitors chart fills in as the day goes on. To mark the day you started, click + Add note under the chart, type something like
Countnest added in child theme, and click Save note.
Sample data in the Countnest dashboard (light theme).
Part 5: set goals and connect search data (7 minutes)
Step 13: Add your first goals
Open Goals & events. Type a Goal name, choose a Goal type and a match, and click Add goal. For WordPress sites, the most useful first goals are usually a Page path goal for your thank-you or order-received page (for example
/thank-you, or/checkout/order-received/*on WooCommerce), and a Form submission goal with*to count any form sent. Form submissions, outbound link clicks and file downloads are recorded automatically, with only the form's id or name and never what people type, so they need no code. For a button that is not a form or a link, addcountnest('Signup')to its click handler and an Event name goal forSignup. You can keep up to 20 goals per site.
Sample data in the Countnest dashboard (light theme). Step 14: Connect Search Console
Open the SEO tab and click Connect Google Search Console, sign in with Google (read-only access) and pick your property. Google's data is about 3 days behind, and Countnest fills in up to 16 months of history over the next nights. Bing Webmaster Tools connects in the same tab. Your UTM-tagged links show up under Sources in UTM campaigns; the free UTM link builder helps you tag new ones.

Sample data in the Countnest dashboard (light theme).
If no visits show up
| What you see | Likely cause | What to do |
|---|---|---|
| The tag is not in the page source | The cached page is old, or the code is in the parent theme or an inactive child theme | Clear all caches; check that the child theme is the active theme |
| The tag is there, but no visit arrives | Your browser sends Global Privacy Control or Do Not Track, or an ad blocker blocks the script | Test in another browser or a private window without extensions |
| Only some visits arrive | An optimisation plugin delays the script until interaction | Exclude countnest.com/c.js from delayed JavaScript |
| Visits stop after a theme switch | The code lived in the old theme's functions.php | Add it to the new child theme, or use a must-use plugin file |
| You see visits from your own team | The tag prints for logged-in users | Use the is_user_logged_in() version from step 8 |
| The domain does not match | The site in Countnest uses another domain | Use the live domain, or *.example.com for subdomains |
When the Countnest plugin is the easier route
The no-plugin way suits people who already have a child theme and are comfortable editing a PHP file. The Countnest plugin is easier when:
- You do not want to touch code or do not have a child theme. Choose WordPress on the Install page, click Download WordPress plugin (.zip), upload it under Plugins, Add New, Upload Plugin, activate it, open Settings → Countnest and paste your Site ID and Ingest key.
- You change themes often. Code in a theme moves with the theme; a plugin stays when you switch.
- You want to see AI and search crawlers. The plugin also reports visits from bots such as GPTBot, ClaudeBot and Googlebot from your server (bot type and path only), which a browser script cannot see.
- You want one-click fixes. With its apply option turned on, the plugin can put live the redirects, structured data and internal links you approve in your weekly Action plan. See Apply fixes.
The plugin is a zip from your dashboard; it is not listed on WordPress.org yet. Both routes are described on WordPress and WooCommerce analytics and in the WordPress install doc.
How Countnest does this
- One small script. The tracker is about 2.6 KB (about 1.4 KB compressed) and loads with
defer, so it does not block your page. Page views, scroll depth, engaged time, outbound link clicks, file downloads, form submissions (only the form's id or name), site search phrases and 404 pages are recorded automatically. - Made for WordPress habits. Page path goals end in
*for whole sections, such as/blog/*; 404 pages are detected from the page title; and WooCommerce shops can connect orders in site settings to see revenue per source (see the WooCommerce doc). - Reports in one place. Overview with Live now, Sources with UTM campaigns, Pages, Audience, Goals & events with funnels, and visits from 17 AI assistants in AI traffic, next to Google Search Console and Bing Webmaster Tools data in SEO.
- A weekly to-do list. The Action plan ranks up to 10 fixes for your site each week; without the plugin you apply them yourself.
- Privacy. It never saves IP addresses. The IP address is read in memory to form a one-way code that changes daily, and is then discarded. Its script does not set cookies or use local storage, and stores nothing on visitors' devices. On the same day, visits from the same browser and network can still be grouped, so the records are pseudonymous rather than strictly anonymous. Data is stored in the EU (Frankfurt). Read our privacy explainer and the Data Processing Agreement.
A note on consent
Whether you need a consent banner depends on your country and on what a tool does, for example whether it stores or reads information on the device, stores IP addresses or records sessions. How you install a tool, with a plugin or without, does not change that, and no tool can promise that you never need consent. This is general information, not legal advice. Official sources: the ePrivacy Directive (2002/58/EC), the GDPR (2016/679) and the EDPB Guidelines 2/2023 on the technical scope of Art. 5(3) ePrivacy. Our overviews: Do I need a consent banner for website analytics? and consent rules in Europe, country by country. Remember to describe Countnest in your privacy policy: the provider (IDCPH ApS, Denmark), what is counted and that data is stored in the EU.
What it costs after the trial
Countnest has no free plan. After the 30-day trial you choose Starter at $14 a month (1 site, 20,000 sessions), Growth at $29 (5 sites, 100,000 sessions) or Agency at $79 (25 sites, 500,000 sessions), VAT included, with about 2 months free on yearly billing. Every plan has every analytics report, including goals, funnels and revenue; the Stats API and team seats are on Growth and Agency. The script and the plugin are the same price: the plan is what you pay for. If you do nothing, the trial simply ends, and the data is deleted 30 days later (we email you 7 days before). See pricing.
Free tools that help
- Third-party tracker checker: confirm that Countnest loads, and see which other analytics or tracking scripts your WordPress pages still load.
- UTM link builder: tag newsletter and social links so they show up as campaigns.
- AI readiness checker: see which AI and search crawlers your robots.txt allows.
How we checked
On 25 November 2026 we read the WordPress developer reference for wp_enqueue_script(), wp_print_script_tag(), wp_get_script_tag(), the wp_head, wp_enqueue_scripts and script_loader_tag hooks, is_user_logged_in() and current_user_can(), and the Roles and capabilities page; the Theme Handbook pages on child themes, custom functionality and including assets; the WordPress 6.3 note on async and defer; the Advanced Administration pages on editing files, must-use plugins and caching; the WordPress.org documentation on the Site Editor, the Customizer and the Theme File Editor; the WordPress.org release archive; the WordPress.org plugin pages for WPCode, Code Snippets, WP Super Cache and Create Block Theme; WP Rocket's documentation on delaying JavaScript; and W3Techs' WordPress report (all listed under Sources). The Countnest steps follow the labels in the Countnest dashboard and the tracker code on the same day. We did not test every theme or caching plugin; if yours behaves differently, tell us at support@countnest.com and we will add it. WordPress is a trademark of the WordPress Foundation. Countnest is not affiliated with or endorsed by the WordPress Foundation, Automattic or the makers of the plugins named here.
Questions and answers
Can I add analytics to WordPress without a plugin?
Yes. Hosted analytics such as Countnest only needs one script tag in the <head> of your pages. Add it from a child theme's functions.php with the wp_head hook, or enqueue it with wp_enqueue_script(). No plugin is needed to collect visits.
Where do I paste the analytics code in a block theme?
In your child theme's functions.php, hooked to wp_head. The Site Editor edits the visible header made of blocks, not the HTML head, so it is not the place for a tracking tag.
Will a theme update remove my analytics code?
Not if the code is in a child theme. The WordPress Theme Handbook warns that code added to a parent theme's functions.php disappears when that theme is updated, which is why it recommends a child theme.
Is a code-snippets plugin the same as no plugin?
No. WPCode and Code Snippets are plugins themselves, even if they make adding code easy. A must-use plugin file in wp-content/mu-plugins is also a plugin, just one that is always on. The child theme method is the only one here without any plugin.
How do I stop my own visits from being counted?
Wrap the code in if ( is_user_logged_in() ) return; so logged-in users get no script, or use current_user_can( 'edit_posts' ) to skip only people who can write posts (contributors, authors, editors and administrators). Countnest also skips browsers that send Global Privacy Control or Do Not Track.
Do I need to change anything for caching plugins?
Clear the page cache after adding the code. If your optimisation plugin delays JavaScript until the first interaction, exclude countnest.com/c.js, and do not let it combine or inline the tag, because the script reads its own data-site attribute.
What do I miss without the Countnest plugin?
No visitor reports. You miss only the server-side log of AI and search crawlers such as GPTBot and Googlebot, and the one-click apply of Action plan fixes. Both need the plugin's code on your server.
Does the script slow down WordPress?
The Countnest script is about 2.6 KB (about 1.4 KB compressed) and loads with defer, so the browser downloads it without blocking the page and runs it after the HTML is parsed.
30-day free trial, no card required. Then from $14 a month. Cancel anytime.
Start free for 30 daysSources
- WordPress Developer Reference: wp_enqueue_script() ($args strategy defer/async, in_footer; changelog 6.3.0; checked 25 November 2026)
- WordPress Developer Reference: wp_head action hook (prints scripts or data in the head on the front end)
- WordPress Developer Reference: wp_print_script_tag() (since 5.7.0)
- WordPress Developer Reference: wp_get_script_tag() (boolean attributes printed as name only)
- WordPress Developer Reference: wp_enqueue_scripts hook
- WordPress Developer Reference: script_loader_tag filter
- WordPress Developer Reference: is_user_logged_in()
- WordPress Developer Reference: current_user_can()
- WordPress.org Documentation: Roles and capabilities (edit_posts for contributors and up)
- Make WordPress Core: Registering scripts with async and defer attributes in WordPress 6.3 (14 July 2023)
- WordPress Theme Handbook: Child themes (Template header, functions.php loaded before the parent's)
- WordPress Theme Handbook: Custom functionality (functions.php)
- WordPress Theme Handbook: Including assets
- WordPress Advanced Administration: Editing files (Theme File Editor under Tools for block themes, Appearance for classic; DISALLOW_FILE_EDIT)
- WordPress Advanced Administration: Must-use plugins
- WordPress Advanced Administration: Cache (caching plugins serve static copies)
- WordPress.org Documentation: Site Editor (header and footer template parts)
- WordPress.org Documentation: Customizer (menu options; hidden for block themes)
- WordPress.org Documentation: Appearance Theme File Editor screen (no backups; use a child theme)
- WordPress.org: Releases (latest 7.1.5, 18 November 2026; checked 25 November 2026)
- WordPress.org plugin: WPCode (3+ million active installations, 25 November 2026)
- WordPress.org plugin: Code Snippets (1+ million active installations, 25 November 2026)
- WordPress.org plugin: WP Super Cache (known users setting)
- WordPress.org plugin: Create Block Theme (Create Child Theme)
- WP Rocket docs: Delay JavaScript execution (Excluded JavaScript Files)
- W3Techs: Usage statistics and market share of WordPress (25 November 2026)
- Countnest pricing
- Countnest WordPress install doc
- Countnest install docs