How to install the new Google Analytics 4 code to your site? #248
Replies: 3 comments 3 replies
-
I just stumbled across this. I use a different template ( |
Beta Was this translation helpful? Give feedback.
-
I was trying and trying and it wasn't working until I noticed I was using Brave browser to test my site. Lol |
Beta Was this translation helpful? Give feedback.
-
Google Analytics is now using the new
gtag.js
tracking code. But Hugo's internal GA template doesn't work with the new code yet. So, I just wanted to give a heads up to people who're not sure how to get it to work.The code looks something like this -
G-XXX012XXYY
. And updating theconfig.yaml
with that code instead of the olderUA-XXX012XXYY
wouldn't work. Fortunately & thanks for @adityatelange's forward thinking, you can easily integrate the new code with ease.So, here's how you do it.
Ensure you've updated your
config.yml
is updated with the new code. So, replace the older value ofGoogleAnalyticsID
with the newG-XXX012XXYY
.Copy & paste the following
gtag.js
snippet intoextend_head.html
:Ensure your browser isn't blocking any JavaScript & tracking cookies while running the
hugo server
in the background. Check your site loads properly onlocalhost:1313
& you should see something similar to the image below on your Google Analytics dashboard.Beta Was this translation helpful? Give feedback.
All reactions