Skip to content
Skip to main content
European Data Processing
← All platform guides

Install on WordPress

The VeritaMetrics plugin is the shortest route and the one we recommend; the three snippet routes below are for sites that would rather not add one. A header and footer plugin survives theme updates, functions.php suits people who prefer code, and GTM suits a site already running it.

Start with the WordPress plugin

It needs your site id and nothing else, and a theme update cannot remove it, which is how the functions.php snippet stops counting. The snippet routes still work if you would rather keep the code in a child theme you version-control.

It is not in the WordPress.org directory yet, so ask us for the zip.

Read the plugin guide

Before you paste anything

Every snippet below shows YOUR-SITE-ID . Replace it with your own site id, which is on the Tracking Code page of the site in your account. If you do not have an account yet, creating one and adding your domain takes about a minute.

Create a free account

Which method should you use?

  1. 1. Method A: paste the script into a header and footer plugin

    Start here. It takes about a minute, needs no code, and a theme update cannot remove it.

  2. 2. Method B: add the snippet to functions.php

    Choose this if you already maintain a child theme and prefer the code in version control.

  3. 3. Method C: add a Google Tag Manager tag

    Choose this only if GTM is already installed on the site. It adds a second tool to keep working.

Method B: add the snippet to functions.php

  1. Create or open your child theme, then open its functions.php.
  2. Paste the snippet at the end of the file. It hooks wp_footer, so it renders on every page the theme serves.
  3. Save the file and load any page on your site.
wp-content/themes/<your-child-theme>/functions.php
<?php
/**
 * VeritaMetrics Analytics Tracking
 * Add this code to your active theme's functions.php file.
 */
function veritametrics_analytics_tracking() {
    $site_id = 'YOUR-SITE-ID';
    $tracking_domain = 'www.veritametrics.com';
    $current_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    $referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
  ?>
  <script>
    (function() {
      if (typeof window === 'undefined') return;
      var siteId = '<?php echo esc_js($site_id);?>';
      var trackingDomain = '<?php echo esc_js($tracking_domain);?>';

      // 1. Initialize the Async Command Queue
      window.verita = window.verita || function() { (window.verita.q = window.verita.q || []).push(arguments) };
      window.verita.l = new Date().getTime();

      // 2. Load the enhanced tracker script
      var script = document.createElement('script');
      script.src = 'https://' + trackingDomain + '/api/tracker.js?siteId=' + siteId;
      script.async = true; script.defer = true;
      script.dataset.siteId = siteId;
      script.dataset.trackingDomain = trackingDomain;
      document.head.appendChild(script);

      // 3. Send the initial pageview using the queue
      window.verita('trackPageView');
    })();
    </script>
    <noscript>
      <img src="https://<?php echo esc_url($tracking_domain);?>/api/track-pageview?siteId=<?php echo esc_attr($site_id);?>&url=<?php echo urlencode($current_url);?>&ref=<?php echo urlencode($referrer);?>" alt="" width="1" height="1" style="display:none" aria-hidden="true" />
    </noscript>
    <?php
}
add_action('wp_footer', 'veritametrics_analytics_tracking');

Note: Put this in a child theme. In the parent theme, the next theme update overwrites functions.php and the tracking stops with no error anywhere.

Method C: add a Google Tag Manager tag

  1. In Google Tag Manager, create a new tag, choose Custom HTML, and paste the snippet.
  2. Set the trigger to All Pages.
  3. Click Submit, then Publish.
GTM: Custom HTML tag
<!--
  VeritaMetrics: Google Tag Manager Custom HTML Tag

  Install: Create a new "Custom HTML" tag in GTM, paste this code,
  and set the trigger to "All Pages" (or your preferred trigger).

  After installing this base tag, you can track custom events and
  revenue from other GTM tags using:

    window.verita('trackEvent', 'event_name', { key: 'value' });

    window.verita('trackRevenue', {
      orderId: 'ORDER-123',
      amount: 49.99,
      currency: 'USD',
      products: ['product-a', 'product-b']
    });
-->
<script>
  (function () {
    if (typeof window === 'undefined' || typeof document === 'undefined') return;

    var siteId = 'YOUR-SITE-ID';
    var trackingDomain = 'www.veritametrics.com';

    // 1. Initialize the async command queue
    window.verita =
      window.verita ||
      function () {
        (window.verita.q = window.verita.q || []).push(arguments);
      };
    window.verita.l = new Date().getTime();

    // 2. Load the tracker script
    var script = document.createElement('script');
    script.src = 'https://' + trackingDomain + '/api/tracker.js?siteId=' + siteId;
    script.async = true;
    script.defer = true;
    script.dataset.siteId = siteId;
    script.dataset.trackingDomain = trackingDomain;
    document.head.appendChild(script);

    // 3. Send initial pageview
    window.verita('trackPageView');
  })();
</script>

What this route looks like

The VeritaMetrics widget on the WordPress dashboard, showing pageviews, visitors and the busiest pages for the last seven days.
What the plugin adds to your WordPress dashboard once an API key is saved.

Read the plugin guide

Check that the data is arriving

  1. Open your site in a browser and load any page.
  2. In VeritaMetrics, open the site and click Tracking Code in the sidebar. The status turns active and your visit appears in the recent-pageviews list within a few seconds.

If nothing arrives, open your browser devtools on the Network tab and reload. You should see a request to /api/tracker.js that returns 200, then a request to /api/v1/c when you move or scroll.

Appearance, then Theme Editor is the route that breaks

Editing the active parent theme from the WordPress admin works until the theme updates, which replaces the file and takes your tracking with it. Nothing warns you, and the first sign is a dashboard that stops counting on a date you cannot explain. Method A avoids the problem entirely; method B avoids it as long as the file belongs to a child theme.

Guides for other platforms

The same install, on a different stack.

Explore the documentation

Jump to another guide.