How to Add Google Analytics to Hugo Theme
Date: 2018-08-29 |
DISCLOSURE: If you buy through affiliate links, I may earn a small commission. (disclosures)
Problem: I have a Hugo theme (currently using manis-hugo-theme) and I want to use Google Analytics to keep track of my traffic. How do I do this?
Solution:
Hugo actually has a really awesome built-in solution that you can read about in their guide Google Analytics with Hugo.
Basically, you can just add this line to your config.toml:
googleAnalytics = "my-google-analytics-code"
Then you can add the internal template that Hugo maintains by adding this line somewhere in your header partial (so that the Google Analytics JS payload is generated on each page):
{{ template "_internal/google_analytics_async.html" . }}
Simple as that, your Hugo site is backed by Google Analytics.
Want more like this?
The best way to support my work is to like / comment / share for the algorithm and subscribe for future updates.