Hi I’m new here.
I’m using the Hugo Docs Theme for a fairly straightforward static site (nothing fancy) that’s deployed via Netlify (but I don’t think my issue has anything to do with Netlify…please corret me if this is wrong).
Somehow I’m not able to get the hooks to work. The reason I’m even looking into using hooks is because I want to use umami analytics. The theme already supports some analytics, but NOT uamami, so per the instruction in the documentation I try it with hooks.
Approach 1
I’m not a web developer so I’m not familiar with a lot of the html/css structure. So what I did was I hugo vendor the theme and looked inside for the correct structure, and I found that the correct structure to place my hooks are inside layouts/_partials/hooks/body-end (at least that’s the folder in the vendor). So I created a script called umami.html with just one line that umami provided. However, this didn’t work. I know it didn’t work because I check the umami dashboard. Also, I try to test if the hooks are even being seen by creating a test.html file containing a single comment <!--TEST-->. I then cleared out cashe, hugo server an then looked at the source code. My test was not shown anywhere so I know that the hook is not been injected properly. Now, I’ve also try the same with partials not _partials and it made no difference.
Approach 2:
googling I found the hugomod/umami-analytics. and this is what I did.
- so I downloaded the module
hugo mod get github.com/hugomods/umami-analytics - added
imports: path: github.com/hugomods/umami-analyticsto myconfig/_default/module.yaml, - then I copied the
layouts/_partials/site_head.htmlfile in vendor into my own repo (layouts/partials/site_head.html) NOT the_partialsfolder.
should I have place it in the _partialsinstead?
- then I added
{{ partialCached "hugomods/umami-analytics/index" . .Params.analyze }}to the end of that copied file above the last</head>. (per instruction of the module), although the instruciton didn’t explictly say which file I’m suppose to be doing this in. It just says a html file with<head>...</head>in there.
If site_head.htmlis not the correct file, which file should I use?
- then I made sure to turn on the parameter by adding the following to my
hugo.yamlfile: (originally I only had “production” but because I’m on free tier of Netlify and can’t deploy too many times so I added “development” so I can test with just local preview)
params:
services:
umami_analytics:
enabled: true
src: "https://cloud.umami.is/script.js"
website_id: "MY UMAMI ID"
domains: "MYSITE.netlify.app"
environments: ["development","production"]
- Now, I’m not sure if I should have included
services:or simplyparams: umami_analytics:would be enough. although I’ve tried both and neither worked.
can someone please help? either in terms of approach 1 (using raw script) or approach 2 (using a module). I don’t know exactly what I’m doing wrong.
thanks.