Cannot get hooks to work in Hugo Docs Theme

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.

  1. so I downloaded the module hugo mod get github.com/hugomods/umami-analytics
  2. added imports: path: github.com/hugomods/umami-analytics to my config/_default/module.yaml,
  3. then I copied the layouts/_partials/site_head.html file in vendor into my own repo (layouts/partials/site_head.html) NOT the _partials folder.
    • :red_question_mark: should I have place it in the _partials instead?
  4. 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.
    • :red_question_mark: If site_head.html is not the correct file, which file should I use?
  5. then I made sure to turn on the parameter by adding the following to my hugo.yaml file: (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"]
  1. Now, I’m not sure if I should have included services: or simply params: 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.

Which version of Hugo are you running locally?
Which version of Hugo are you running remotely (Netlify)?

For anyone else looking into this, here’s the relevant documentation:
https://docs.hugoblox.com/guides/extend/#hooks

cc: @alcarazr

Hi, apologies, forgot to add these:
Hugo running locally: hugo v0.151.2 / go1.25.3
Hugo running on Netlify: hugo v0.152.1 / go1.22.6
so yes I do have a mismatch and will now update. although I don’t think these mismatch would be the cause of hooks being ignored? and yes I’ve looked indeed looked at the documentation page and followed it. but still no joy.

Which version of HugoBlox? I have no idea which version is compatible with Hugo v0.151.2 and later.

You might consider raising your question here:
https://github.com/HugoBlox/hugo-blox-builder/discussions

Make sure you’re using the latest version of Hugo Blox. Hooks were fixed not long ago.

1 Like