PSR-14 events

Target group: Developers

Have a look into the event dispatcher documentation if you are not familiar with PSR-14 events.


New in version 1.7.0/2.1.0.

This event provides a possibility to adjust the site ID and the authentication token just before making the request to the Matomo API. This may be helpful in a big multi-site installation where you added a configuration independent from a site.

The event Brotkrueml\MatomoWidgets\Event\BeforeMatomoApiRequestEvent provides the following methods:


Returns the site ID.


Sets the site ID.


Returns the authentication token.


Sets the authentication token.


Dependent on the host name the current backend user is using we change the site ID:

namespace YourVendor\YourExtension\EventListener;

use Psr\Http\Message\ServerRequestInterface;
use YourVendor\YourExtension\Mapping\MatomoSiteMapper;

final class BeforeMatomoApiRequestEventListener
   private MatomoSiteMapper $matomoSiteMapper;

   public function __construct(MatomoSiteMapper $matomoSiteMapper)
      $this->matomoSiteMapper = $matomoSiteMapper;

   public function __invoke(BeforeMatomoApiRequestEvent $event): void
      $hostName = $this->request->getServerParams()['REMOTE_HOST'];
      if ($idSiteFromHostName = $this->matomoSiteMapper->getIdSiteFromHostName($hostName)) {

   private function getRequest(): ServerRequestInterface
      return $GLOBALS['TYPO3_REQUEST'];

Registration of the event listener:

         - name: event.listener
           identifier: 'myMatomoApiRequestListener'