If you’re using SharePoint Classic sites, you can setup Matomo Tag Manager by following the instructions in the article Setup Matomo Tag Manager to the classic SharePoint site collections. The solution described in the article involves running this third-party PowerShell script to automatically add the Tag Manager container code to your SharePoint sites.

See also Is Matomo compatible with Microsoft SharePoint Online (O365 Analytics) and/or SharePoint On-Premises?