Today I set up Google Analytics with Jekyll Minima. I learned a few things:

It looks like a one line change

In theory, setting it up is very straightforward. You simply have to add a line of code to the config file:

# _config.yml
google_analytics: YOUR-MEASUREMENT-ID

Modifying the build command

But it didn’t work at first. In the head.html it only includes the analytics if jekyll.environment == 'production' (it works like that so you don’t track yourself in development). To achieve this, I modified the build command in Netlify.

I replaced this command (configured by default by Netlify):

bundle exec jekyll build

For this one:

JEKYLL_ENV=production bundle exec jekyll build

Going with a custom solution

And it still didn’t work. Then I found this article that refers to this bug. Their recommended solution required installing a gem. I chose to keep my setup as it is and followed this custom solution. Now it works 👍.