Docs · Install

Install Statlark on WordPress

Add the tracker to every page with the free WPCode plugin, or from a child theme if you'd rather not add a plugin.

Using an AI coding tool?Hand it the prompt below, or point it at this page as markdown: wordpress.md

Where it goes

Code Snippets → Header & Footer → Header, in your WordPress admin, once the WPCode plugin is active.

Steps

  1. In your WordPress admin, go to Plugins → Add Plugin. Search for WPCode, click Install Now, then Activate.
  2. Go to Code Snippets → Header & Footer.
  3. Paste the snippet into the Header box, with your site ID from Settings → Install. WPCode prints it in the <head> of every page.
  4. Click Save Changes. If you use a caching plugin, clear its cache so visitors get the new page.
  5. Rather not add a plugin? Use the wp_head hook in a child theme's functions.php instead. Don't edit the parent theme: its next update wipes your change.

Code Snippets → Header & Footer → Header

<script defer src="https://statlark.com/script.js" data-website-id="YOUR_SITE_ID"></script>

functions.php (child theme, no plugin)

// Prints the Statlark tracker in the <head> of every front-end page.
add_action( 'wp_head', function () {
	echo '<script defer src="https://statlark.com/script.js" data-website-id="YOUR_SITE_ID"></script>' . "\n";
} );

The tag sets a first-party analytics cookie as soon as it loads. Where the law asks for consent first, such as for visitors in the EU or UK, install the consent banner in its place: it loads the tracker only after the visitor accepts. Or switch on cookieless mode, which stores nothing on the device.

Hand this to your AI

Paste this into Claude Code, Cursor or another AI coding tool, in your project. Replace YOUR_SITE_ID with the ID from Settings → Install first. It never needs your API key.

Add Statlark analytics to this WordPress site. My Statlark site ID is YOUR_SITE_ID. If that isn't a real ID (they start with sl_), ask me for it. Use it in place of the guide's placeholder.

Follow this guide for the exact code: https://statlark.com/docs/install/wordpress.md
If that link doesn't open, try the same address without .md. If neither opens, stop and tell me. Don't write this from memory.

1. First check the site doesn't already load Statlark, whether through a script tag, consent.js, @statlark/web or a first-party proxy. If it does, stop and tell me.
2. Statlark sets first-party analytics cookies. Ask me whether this site has visitors in the EU or UK; you can't tell from the code. If it does, or I'm not sure, stop before adding it, because it may need to load through the consent banner: https://statlark.com/docs/consent.md
3. Add the guide's wp_head hook to the child theme's functions.php. If this project isn't a child theme, stop and ask me: changes to a parent theme are wiped by its next update. If there's no theme code here at all, stop and tell me to use the guide's WPCode steps instead.
4. Don't change anything else. Finish by telling me what you changed. Remind me to get the theme change onto the live site, to clear any page cache, to check the tag isn't also in a plugin such as WPCode's Header box, to add statlark.com/script.js under Excluded JavaScript Files if I use WP Rocket's Delay JavaScript execution, and to confirm it in Statlark under Settings, Install, Verification.

Check it’s working

Clear your cache, then open your site in a private window, the way a visitor sees it. View the page source and search for script.js.

Then open Settings → Install in Statlark and look under Verification. It says “You're live” once the site's first event arrives, usually within seconds. On a site that already had traffic it's green already, so the real test is your own visit: open your live site, then find yourself on the Overview with the Now range. A browser you excluded with ?statlark_ignore=1 won't show up.

Good to know

  • WP Rocket's Delay JavaScript execution (on its File Optimization tab) holds scripts until the visitor scrolls, taps or moves the mouse, so visitors who leave without doing any of that aren't counted. Add statlark.com/script.js under Excluded JavaScript Files.
  • On WordPress.com, adding header code needs a Personal plan or higher.

Other platforms

Next.js · Shopify · Webflow · Google Tag Manager · npm · anything else

Sources

These steps were checked against the pages below on .

Last reviewed