How to self host a Privacy respecting analytics solution?

How to self host a Privacy respecting analytics solution?

Written by Pranav Chakkarwar on 04 May 2021 • 7 minutes to read

Privacy WebDev

Big tech companies collect more and more data to keep their advertising business model make money while sacrificing user privacy in the process. They analyze personal data from end-users of apps, websites, services that use their analytics. These companies include Google, Facebook, Microsoft, Amazon, and many others. If some data points are missed out, they buy them from smaller companies. These are even worse because their primary business is to sell the data in the open market to multiple companies.

Instead of opting out, they don’t even let you opt in to sell your data. For example, Disqus commenting platform provides an opt-out link, saying DON’T SELL MY DATA.

Disqus bad privacy settings

Why are big tech analytics used in the first place?

These advanced conversion-boosting analytics are free because we pay them with the user’s data. Every website owner 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 it comes with a great cost of privacy for you as well as the users of your website. You may want to read Why is privacy improtant?

Other privacy friendly analytics
  1. Simple Analytics
  2. Plausible Analytics
  3. Fathom Analytics
However, I chose to host my analytics myself.

There are several advantages of self-hosting an analytics solution. As I don’t collect any personally identifiable data, I want to bypass AdBlockers. Third-party analytics solutions often charge extra to serve the analytics from your custom domain. A self-hosted instance can connect to multiple custom domains and subdomains at no cost.

I have complete control over my data and its storage. I can even self-host it on raspberry pi and start collecting analytics right away with a reverse proxy solution.

Ackee can track any number of websites, easily create new websites from the dashboard, filter collected data by referrers, and more.

It can be implemented as a cookieless tracking solution while 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. Thus making it pay what you want to model (except for the hosting :p)

Let’s host it

I am currently using ackee for this website. My hosting stack will get you started for free or you can check out other deploy options in the ackee documentation.

Requriments

Optionally

Setup up the MongoDB server
  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 the ackee frontend and the Serverless function
  1. This is the easiest step because you can deploy it to Netlify with a click of a button. Other deployment options are available in the ackee documentationDeploy 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
Finally, install the tracking script on your website

You can either use ackee from the netlify subdomain or…

  1. Add a custom domain in the netlify site settings to serve the tracking script from a first-party resource. Avoid using subdomains like analytics or stats to stay away from Adblockers.

  2. Once you get the SSL, log into ackee and add your website from the settings tab and copy the 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 in the body of every page of your website.

That’s it you have successfully hosted a privacy-respecting analytics solution :D
UPDATE

I found a quicker way to deploy Ackee and MongoDB together on railway.app

Deploy on Railway

💁‍♀️ How to use
What’s different with railway.app?

If you know an even better way to host Ackee or know about any other self hosted analytics, make sure to leave a comment. Thank you for reading.



Get interesting articles delivered to your email 📨



Enjoyed this article?

Comments

Post a comment

Comments will be manually approved and will take time to reflect.

You may also Enjoy

A simple and effective guide to online privacy

A guide to online privacy

Published on 17 Jul 2021 • 5 minutes to read

Protecting our privacy online tends to be especially important nowadays, but arguing won't solve ...
A personal dashboard with bookmarks and search that works across browsers.

Crossbrowser personal dashboard

Published on 05 Jun 2021 • 1 minutes to read

A tutorial to setup a personal dashboard with bookmarks and search that works across browsers. No...
An interactive tutorial to implement a dark mode on any website.

Adding a dark mode to any website

Published on 02 Jun 2021 • 7 minutes to read

Adding a dark mode to a website is an excellent way to make it more visually appealing. It also m...
Understanding the importance of design with the help of dark patterns on the internet

Avoid using dark patterns!

Published on 27 May 2021 • 3 minutes to read

Dark patterns cause more harm than good! It not just the visuals that count but the whole experie...