kirby-matomo icon indicating copy to clipboard operation
kirby-matomo copied to clipboard

Panel page widget not working for pages with custom URLs?

Open jhogervorst opened this issue 1 month ago • 0 comments

I'm using the matomo-page section in my Kirby v4 site with the latest version (2.0.1) of this plugin. Some of the pages have custom URLs, configured according to Kirby's documentation. The url() method on these pages is overridden to return the correct (custom) URL, as also instructed in your readme:

Matomo receives public urls, which means that its URIs are fetched once routes have been applied. Therefore, the plugin filters Matomo's responses with a uri created from the public url of the page. If you have set up custom routes, to skip subfolders for example, please make sure to overwrite the url method for the template with a page model, otherwise the uri won't be correct.

However, the widget is not working correctly. I notice the following error:

GET http://site/api/matomo-panel/get-page-metrics?period=month&multilang=false&overview=false&default=false&uri=/page

{
    "status": "error",
    "message": "Call to a member function url() on null",
    "code": 500,
    "exception": "Error",
    "key": null,
    "file": "/site/plugins/matomo/lib/matomo.php",
    "line": 171,
    "details": [],
    "route": "matomo-panel/get-page-metrics"
}

(In this case, /page is my custom URL, and the original URL would be something like /section/page.)

According to my debugging, the plugin tries to find the right page using $pages->find() with the custom URL:

https://github.com/sylvainjule/kirby-matomo/blob/ce5da6b1427da225efe3ebc05c3a1a4d6b7781c2/lib/matomo.php#L168

However, that method finds pages based on their ID, which is not equal to the (overridden/custom) URL.

I'm curious if something is wrong in my configuration, or this is a bug in the plugin.

jhogervorst avatar May 17 '24 08:05 jhogervorst