Matomo Integration

I just wanted to see if there is interest in integrating Matomo into fastpages. I was able to do it without much issue based on the google analytics configuration already available. I can try integrating if anybody else is interested. Otherwise, I will just describe the changes I made here.

First, I created a matomo.html file in the _includes directory. Inside of this, I added my matomo tracking script.

{% if site.matomo %}

<!-- Matomo -->
<script  type="text/javascript">
    var _paq = window._paq = window._paq || [];_paq.push(['trackPageView']);_paq.push(['enableLinkTracking']);_paq.push(['alwaysUseSendBeacon']);_paq.push(['setTrackerUrl', "\/\/{{site.matomo}}\/wp-json\/matomo\/v1\/hit\/"]);_paq.push(['setSiteId', '1']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];g.type='text/javascript'; g.async=true; g.src="\/\/{{site.matomo}}\/wp-json\/matomo\/v1\/hit\/"; s.parentNode.insertBefore(g,s);
<!-- End Matomo Code -->
{% endif %}

Next, I added a couple of lines to head.html mirroring google analytics again:

  {%- if jekyll.environment == 'production' and site.matomo -%}
    {%- include matomo.html -%}
  {%- endif -%}

lastly, I added a line to _config.yml:


WIth these three changes, matomo is working as expected on my site. Not sure if anybody else is using it, but figure if there is interest, Iā€™m willing to create a PR to add it as an option.

1 Like