Unfortunately, I have spent the last 24 hours so deep in the google seo suite it’s sending me that “u up?” text at 3am. Somehow more true to the analogy than I care to admit, the entire expierence has been a disapointment for everyone involved, in ways that prior to this experience I would have thought impossible.
I think this screenshot sums up the experience pretty well:
Anyway, I’m not here to talk about how much I hate google, I’m here to talk about how to set up a google analytics 4 tag on a hugo site. This will hopefully be short and sweet, but I’m not making any promises.
Throw out your tag manager snippet.
Normally I use the google tag manager to handle the tags, mainly for ease of updating with 101 random cookies and tracking pixels. HOWEVER, using the honest to god snippet they provide for the tagmanager just straight up does not work (citing being depricated, only for the help docs to be cyclical and not actually provide a solution).
Set up a new property in google analytics 4
simples.
Add the Tag to the Website
So this will slightly differ depending on how you want to lay out your config. I’m setting mine to params.seo.ga4, but you can set it to whatever you want.
[params.seo.ga]
ID = "G-XXXXXXXXXX"
once thats in place create a new file in layouts/partials called ga4.html
|
|
Bonus Copilot suggestion:
|
|
You can add this optional dataLayer script for an easy entry point for custom events
|
|
Add the Tag to the Header
Add the following to the header partial
|
|
The only thing left to do is to test it, and then wait for the data to come in.
Personally I swear by this plugin, it’s originally for chrome but it’s been ported to firefox and works great. You can find it here: https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna
Comments....