Docs
Browse the docs

Install Privatus Analytics on WordPress

Install the Privatus Analytics WordPress plugin or add the snippet to your theme, exclude admins, track WooCommerce purchases and add an opt-out shortcode.

View as Markdown
  1. In WordPress go to Plugins → Add New and search for Privatus Analytics. If it isn't listed in the plugin directory yet, contact us for the plugin zip and upload it under Plugins → Add New → Upload Plugin, or upload the privatus-analytics folder to /wp-content/plugins/.
  2. Activate it.
  3. Go to Settings → Privatus Analytics and paste your site id (pa_…).

The plugin adds the tracker to every page and exposes every tracker option (SPA mode, modules, excluded paths, masks, extra query parameters, canonical URLs, hash routing).

It also:

  • excludes logged-in users by role (administrators by default), so your own visits don't count,
  • tracks WooCommerce purchases as a purchase event with revenue, currency, the number of items and whether a coupon was used. It never sends order ids, names, emails or addresses, and masks order-specific URLs,
  • offers a server-side purchase mode that sends the purchase from your server with a secret ingest key. Put the key in wp-config.php to keep it out of the database:
php
  define( 'PRIVATUS_INGEST_KEY', 'pik_…' );
  • adds a [privatus_optout] shortcode for your privacy page (see Opt-out),
  • suggests privacy policy text under Settings → Privacy,
  • shows your shared dashboard in a dashboard widget.

Filters for developers#

Filter Type Use
privatus_analytics_should_track bool Return false to skip tracking on a request
privatus_analytics_script_attributes array Change the attributes of the script tag
php
add_filter( 'privatus_analytics_script_attributes', function ( $attrs ) {
    $attrs['data-modules'] = 'engage,auto,vitals';
    return $attrs;
} );

Without the plugin#

Add the snippet to your theme's header.php before </head>, or with a "header and footer scripts" plugin. In a child theme's functions.php:

php
add_action( 'wp_head', function () {
    if ( current_user_can( 'manage_options' ) ) {
        return; // don't count administrators
    }
    echo '<script defer src="https://privatusanalytics.com/js/pa.js" data-site="pa_YOURSITEID"></script>';
} );

Warning: Caching and optimization plugins (WP Rocket, Autoptimize, LiteSpeed Cache…) sometimes combine or delay scripts. Exclude pa.js from "combine", "defer JS" and "delay JS" features. See Caching plugins.