Posted on April 13, 2019Tweet
For the last couple of years I have been trying to reduce my dependency on Google's services, one of the harder services I found to replace was Google Analytics for this website. To be fair to Google Analytics it is very handy and easy to setup (like most of Google's services). Once you have it all working you don't really have to worry about it and you can just leave it there working away. There are also a lot of advanced features available but I never really felt the need for them since this is just a basic blog. All I was ever interested in was the amount of hits and where in the world they were coming from.
I had a couple of requirements for a self-hosted analytics solution. Firstly it would have to be fairly lightweight as it would have to share resources with this web server which runs on a small t2.micro AWS instance with one vCPU core and 1GB RAM. This blog runs in a simple docker container with Nginx. docker-compose is used for some basic orchestration so an analytics solution with a docker image available would be ideal. An open source solution would be preferred too.
Matomo was the solution that I landed on which fulfilled everything I needed. I had to setup a reverse proxy in order to deploy Matomo to the same AWS instance as the web server. Traefik is the reverse proxy I went with. As a bonus I was able to configure automated SSL certs from LetsEncrypt to secure this page over HTTPS. Matomo also requires a MariaDB instance. Luckily Bitnami have docker images available for Matomo and MariaDB. In order to deploy these all I had to do was add the following and run docker-compose up:
mariadb: image: 'bitnami/mariadb:latest' networks: - default environment: - MARIADB_USER=xxxxxx - MARIADB_DATABASE=xxxxxx volumes: - 'mariadb_data:/bitnami' matomo: image: 'bitnami/matomo:latest' networks: - web - default environment: - MARIADB_HOST=xxxxxx - MARIADB_PORT_NUMBER=xxxxxx - MATOMO_DATABASE_USER=xxxxxx - MATOMO_DATABASE_NAME=xxxxxx - MATOMO_USERNAME=xxxxxx - MATOMO_PASSWORD=xxxxxx labels: - "traefik.docker.network=web" - "traefik.enable=true" - "traefik.frontend.rule=Host:careyscloud.ie" - "traefik.port=80" - "traefik.basic.protocol=http" depends_on: - mariadb volumes: - 'matomo_data:/bitnami'
Another solution I came across was called Fathom although that did not seem as mature or feature rich as Matomo.
If you are running Google Analytics to track any of your personal sites, I definitely recommend giving Matomo a go! A couple of caveats though, obviously there is a bit more overhead in managing Matomo when compared to Google Analytics & there is also some potential of downtime in the early stages until you have it setup just as you like it.
Brian Carey | DevOps Engineer