Integrating Analytics to Your Static Site
In our last article, we added a custom domain email to build brand credibility. Now, let’s make your site smarter by adding Google Analytics — a free and powerful tool that helps you understand your visitors - who’s visiting, where they’re coming from, and what they’re doing.
Step 1: Create a Google Analytics Property
Head over to Google Analytics:
- Sign in with your Google account.
- Click Start Measuring.
- Enter an Account Name (e.g.,
eyerie). - Click Next, then give your Property a name (e.g.,
th3b1rdm2n-site). - Choose your Time Zone and Currency, then click Next.
- Choose your business size and industry, then click Next.
- Check the boxes that aligns with your business objective, then click Create.
- Check the Google Analytics Terms of Service Agreement and click I Accept.
Step 2: Get Your Measurement ID
You’ll now be on the Web Stream Details page:
- Click Web as the platform.
- Enter your site URL (e.g.,
th3b1rdm2n.site) and a stream name(e.g,th3b1rdm2n-site). - Click Create & continue.
- Click Next and copy the Measurement ID (starts with
G-).
We’ll use this ID to connect your Hugo site.
Step 3: Add the Tracking Code to Hugo
In your Hugo site’s root directory:
- Open the
params.toml(located atconfig/_default). - Add the following under
google_tag_manager_id(if using Clarity or a similar theme):
1# Google tag manager
2google_tag_manager_id = "G-XXXXXXXXXX"
Step 4: Rebuild and Deploy
After updating the config file, rebuild your site and push the changes to GitHub Pages:
1git add -u
2git commit -m "chore: added google analytics to site - $(date +%F_%H:%M)"
3git push -u
4git switch production
5git merge development
6git push -u
7git switch development
You're All Set 🎉
Now that Google Analytics is integrated, your Hugo site can give you insights into:
- Visitor locations
- Page popularity
- Traffic sources
- Device types
It’s a small step for your site, but a giant leap for understanding your audience.
For the full walkthrough, here’s a companion video: