Quit Google Analytics and use self-hosted Gatsby statistics with Ackee
By: Alec Brunelle
Tags: Analytics, Privacy, Programming, JavaScript, Gatsbyjs

Photo by Hal Gatewood on Unsplash

There are many different goals one can have when it comes to hosting your own website or blog. For me, it means just having a place where I own the content of my words and can customize to my liking. When it comes to analytics, my needs aren’t many — most of my audience reads my content via platforms like dev.to or Medium. All I need to know is how many people visit my site, which posts are doing well, and where users come from (referral links).

Given my recent obsessive elimination of all things tracking and advertising in my life, I chose to stop supporting Google and move from Google Analytics to something self-hosted. It wasn’t an easy product to use and most of the features were useless to me as I don’t sell anything on my blog. This way I own the data and am not contributing it to a company that could potentially use it in malicious ways.

I set out to search for a new tracking tool for my blog. My criteria for choosing a new product were:

Be simple.

Have features I will use.

Have a focus on privacy.

Be built with a programming language I know, so making changes is easy.

Be able to easily host on a Platform-as-a-Service like Heroku

Have the ability to be easily added to a Gatsby blog

Have an option to not collect unique user data such as OS, browser info, device, and screen size

Meet Ackee

Beautiful, isn’t it

I came across Ackee, a self-hosted analytics tool, and found that it fit my requirements almost perfectly. It’s built using Node.js, which I have experience of, and it focuses on anonymizing the data that it collects. Read more information on how Ackee anonymizes data here.

The steps you need to take to start collecting statistics with Ackee are to start running it on a server, Heroku in my case, add the Javascript tracker to your Gatsby site and test to see if the data is flowing correctly.

This a detailed guide on how I went about deploying it to Heroku. After, I contributed a Deploy-to-Heroku button which deploys it in one-click. Find the button here.

Up and running on Heroku

First, you have to start running the server which is going to receive the tracking data from your website.

Create a new Heroku app instance:

Use the heroku-cli to upload the code:

Configure a MongoDB add-on — this is where the data is stored:

Configure the environment variables:

Voila — you’re finished! That was easy, wasn’t it?

Open up the webpage that Heroku automatically configures for you — it should be https://ackee-server.herokuapp.com/ — and you should see this:

The login page!

Adding the tracker

Now we need to send data over from the website to the server we now have running on Heroku. If you’re using Gatsby, this is incredibly easy with the plugin.

Install the tracker:

npm install gatsby-plugin-ackee-tracker

Create a domain on Ackee and get the domain id. Find this option in the settings tab of your Ackee instance.

Add it to your Gatsby config.

Run the site locally:

gatsby develop

Testing to make sure it worked

Open up your site at http://localhost:8000 and go to a new URL.

Observe the network requests your site is sending. You will notice it now sends requests to your Heroku instance.

The Brave dev tools

We now have the server running Ackee and our Gatsby sending analytics!

What you get

Let’s explore Ackee.

Home page with total site views

List of referrers