Skip to content

How to use Matomo to track your experiments

Osvaldo edited this page Feb 4, 2023 · 2 revisions

Abrantes can use Matomo to track the experiments results. Just like with Google Analytics 4, you'll use Matomo custom dimensions to track behaviors in each of the experiment's variations.

It also needs Matomo tracking to be set up in a specific way that might be slightly different from what you use now.

In the head just add this code:

<script>
    var _paq = window._paq = window._paq || [];
</script>

And add the rest of the code to the footer, after properly configuring it:

<script>
    _paq.push(['trackPageView']);
    _paq.push(['enableLinkTracking']);
    (function () {
        var u = "//URL_OF_YOUR_TRACKING_DOMAIN_OR_SUB_DOMAIN";
        _paq.push(['setTrackerUrl', u + 'matomo.php']);
        _paq.push(['setSiteId', 'NUMBER_OF_YOUR_SITE_ID']);
        var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
        g.async = true; g.src = u + 'matomo.js'; s.parentNode.insertBefore(g, s);
    })();
</script>

Between the head and the footer you'll configure the experiment. Tracking with Matomo happens by calling track and passing the dimension id number, like for example:

MyTest.track(1);

Look at the Matomo example for more information.

Note: The current Matomo plugin can't be used at the same time as the Google Analytics 4 plugin, so with this plugins you can't track a page with GA4 and Matomo at the same time. I'm assuming that if you are using Matomo you will not want to use GA4. And adding too many trackers ads bloat to the page. If you need to use both GA4 and Matomo at the same time, you can quickly create a custom plugin that does that.