How to setup Ackee Analytics on Hugo with Docker and Traefik

Ackee

Ackee live demo

Traefik

Hugo

intro

You are pro-privacy why are you using a TRACKER on your website!?

Well, it’s the only way for me to know if anyone even reads my blog.

Also, it’s ethical and everything you’re interested on will be answered in the Ackee section.

what is Ackee

As mentioned in their website:

Self-hosted, Node.js based analytics tool for those who care about privacy. Ackee runs on your own server, analyzes the traffic of your websites and provides useful statistics in a minimal interface.

why use it

It’s:

  • Open source
  • Beautiful
  • Cookie-free and secure
  • Self Hosted
  • Easy to integrate
  • No personal data is colleted
  • Only anonymous data is collected
  • No fingerprinting

Hooked? Let’s start.

configuration

Ackee

docker-compose.yaml file goes as follows:

version: "2"
services:
  ackee:
    image: electerious/ackee
    container_name: ackee
    restart: always
    environment:
      - WAIT_HOSTS=mongo:27017
      - ACKEE_MONGODB=mongodb://mongo:27017/ackee
    env_file:
      - .env
    depends_on:
      - mongo
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=proxy"
      # Middleware for CORS headers
      - "traefik.http.middlewares.corsheaders.headers.accesscontrolallowmethods=GET,POST,PATCH,OPTIONS"
      - "traefik.http.middlewares.corsheaders.headers.accesscontrolalloworiginlist=https://kerezius.lt"
      - "traefik.http.middlewares.corsheaders.headers.accessControlAllowHeaders=Content-Type"
      # HTTP endpoint - redirected
      - "traefik.http.routers.ackee.entryPoints=web"
      - "traefik.http.routers.ackee.rule=host(`analytics.kerezius.lt`)"
      - "traefik.http.middlewares.ackee-redirect.redirectScheme.scheme=https"
      - "traefik.http.middlewares.ackee-redirect.redirectScheme.permanent=true"
      - "traefik.http.routers.ackee.middlewares=ackee-redirect"
      # SSL endpoint
      - "traefik.http.routers.ackee-ssl.entryPoints=websecure"
      - "traefik.http.routers.ackee-ssl.rule=host(`analytics.kerezius.lt`)"
      - "traefik.http.routers.ackee-ssl.tls=true"
      - "traefik.http.routers.ackee-ssl.tls.certResolver=le"
      - "traefik.http.routers.ackee-ssl.service=ackee-ssl"
      - "traefik.http.routers.ackee-ssl.middlewares=corsheaders"
      - "traefik.http.services.ackee-ssl.loadBalancer.server.port=3000"

  mongo:
    image: mongo
    container_name: mongo
    restart: always
    volumes:
      - ./data:/data/db

networks:
  default:
    external:
      name: proxy

You also have to create .env file in the same directory as docker-compose.yaml

ACKEE_USERNAME=username
ACKEE_PASSWORD=password

These credentials will be your admin login.

The most important part is CORS headers, without them tracker.js will be unable to communicate with ackee server.

# Middleware for CORS headers
      - "traefik.http.middlewares.corsheaders.headers.accesscontrolallowmethods=GET,POST,PATCH,OPTIONS"
      - "traefik.http.middlewares.corsheaders.headers.accesscontrolalloworiginlist=https://kerezius.lt"
      - "traefik.http.middlewares.corsheaders.headers.accessControlAllowHeaders=Content-Type"

where

 - "traefik.http.middlewares.corsheaders.headers.accesscontrolalloworiginlist=https://yourSiteDomain.com

Everything else can be left as is (of course routers and ssl have to be configured according to your setup).

Now do the whole docker-compose up -d dance and go to the URL you Ackee server is hosted on.

You should be greeted with a login page, enter your credentials and go to Settings, press New Domain and copy Embed code, then paste it into your Hugo config.

Process is described in the next section.

hugo

I’m using a theme named Hermit. Conveniently it has an html file where you can put your tracker.js script (many themes have it).

It’s located at

layouts/partials/analytics.html

Paste your Embed code here. On my end it looks like this:

{{ template "_internal/google_analytics_async.html" . }}
<script async src="https://analytics.kerezius.lt/tracker.js" data-ackee-server="https://analytics.kerezius.lt" data-ackee-domain-id="audited">
</script>

REMEMBER TO DISABLE AD AND/OR TRACKER BLOCKER IN YOUR BROWSER

Now reload your page a couple of times and you should see some new entries in your Ackee dashboard.

And that’s pretty much it.


hosting

367 Words

2020-11-03 09:49 +0000