Docs

WordPress

A must-use plugin survives theme changes and cannot be deactivated by accident.

Install

wp-content/mu-plugins/x3-analytics.php
<?php
/**
 * Plugin Name: 3x Analytics
 * Description: Cookieless first-party analytics (3x).
 */

const X3_KEY  = '{{PUBLISHABLE_KEY}}';
const X3_HOST = '{{API_ORIGIN}}';

add_action('wp_enqueue_scripts', function () {
    wp_enqueue_script('x3', X3_HOST . '/v1/s/x3.full.js?k=' . rawurlencode(X3_KEY), [], null, ['strategy' => 'async', 'in_footer' => false]);
    wp_add_inline_script('x3', 'window.x3=window.x3||function(){(window.x3q=window.x3q||[]).push(arguments)}', 'before');
});

add_filter('script_loader_tag', function ($tag, $handle) {
    if ($handle !== 'x3') return $tag;
    return str_replace(' src=', ' data-key="' . esc_attr(X3_KEY) . '" src=', $tag);
}, 10, 2);

Logged-in editors are measured too; add if (is_user_logged_in()) return; at the top of the wp_enqueue_scripts callback to skip them, or open the site once with ?x3_notrack=1.

Verify

  1. Open the site in a private window and click around.
  2. The network tab shows POST {{API_ORIGIN}}/v1/e → 204.
  3. Caching plugins (WP Rocket, LiteSpeed): purge the page cache, and exclude the 3x script from JavaScript combining/delaying if the request does not appear.

Proxy (optional)

A REST route on your own domain forwards events with the visitor's IP. Store the proxy key in wp-config.php, never in the database:

wp-config.php
define('X3_PROXY_KEY', 'sk_3x_YOUR_PROXY_KEY');

Then follow WordPress proxy and change the script source to the REST route:

wp-content/mu-plugins/x3-analytics.php
const X3_HOST = '/wp-json/n3';

Consent plugins: set the CMP in the project's consent settings (Complianz and Borlabs have built-in adapters). Any other banner can call 3x from its accept/decline hooks:

wp-content/mu-plugins/x3-consent.js
document.addEventListener("cookie_consent_accepted", () => window.x3("consent", "granted"));
document.addEventListener("cookie_consent_declined", () => window.x3("consent", "denied"));
wp-content/mu-plugins/x3-analytics.php
add_action('wp_enqueue_scripts', function () {
    wp_enqueue_script('x3-consent', content_url('mu-plugins/x3-consent.js'), ['x3'], null, ['in_footer' => true]);
});

Replace the event names with your banner's.

Events

Block editor: add data-x3-* attributes via Advanced → HTML anchor / Additional CSS plugins, or in custom HTML blocks:

wp-content/themes/your-theme/parts/cta.html
<a class="wp-block-button__link" href="/contact" data-x3-cta data-x3-section="hero">Get a quote</a>

Contact Form 7, Gravity Forms and WPForms are measured by the forms plugin (start, submit, abandon) without extra code.