Integrate Matomo with instantsearch.js

I am using Matomo (https://developer.matomo.org/guides/tracking-javascript-guide) for tracking site search. However I do not know how to configure the “analytics” widget as the Algolia documentation does not give an example for Matomo (https://www.algolia.com/doc/api-reference/widgets/analytics/js/). Would be happy if the Algolia team could add a Matomo example or someone from the community already solved this and is happy to provide a code snippet.

Here is my (work-in-progress) application:

Found the solution myself. This code does the job:

  instantsearch.widgets.analytics({
    pushFunction(formattedParameters, state, results) {
      /*  help needed: add code for Matomo  (https://developer.matomo.org/guides/tracking-javascript-guide)*/
      window._paq.push([
        'setDocumentTitle',
        window.location.pathname + window.location.search,
      ]);
      window._paq.push(['trackPageView']);
    },
  }),