Matomo was formerly known as Piwik, and is an advanced, PHP based, open source analytics system that tries to replicate much of what something like Google Analytics can do for you. Care has to be taken to collect data in a way that is compliant with e.g. the EU’s GDPR.