We run Matomo on a self-hosted server for all our websites and it works very well, there's a large discrepancy between the traffic / visitor count shown by Cloudflare and Matomo though: Matomo will show 50-80 % less unique visitors than Cloudflare, which seems a lot even when accounting for ad-blocking users. It might be due to our very user-friendly cookie script though, which only loads Matomo after the user explicitly clicks on OK (and he/she can click on "Decline" as well). Guess we should investigate how many people actually click on "Decline".
If you are writing your own web servers and request handlers at the outset. Then you can structure your log file data as required. And use the ELK stack to process very powerful queries, business analytics, predictive machine learning, sentiment analysis, etc.
Note: I’m the creator of Simple Analytics.
Note: I am biased, I work at Mixpanel.