Dokumentation
Bläddra i dokumentationen

Install Privatus Analytics on WordPress

Install our free plugin from the WordPress plugin directory and paste your site id, or add the snippet to your theme yourself.

Visa som Markdown

You want to see who visits your WordPress site without cookies or a cookie pop-up. Install our free plugin from the WordPress plugin directory and paste your site id. It leaves your own visits out and updates like any other plugin.

With the plugin#

Our plugin is listed in the WordPress plugin directory as Privatus Analytics, by privatusanalytics. Check the author before you install. If a plugin with the same name has another author, it is not ours.

  1. In your WordPress admin, go to Plugins → Add New.
  2. In the search box, search for Privatus Analytics and find the one by privatusanalytics.
  3. Click Install Now, then Activate.
  4. Go to Settings → Privatus Analytics and paste your site id (pa_…).

WordPress shows new versions on the Plugins page, and you update it there like any other plugin.

The plugin adds the tracker to every front-end page and has settings for these tracker options: SPA mode, manual pageviews, modules, allowed domains, excluded paths, path masks, extra query parameters, canonical URLs and 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,
  • 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,clicks,ask';
    return $attrs;
} );

Without the plugin#

If you would rather not add a 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://privatusstats.com/js/pa.js" data-site="pa_YOURSITEID" data-modules="engage,auto,vitals,clicks,ask"></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.