Let’s start with the open source application that rivals Google Analytics for functions: Matomo (formerly known as Piwik). Matomo does most of what Google Analytics does, and chances are it offers the features that you need. Those features include metrics on the number of visitors hitting your site, data on where they come from (both on the web and geographically), the pages from which they leave, and the ability to track search engine referrals. Matomo also offers many reports, and you can customize the dashboard to view the metrics that you want to see. To make your life easier, Matomo integrates with more than 65 content management, e-commerce, and online forum systems, including WordPress, Magneto, Joomla, and vBulletin, using plugins. For any others, you can simply add a tracking code to a page on your site. You can test-drive Matomo or use a hosted version.
Open Web Analytics
Web server log files provide a rich vein of information about visitors to your site, but tapping into that vein isn't always easy. That's where AWStats comes to the rescue. While it lacks the most modern look and feel, AWStats more than makes up for that with breadth of data it can present. That information includes the number of unique visitors, how long those visitors stay on the site, the operating system and web browsers they use, the size of a visitor's screen, and the search engines and search terms people use to find your site. AWStats can also tell you the number of times your site is bookmarked, track the pages where visitors enter and exit your sites, and keep a tally of the most popular pages on your site. These features only scratch the surface of AWStats's capabilities. It also works with FTP and email logs, as well as syslog files. AWStats can gives you a deep insight into what's happening on your website using data that stays under your control.
Countly bills itself as a "secure web analytics" platform. While I can't vouch for its security, Countly does a solid job of collecting and presenting data about your site and its visitors. Heavily targeting marketing organizations, Countly tracks data that is important to marketers. That information includes site visitors' transactions, as well as which campaigns and sources led visitors to your site. You can also create metrics that are specific to your business. Countly doesn't forgo basic web analytics; it also keeps track of the number of visitors on your site, where they're from, which pages they visited, and more. You can use the hosted version of Countly or grab the source code from GitHub and self-host the application. And yes, there are differences between the hosted and self-hosted versions of Countly