Skip to content
fusionaly_ GitHub

WordPress Analytics Without Cookies

Add Fusionaly to WordPress with a small must-use plugin: no plugin from the directory, no cookies, and it stays when you change themes.

You don't need a plugin from the directory. A must-use plugin of a few lines adds the Fusionaly script to every page. WordPress loads must-use plugins on its own, and they stay when you change themes.

Before you start

You need a Fusionaly server, with your site's domain added as a website. Fusionaly takes events only from the domains you added. See Installation.

In the examples, replace analytics.example.com with the domain of your Fusionaly server.

Add the script

  1. On your server, open wp-content/. Create the folder mu-plugins if it does not exist.

  2. Create wp-content/mu-plugins/fusionaly.php:

    wp-content/mu-plugins/fusionaly.php
    <?php
    /*
    * Plugin Name: Fusionaly
    * Description: Loads the Fusionaly analytics script.
    */
    add_action('wp_enqueue_scripts', function () {
    // Do not count your own visits while you are logged in.
    if (is_user_logged_in()) {
    return;
    }
    wp_enqueue_script(
    'fusionaly',
    'https://analytics.example.com/y/api/v1/sdk.js',
    [],
    null,
    ['strategy' => 'defer']
    );
    });

WordPress lists the file under Plugins > Must-Use. You cannot turn it off from the admin. To remove it, delete the file. The strategy option needs WordPress 6.3 or later.

Page changes

Every WordPress page is a full page load, so Fusionaly counts each page without any setup.

Track events

Fusionaly counts page views and button clicks without any setup. To give an event your own name, use the data-fusionaly-event-name attribute. See Tracking.

Core blocks cannot take custom attributes. For a tracked button or form, use a Custom HTML block:

<a class="wp-element-button" href="/contact/"
data-fusionaly-event-name="contact_clicked">Contact us</a>

In theme files, add the attribute to the HTML in the same way:

footer.php
<form action="/subscribe" method="post" data-fusionaly-event-name="newsletter_subscribed">
<input type="email" name="email" required>
<button type="submit">Subscribe</button>
</form>

Check that it works

  1. Open your site in a normal browser window. Fusionaly skips automated browsers, such as Playwright, and browsers that send Do Not Track.
  2. The plugin skips logged-in users, so check in a private window.
  3. In the developer tools, open the network tab, and find a POST request to /x/api/v1/events. A 403 status means that your site's domain is not added as a website.
  4. Open your Fusionaly dashboard. The visit shows up within about a minute.

Notes

  • Some cache plugins can delay JavaScript until the visitor clicks or scrolls, for example the Delay JavaScript execution option of WP Rocket. Visitors who leave without a click are then not counted. Exclude sdk.js from this option.
  • Cache plugins that combine scripts into one file can also break the script. Exclude sdk.js from combining, too.
  • On WordPress.com, you need a plan that lets you upload plugins.

Next steps

Guides for other frameworks: Next.js, React, Astro, Nuxt, SvelteKit, Shopify, Webflow, Ghost, Hugo, and the generic guide.