← Install guides

Add Hark to a WordPress site

WordPress needs a little help to add a script to every page: a plugin that inserts header code, or a hook in your theme.

The code below is for example.com. Replace it with your site's domain.

  1. 1

    Option 1: a header-code plugin

    Install a plugin that adds code to your site's header, such as WPCode ("Insert Headers and Footers"). Paste the snippet into its header box and save.

    Header

    <script defer data-domain="example.com" src="https://harkstats.com/js/script.js"></script>
  2. 2

    Option 2: your child theme's functions.php

    If you'd rather not add a plugin, hook into wp_head. Use a child theme, or a theme update will remove it.

    wp-content/themes/your-child-theme/functions.php

    add_action('wp_head', function () {
        echo '<script defer data-domain="example.com" src="https://harkstats.com/js/script.js"></script>' . "\n";
    });
  3. 3

    Clear your cache, then visit your site

    If you use a caching plugin or host-level caching, clear it so pages include the snippet. Your site's settings page in Hark shows "Receiving events" when the first pageview arrives.

WordPress.com

Adding scripts or plugins needs a WordPress.com plan that allows plugins. Self-hosted WordPress has no such limit.

Not seeing visits?

  • Your site's settings page in Hark says "Receiving events" once the first pageview arrives. It updates by itself, so keep it open while you visit your site.
  • data-domain must be the domain you added to Hark, without https:// or www.
  • Visits from localhost aren't counted. Add a data-local attribute to the tag to test on your machine.
  • Check your published page's source for the tag: caching plugins and CDNs can serve an old copy.
  • Some ad blockers block analytics scripts, including this one; try another browser to rule that out.
  • To leave your own visits out, run localStorage.analytics_ignore = "true" in your browser's console on your site.

No site yet? The trial is free, with no card.

Start your free trial