Countnest

How to add privacy-friendly analytics to WordPress without a plugin

By Adrian Ababei · Published · Updated · About 30 minutes · Facts checked 25 November 2026

Share card reading: How to add privacy-friendly analytics to WordPress without a plugin, by Countnest

Want these numbers for your own site? Start a 30-day free trial of Countnest, no card required, or see pricing.

Which page do you need?

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?

MethodPlugin?Works withGood to know
Child theme functions.php with wp_head (this guide)NoBlock and classic themesSurvives theme updates; one place for the code
Child theme header.php (classic themes only)NoClassic themesYou copy the parent's header.php, so later fixes to it in the parent do not reach your copy
A theme setting for header scriptsNoOnly themes that offer oneNot 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 directlyNoAnyNot recommended: the next theme update removes your code
A must-use plugin file in wp-content/mu-pluginsIt is a plugin, just always onAnyCannot 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)YesAnyEasy, but it is a plugin; WPCode had 3+ million and Code Snippets 1+ million active installations on 25 November 2026
The Countnest plugin (zip)YesAnyAdds 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)

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

  2. 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 without www. If you also want a subdomain such as shop.example.com counted, type *.example.com instead. A local or staging copy on another domain is not counted, which keeps test visits out.

  3. 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.js and your site ID, the value of data-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 Countnest onboarding screen in the light purple-and-blue theme: the snippet card reads “Paste this in the head of every page”, shows the one-line script with a sample site id, and says the tracker is about 2.6 KB (about 1.4 KB compressed). Beside it, a card is waiting for the first visit.
    Sample data in the Countnest dashboard (light theme).

Part 2: make sure you have a child theme (10 minutes, once)

  1. 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 or DISALLOW_FILE_EDIT in wp-config.php has turned it off; then use SFTP or your host's file manager for the next steps.

  2. Step 5: Create and activate a child theme

    On your computer, make a folder named after your theme plus -child, for example twentytwentyfive-child. Put a file called style.css in it with this header, where Template must match the parent theme's folder name exactly:

    /*
     Theme Name: Twenty Twenty-Five Child
     Template:   twentytwentyfive
    */

    Add an empty file called functions.php that starts with <?php on 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)

  1. 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 <?php line. Replace YOUR-SITE-ID with 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_head hook fires inside the <head> of every front-end page, and wp_print_script_tag() prints a script tag from the attributes you give it, writing defer as a plain attribute because its value is true. Do not add a second <?php if 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.

  2. 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 the defer strategy (WordPress 6.3 and later) prints the tag in the head, null as the version keeps WordPress from adding a ?ver= query string, and the script_loader_tag filter 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.php into 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.

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

  4. 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.js to 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 own data-site attribute to know which site the visit belongs to. And if you use is_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).

Want these numbers for your own site? Start a 30-day free trial of Countnest, no card required, or see pricing.

Part 4: check that it works (3 minutes)

  1. 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 Countnest onboarding screen in the light purple-and-blue theme: the snippet is in place and the companion card reads “First visit received” with an Open dashboard button.
    Sample data in the Countnest dashboard (light theme).
  2. 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 your data-site value, 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 Countnest Install page in the light purple-and-blue theme for Example Shop (site ID cn_sample0001): WordPress is selected with the Download WordPress plugin (.zip) button, and after Check installation the Tracker card shows a tick with 3 pageviews while Bot logging still waits for crawler pings.
    Sample data in the Countnest dashboard (light theme).
  3. 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 Countnest Overview tab in the light purple-and-blue theme, with invented figures for Example Shop: 842 visitors, 1,486 pageviews and 15% AI share over 7 days. The visitors chart compares this period with the previous one and has a pinned note on 15 Nov that says “Added Countnest”.
    Sample data in the Countnest dashboard (light theme).

Part 5: set goals and connect search data (7 minutes)

  1. 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, add countnest('Signup') to its click handler and an Event name goal for Signup. You can keep up to 20 goals per site.

    Sample Countnest Goals & events tab in the light purple-and-blue theme, with invented figures for Example Shop: signup, purchase and form-submit events, plus four goals (Signup, Purchase, Visited pricing, Newsletter signup) and the Add goal form.
    Sample data in the Countnest dashboard (light theme).
  2. 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 Countnest SEO tab in the light purple-and-blue theme, with invented figures for Example Shop. Below the organic search cards, the Search engine data section shows the Connect Google Search Console button and the Connect Bing Webmaster Tools card.
    Sample data in the Countnest dashboard (light theme).

If no visits show up

What you seeLikely causeWhat to do
The tag is not in the page sourceThe cached page is old, or the code is in the parent theme or an inactive child themeClear all caches; check that the child theme is the active theme
The tag is there, but no visit arrivesYour browser sends Global Privacy Control or Do Not Track, or an ad blocker blocks the scriptTest in another browser or a private window without extensions
Only some visits arriveAn optimisation plugin delays the script until interactionExclude countnest.com/c.js from delayed JavaScript
Visits stop after a theme switchThe code lived in the old theme's functions.phpAdd it to the new child theme, or use a must-use plugin file
You see visits from your own teamThe tag prints for logged-in usersUse the is_user_logged_in() version from step 8
The domain does not matchThe site in Countnest uses another domainUse 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.

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

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.

See your own numbers in minutes

30-day free trial, no card required. Then from $14 a month. Cancel anytime.

Start free for 30 days

Sources

Facts checked on 25 November 2026.