Creating and running websites is a fun and rewarding hobby. Especially if you’re using your own hardware or VPS to host it on a Linux system. But measuring visitor traffic and analyzing their behavior can be difficult if you don’t want to rely on intrusive third-party analytics packages.
GoAccess collects data from server logs and provides a beautiful terminal user interface that lets you discover what your visitors want from your site and how to improve it.
Why not use Google Analytics
Google Analytics is the de facto king of analytics packages, and most sites you visit today (including this site) log basic facts about your visit, such as your IP address, browser, and operating system.
Your progress on these sites is tracked using cookies. The benefits of Google Analytics for website owners are obvious. Easy to get started, free to use, and powerful.
You can bring Google Analytics to almost any web page by copying the code snippet into your page header, using a plugin, or following the steps to add Google Analytics to your WordPress site.
However, Google does not have a great reputation for respecting privacy. If you are visiting the website from another country, you may be concerned that using Google Analytics may compromise your relationship with various data protection authorities.
Additionally, if you run your website on your own hardware at home, Google Analytics can be a little jarring.
GoAccess leverages access logs to provide superior analytics
GoAccess is no more different in the way it works, except that it shares the same initialization and functionality similar to that provided by Google.
When running a Linux server on a physical machine or VPS, it’s standard practice to log all accesses. These logs record all information provided by the visitor’s browser. It typically includes device type, IP address, operating system, browser, pages viewed, time of day, and more.
By going through these logs, you can gain insight into who is visiting your site, what they are looking at, and more. However, access logs are not particularly easy to read, and counting every entry is time consuming and tedious.
GoAccess takes the information in your logs and formats it in an intuitive and easy-to-read way with graphs and charts, including number of visitors per day, files requested, time distribution, static resources, country of origin, etc. , to display various metrics such as status codes. more.
It is non-intrusive, does not transmit user data internationally, and does not require any code from Google.
Install GoAccess on your Linux server
GoAccess is available in standard repositories for most distributions. To install GoAccess on Debian or Ubuntu:
sudo apt install goaccess
For Arch and related distributions:
pacman -S goaccess
Or on Fedora:
yum install goaccess
For Gentoo as the selected distribution:
emerge net-analyzer/goaccess
You need to tell GoAccess exactly what your log file format is. Edit the GoAccess configuration file using nano.
sudo /etc/goaccess/goaccess.conf
Everything in this file is commented out and you need to uncomment the lines corresponding to time format, date format and log format. You can check one of your system logs to see if the date format is described as: %d/%b/%Y Also %Y-%m-%d.
save and exit nano Ctrl + O after that Ctrl + X.
View website analytics in Terminal with GoAccess
Viewing logs using GoAccess is easy. Just feed the path to your logs or your logs to GoAccess. Apache logs are typically stored in: /var/log/apache2/while the NGINX logs are in /var/log/nginx/. For example:
goaccess /var/log/apache2/your_site.log
…will produce output similar to the image above.
You can see that the fields displayed include:
- Requests analyzed overall: This section provides a breakdown of total requests, unique visitors, requested files, referrers, and more.
- Unique users per day (including spiders): This section shows a bar chart of the number of visitors per day.
- Requested file (URL): Shows a list of the 7 most visited URLs along with their total bandwidth, total number of hits, and percentage of traffic.
- Static request: These are requests for files that are not HTML. Usually CSS or an image.
- URL not found (404): Shows URLs that were requested but not found. Unless your site is well configured, these could be bots aiming at commonly used targets such as login, settings, and configuration pages.
- Visitor’s hostname and IP: Shows the IP addresses of the 7 most frequent visitors. If the hostname is available, it will also be displayed. These may belong to your RSS feed reader.
- operating system: This will show you the most common operating systems for users visiting your site.
- browser: The most common browser to access your site.
- Reference site: Where did the visitor land on a particular page?
Analyzing a single log file is fun, but analyzing multiple files at the same time can give you an idea of how your site is performing over time. Feed the entire log directory with:
goaccess /path/to/logs/*
Or selectively parse multiple log files as follows:
goaccess your-site.log your-site.log.1 your-site.log.2
View GoAccess analytics in your browser
Viewing the log file analysis in the terminal is the coolest way, but some people prefer to view the stats using their browser.
GoAccess can generate and update HTML files in real time using:
goaccess /path/to/log/file.log -o /path/to/report.html
then you can open report.html in your browser.
If you want your GoAccess report to be accessible from a web address, write the report to an HTML directory on your website.
Use sudo if you are not running GoAccess as the root user or if the user does not have write permissions to the HTML directory. for example:
goaccess /path/to/log/file.log -o /var/www/your-site-root-directory/report.html --real-time-html
You can then access the reports from any machine at: https://your-site.tld/report.html.
As you can imagine, the report is much prettier than what you see in the terminal, but it contains the same information and elements are clickable. To change from the default theme, gear Click to select dark grey, bright, dark blue, or dark purple.
You can also choose the number of items and layouts per page.
GoAccess isn’t the only privacy-friendly alternative to Google Analytics
Running GoAccess on a Linux server is easy. This means you don’t have to leave the comfort of your device even if you don’t want to use it.
Google Analytics is not the only option if you want to view your site analytics in your browser. There are some great privacy-friendly alternatives to Google Analytics.