hyrax icon indicating copy to clipboard operation
hyrax copied to clipboard

Analytics - Matomo analytics should be more resilient and easier to debug

Open cudevmaxwell opened this issue 2 years ago • 1 comments

In Hyrax 3.4.1, in services/hyrax/analytics/matomo.rb, get returns an empty array if the response status is not 200. That causes a confusing "ActionView::Template::Error (no implicit conversion of String into Integer)" error when the contents of the response is indexed in new_visitors, returning_visitors, etc.

The error from the analytics backend should instead be logged and the front end should handle the error gracefully, showing no results.

cudevmaxwell avatar Apr 01 '22 16:04 cudevmaxwell

One issue in particular with the current code in services/hyrax/analytics/matomo.rb is that Faraday doesn't follow HTTP redirects. This probably depends on the Matomo webserver configuration, but at least on some Matomo servers, HTTP requests to /?someparameters get redirected to /index.php?someparameters with a 302 temporary redirect, which leads to the above mentioned empty array. Users might try to work around this by appending index.php to the base_url, but this results in /index.php/matomo.js being included as tracking JS file, which won't work either with most webserver configurations.

IMO, the proper solution would be to use something like faraday-follow-redirects to properly handle redirects, but since I don't have a clue about Ruby or Rails, I'm unsure how to write a pull request to fix this.

hardfalcon avatar Mar 30 '23 17:03 hardfalcon