Nat TaylorBlog, AI, Product Management & Tinkering

Web Analytics with awstats in 2018

Published on .

There are a wealth of free web analytics tools (like Google Analytics,) but they add overhead to every page load, require webmasters to relinquish control, inherently employ third-party user tracking and are may be redundant to existing processes. The alternative is to just use access logs and software like awstats, which is just what I’ve opted for, but with customization (since everything is worth over engineering!) including:
  1. Multisite Summary
  2. Static Generation
  3. Custom Theme
  4. Breadcrumbs
  5. Log merging
  6. Basic Auth
Here is a screenshot of the stats portal.
Themed multisite summary dashboard for awstats
My server already stores access logs and processes them with awstats every day, but I found it painful to log into CPanel then check site by site.  (SSL is also tracking separately from non-SSL, which was annoying.) Multisite summary was something I craved.  After much deliberation, I realized that the awstat “databases” (text files) already had the required SiteVisit and SiteVisitor counts, so it was only a few lines of code to read and combine them. Once they were summarized though, I needed a quick way to access them preferably without a CPanel session and without checking HTTP and SSL separately.  I accomplished this first by merging the “databases” with AwstatsParser, then by generating static reports.  Manually building the awstats reports was a bit tricky to figure out, as the awstats.conf files must be in the same directory as awstats.pl and the working directory must be the location of the awstats.pl script. With that sorted out, it was a short script to generate static copies of the reports, get the paths right for the assets (icons, css, etc) and putting them somewhere web accessible.  My server also stores all of the “database text files in the same directory key by their subdomain, so I settled on a config.json file to specify which to process and how to map them to their actual domain name. Lastly came theming and breadcrumbs.  awstats allows a configurable stylesheet, making theming quite simple (especially if you just borrow from kogakure’s gitweb theme like I did.)  The breadcrumbs are accomplished by using a form of str_replace('{{breadcrumbs}}',$breadcrumbs) which is lazy but works fine. Accessing the result requires SSL and basic auth credentials.

Post Navigation

«
»