Just One Page

Just One Page
Photo by Davide Baraldi / Unsplash

I host a Matomo instance shared with a few clients, and one of them asked me to put on the dashboard the details about a specific page. Those details are easily accessible clicking the "Open Row Evolution" button aside that same page reference in the list of all Pages on the dashboard, but eventually it is too complex to find. You know: users...

But I've found a simple Matomo plugin which permits to create a new dashboard widget with arbitrary HTML, and - after some investigation - I've hacked the following piece of code:

<script>
let page = "path-to-page";
let date = (new Date()).toISOString().slice(0,19).replace("T"," ");

let url = "/index.php?date=" + date + "&apiMethod=Actions.getPageUrls&label=" + page + "&disableLink=1&module=CoreHome&action=getRowEvolutionPopover&colors=%7B%22backgroundColor%22%3A%22%23ffffff%22%2C%22lineColor%22%3A%22%23162c4a%22%2C%22minPointColor%22%3A%22%23ff7f7f%22%2C%22maxPointColor%22%3A%22%2375bf7c%22%2C%22lastPointColor%22%3A%22%2355aaff%22%2C%22fillColor%22%3A%22%23ffffff%22%7D&idSite=24&period=month";

$.ajax({
    method: 'GET',
    url: url,
    dataType: 'HTML',
    success: (widget) => {
        widget = $(widget);
        widget.find('.compare-container').remove();
        $('.custom-widget-body').append(widget);
    }
});
</script>

The fetched URL is the same dinamically loaded opening the "Open Row Evolution" popover for the page, in which I've parametrized both the path of the page and the date. The result is then barely processed to remove the portion of HTML to compare with other pages (redundant, in this context) and appended into the "Custom Widgets" HTML main body.

I've then enabled this Custom Widget into the client's dashboard, and... that's it.

"Custom Widgets" plugin's name suggests the ability to create multiple custom widgets, but the configuration panel permits to setup just one. If more are required, it is probably easier and faster to duplicate the plugin, do some mess with names and identifiers to avoid collisions, and manually handle multiple instances.