Piwik is a powerful alternative to Google Analytics (GA). Unlike GA it is completely free and open-source. Being Open-source means you can get access to the code, customize it according to your preferences and host wherever you need.
Piwik helps you to track user behavior, referral information, setting conversion goals and building better user-experience for site visitors.
Google analytics is a free tool but not open-source. Google also get benefited for the data you share with it on GA. Websites dealing with user privacy and do not want to keep everything private can use Piwik on self-hosted servers.
Otherwise, Piwik also comes with an option to host the software on their servers which is a paid plan.