Sending Panel data to Matomo

So, I’m working on a client site right now, with their own instance of Kirby and Matomo. Thing is, they want those things linked, so when somebody logs into the Kirby Panel, that data would show up in Matomo.

Also, moreover, they’d like the site to send over the username of the logged in person. In another site I’ve built in the past, the results look like this…

<script type="text/javascript">
  var _paq = _paq || [];
  <?php if ($context['user']['id'] != 0 && $context['user']['is_guest'] == false) {
    echo "_paq.push(['setUserId', '" . $context['user']['name'] . "']);";
  } ?>
  (function() {
    var u="//site/analytics/";
    _paq.push(['setTrackerUrl', u+'pwk.php']);
    _paq.push(['setSiteId', '2']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);

So, basically what I’d like is to have that script block load on every panel page, and also to conditionally send _paq.push(['setUserId', {{username}} ]); whenever the user is actually logged in.


You could probably do it with a hook, i guess…

Hmmm, unfortunately, that’s insufficient for two reasons.

  1. I’d like to have a script block that exists on every page, much like it does for the website’s frontend.
  2. That _paq.push event also should be happening on every page, not just once on login.

Ok, well i think the only other way is to use a custom panel Javascript, but the trick there is knowing precisely whcih user has logged in.

You might be able to do it via a custom API end point so the panel javascript hits the API which triggers PHP to send the username through to the Matamo script in the endpoint… but im just thinking out loud there, no idea if its possible or not… @texnixe … is that a plan?