Self-Hosting a Privacy Respecting Analytics Solution

Published on 04 May 2021 | Updated on 03 Jun 2022
Written by Pranav Chakkarwar
5 min to read


The “Free” Analytics

Collecting more and more data to keep feed the advertising business model and make money while sacrificing user privacy has become a trend on the internet. Everytime you visit a website or open an app you can expect companies like Google, Facebook, Microsoft, Amazon, among others to track you using their analytics and they can track you because the developer of the website/app embed third party analytics as they are “free” and “advanced”.

These analytics are often advanced and promise conversions, sales, etc, they are also free because the users pay them with the user’s data. Every website/app developer wants to understand their website traffic. But when your source of income is the website (e.g. e-commerce), you want to understand user behavior, interests, and gather more data points to either retarget them later to boost conversions. But if you are a developer and use these privacy-invading analytics it can come at a great cost for you as well as the users of your website. You may want to read Why is privacy improtant?

Self-Hosted Analytics

A self-hosted solution will give you complete control over your collected data and its storage. You can even self-host it on a raspberry pi and start collecting analytics right away.

There are other advantages of self-hosting an analytics solution, like bypassing AdBlockers. That sounds evil but as I don’t collect any personally identifiable data so it’s okay i guess :D

If you have are already using a third-party analytics solutions, they probably charge extra to serve the analytics from your custom domain. In case of a self-hosted instance, you can connect to multiple custom domains and subdomains at no cost.

Today we will host Ackee by electerious. It is a cookieless, non-invasive tracking solution that still providing useful insights.

Ackee has a great looking dashboard (Ackee dashoard demo) and the maintainer of this project also plans to support its development (correct me if I am wrong). If you want to support him, donate here.. So we can say it is a pay what you want to model (except for the hosting :p)

Let’s Get Started

My hosting stack will get you started for free (using Mongo DB, Netlify and Github) but you can also opt for other deploy options in the ackee documentation.

Requriments

Optionally

Setup a MongoDB Database

  1. Complete the sign up process at Mongo DB.

  2. Create a free cluster Create a new MongoDB cluster

  3. Choose your cluster hosting options. I am deploying an AWS cloud instance in Ireland. Choose your cluster hosting options

  4. Configure the connection details for the deployed cluster. Configure the connection details for the cluster

  5. Choose the username and password for the atlasAdmin. Save these details as you will need them when connecting to the database from the Ackee instance. Choose the username and password for the atlasAdmin

  6. Now allow access to the cluster from anywhere by adding the 0.0.0.0/0 IP address. The Serverless function will run at the closest possible server so allow access from anywhere is necessary. Don’t worry the username and password will prevent anyone else from accessing your instance. Allow access from anywhere to the cluster

Deploying Ackee Frontend and Serverless Functions

  1. This is the easiest step because you can deploy it to Netlify with a click of a button.

    Deploy on Netlify

  2. Set the Netlify Environment variables.

Set the Netlify Environment variables

mongodb+srv://ADMIN_USERNAME:ADMIN_PASSWORD@cluster0.mongodb.net/FIRST_DATABASE?retryWrites=true&w=majority

Install a JS Snippet on Your Website

  1. You can either use Ackee from Netlify’s subdomain or add a custom domain in the netlify site settings. Avoid using subdomains like analytics or stats to stay away from Adblockers.

  2. Log into Ackee dashboard, go the settings tab, add a website name and copy it’s tracking code. Add your website from the settings tab

  3. The most privacy-respecting settings when installing the tracking script on your website can be set using data ops in the ackee tracker script.

In this example script, data-ackee-opts=’{“detailed”: false, “ignoreLocalhost”: true, “ignoreOwnVisits”: false} will ensure that any personal data is not collected and no cookies will be set because the ackee tracker will not ignore own visits.

<script async src="https://subdomain.domain.tld/tracker.js" data-ackee-server="https://subdomain.domain.tld" data-ackee-domain-id="DOMAIN_ID" data-ackee-opts='{"detailed": false, "ignoreLocalhost": true, "ignoreOwnVisits": false}'></script>

To start tracking, insert this script before the body tag of every page of your website. It is similar to installing any other analytics.

Some Alternatives

  1. Umami.is
  2. Matomo


That's it!

I hope you enjoyed this article, as there are - No ads. No trackers. No paywall. No shilling. No affiliate links. No baised opinions. I put a lot of thought into each article, but I'm not perfect. Feedback is always appreciated.

Explore other articles
Contact me
Hire me
Subscribe