Notes on Hugo for Beginners (and Me), Part 5, GDPR and Cookies

9 Jan 2022 2-minute read Al Eardley

As a good digital citizen, I need to consider legislation such as GDPR (and from Wikipedia) and comply with it.

Hugo has page on GDPR but I could not see any details on setting up a consent banner for cookies.


To create a cookie consent notice I followe the excellent blog from LittleBigTech.

This approach consists of a few simple steps:

  1. Create a partial called cookie-consent.html
  2. Replace the reference to analytics with this partial
    • In my case I had a patrtial that inclded the gtag from the config, so I updated the code provided to use this approach rather than hard coding the gtag
  3. Add a content/ file that the “info” link directs to.
    • I took the content from LittleBigTech as it nicely summarises that all I do is capture data for analytics purposes

Tailor for my site

The next step was to ensure that the notice about the cookies was layed out in a way that matches by site and the brand. This was easy enough to do through changes to the HTML in cookie-consent.html and the CSS.


I now have a prompt in the left side bar of my site that controls whether or not details are captured for Google Analytics. It is in that location so that when the site compresses for mobile viewing, the prompt is at the top of the page before the content rather than after all the content.

Table of Contents

Comment on this post: