Enabling Google Analytics and Misc Fixes
The What
Started simple enough - I just wanted to enable Google Analytics. Why you say? I wanted to play with it really. I am not doing any form of marketing for this blog (sharing, generating leads, ...), but I still wanted to see what Google Analytics will provide and to start getting familiar with it. Such knowledge never hurts.
The hike Begins
Like any sane person, I started with a web search. The first result looked promising; short, well formatted and recent enough. The gist is this:
- Copy the analytics code into its own file analytics.html in the _includes directory.
- Update the default.html in the _layout directory to include the newly created analytics file.
- A simple conditional check to exclude locally run instances from polluting the analytics data.
But it didn't work. The changes made perfect sense, but it was like I did nothing.
The hike becomes a journey
I started troubleshooting of course. After all, this was an opportunity to better understand how Jekyll works. I noticed that default.html was using a different syntax for includes, but switching between them did nothing. So, I decided to not include the changes and embed them directly into the default.html file. Also nothing. It was like Jekyll was not using this file at all.
So I went back to the basics and back to [minima documentation]. Shortly after, I found my first mistake, my default.html was misplaced; I put it in layout_ rather than the correct layouts_. Continued reading and found out that minia already supports Google Analytics out of the box. It only required that I add the tracking id to the site settings.
google_analytics: UA-XXXXXXXXX-Y
Commit, push and wait for Netlify Deploy to finish. Checking the page source code revealed that Google Analytics was still missing. But hey, minia doc writers are great and made it pretty clear was else was missing. The site must be ran in production mode; i.e. a variable named JEKYLL_ENV must be set to a value of production. So, heading over to Netlify > load the site settings > Build & Deploy > Environment and add the required variable. Finally I need to trigger a manual deploy (Adding that variable made no changes to the code base and hence I could not trigger my git workflow). So, Netlify > load the site again > Deploys then Trigger deploy > Deploy site.
Notes
While writing this post, I ventured more into Jekyll markdown where it turned out Jekyll supports several. The default markdown renderer is Kramdown.