Adding analytics to your website
Published on
Initially I setup Google Analytics because I had used it before on a previous project, and spotted that there is a Hugo integration. But I got thinking that there must be information about how to use the information straight from CloudFront. This great article confirmed my suspicions!
Google Analytics
Setting up Google Analytics with Hugo is as simple as adding your Google Analytics id to the config.yaml. I didn’t look into whether this then assumes that the theme you are using also supports this, or whether there is other magic so that it ‘just works’. Anyway, setup took less than 5 minutes, and you can quickly confirm that it’s working, by opening the website in your browser, and following the ’live’ page views on your phone.
Don’t forget to turn off your ad-blocker before testing ;-)
CloudFront
Using CloudFront has the benefit that you’ll still see page views even with an ad-blocker. But of course the interface is much more limited. Still it’s a useful tool if you don’t want to setup Google Analytics.
Getting indexed
Search Engine Optimization (SEO) is a massive topic that I don’t
want to get into. But adding a simple robots.txt that points to
the sitemap.xml should help the website to get indexed by Google
without needing to be crawled too often, thus keeping my bandwidth
bill low. Once again Hugo has a tool for that out-of-the-box.
You just need to add enableRobotsTXT: true
to your config.yaml.
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License .