WordPress

WordPress integration guide

Adding PureStats to your WordPress site is easy. You have several options depending on your setup and preferences.

Option 1: Theme Editor (Simple)

Add the tracking code directly to your theme's header file:

  1. Go to Appearance → Theme File Editor in your WordPress admin
  2. Select header.php from the files list on the right
  3. Find the </head> tag
  4. Paste your tracking code just before it
  5. Click "Update File" to save
<!-- Add this before </head> in header.php -->
<script defer data-domain="yourdomain.com" src="https://purestats.io/pf.min.js"></script>
</head>

Warning: Theme updates will overwrite your changes. Consider using a child theme or one of the other methods below.

Option 2: Insert Headers and Footers Plugin (Recommended)

Use a plugin to add the code without editing theme files:

  1. Install the "Insert Headers and Footers" plugin (by WPBeginner)
  2. Go to Settings → Insert Headers and Footers
  3. Paste your tracking code in the "Scripts in Header" box
  4. Click "Save"

This method survives theme updates and is the recommended approach for most users.

Option 3: Using functions.php

Add the code via your theme's functions.php file:

// Add this to your theme's functions.php
function add_purestats_tracking() {
    ?>
    <script defer data-domain="yourdomain.com" src="https://purestats.io/pf.min.js"></script>
    <?php
}
add_action('wp_head', 'add_purestats_tracking');

Tracking Custom Events

To track custom events in WordPress, you can add JavaScript to your pages:

// Track WooCommerce purchase
jQuery(document).on('checkout_place_order_success', function() {
    purestats('Purchase');
});

// Track form submission (Contact Form 7)
document.addEventListener('wpcf7mailsent', function() {
    purestats('Contact Form');
});

Excluding Admin Users

If you don't want to track visits from logged-in administrators, you can conditionally load the script:

function add_purestats_tracking() {
    // Don't track logged-in administrators
    if (current_user_can('manage_options')) {
        return;
    }
    ?>
    <script defer data-domain="yourdomain.com" src="https://purestats.io/pf.min.js"></script>
    <?php
}
add_action('wp_head', 'add_purestats_tracking');