divinerites / plausible-hugo

Dead simple integration between plausible.io and gohugo.io
GNU General Public License v3.0
108 stars 12 forks source link

Confused about Step 3 of instructions: "<head>" section #15

Closed firasm closed 2 years ago

firasm commented 2 years ago

sorry, fat fingers hit create issue too quickly.

Hello,

I've got a website using the WowChemy Academic Resume theme, and I'm on the latest version and things seem to be done slightly differently, so I'd love some help about Step 3 of the three easy steps in the README file:

  1. Call the partial plausible_head.html in your own section.

My question is how/where do I actually do this?

I am using a config.yml file and I'd like to install it using the plausible-hugo module way. I've done it like so:

module:
  imports:
    - path: github.com/wowchemy/wowchemy-hugo-themes/modules/wowchemy-plugin-netlify-cms
    - path: github.com/wowchemy/wowchemy-hugo-themes/modules/wowchemy-plugin-netlify
    - path: github.com/wowchemy/wowchemy-hugo-themes/modules/wowchemy/v5
    - path: github.com/divinerites/plausible-hugo

Then, I created a new file called head.html in partials/ like so and added the snippet as suggested (I also tried extra_head.html):

<head>
   ...
   {{ partial "plausible_head.html" . }}
   ...
</head>

Is this the right thing to do ? Should this now work? Unfortunately I don't see the plausible.io js in my source when I try to look at the source of the website, nor has the site picked up any traffic.

Here is my directory structure (you'll notice there is no themes directory).

Screen Shot 2022-08-15 at 9 31 52 PM

P.S. I'd be happy to contribute some additional instructions back as a PR if I can get this to work. Thanks in advance for your work on this!

divinerites commented 2 years ago

This is not related to this module. This is just HTML/hugo related.

You have to add this line {{ partial "plausible_head.html" . }} in the file in your theme code where the <head> section is treated. Make a search for <head> to find the file.

What you have done is just create a new partial, not related with the module, and not called from your theme.

I advice you to learn about how hugo and your theme works.

firasm commented 2 years ago

Hello @divinerites, I appreciate that you cannot be expected to provide support for all the hundreds of Hugo themes out there.

I thought I'd report back my findings for anyone that finds this issue using any of the wowchemy themes/templates:

Here are the new instructions on how to inject code into the section:

How can I add custom metadata to my website’s tag?

Create a file at layouts/partials/hooks/head-end/custom.html and paste your HTML tags within it.

For older sites prior to v5.6, create a file at layouts/partials/custom_head.html instead.

I have done this, and it seems to inject the partial correctly, but there is a new error.

The relevant portion of my config.yaml looks like this:

params:
  plausible:
    - enable: true  # Whether to enable plausible tracking
      domain: firas.moosvi.com  # Plausible "domain" name/id in your dashboard

(I already tried putting single and double quotes around the domain).

▶ hugo server -D
Start building sites … 
hugo v0.101.0+extended darwin/arm64 BuildDate=unknown
ERROR 2022/08/16 07:54:57 render of "page" failed: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/wowchemy/wowchemy-hugo-themes/modules/wowchemy/v5@v5.6.0/layouts/_default/baseof.html:5:3": execute of template failed: template: _default/single.html:5:3: executing "_default/single.html" at <partial "site_head" .>: error calling partial: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/wowchemy/wowchemy-hugo-themes/modules/wowchemy/v5@v5.6.0/layouts/partials/site_head.html:319:5": execute of template failed: template: partials/site_head.html:319:5: executing "partials/site_head.html" at <partial "functions/get_hook" (dict "hook" "head-end" "context" .)>: error calling partial: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/wowchemy/wowchemy-hugo-themes/modules/wowchemy/v5@v5.6.0/layouts/partials/functions/get_hook.html:13:9": execute of template failed: template: partials/functions/get_hook.html:13:9: executing "partials/functions/get_hook.html" at <partial $partial_path $context>: error calling partial: "/Users/firasm/Sync/Personal/firas.moosvi.com/layouts/partials/hooks/head-end/custom.html:1:3": execute of template failed: template: partials/hooks/head-end/custom.html:1:3: executing "partials/hooks/head-end/custom.html" at <partial "plausible_head.html" .>: error calling partial: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/divinerites/plausible-hugo@v1.17.2/layouts/partials/plausible_head.html:2:4": execute of template failed: template: partials/plausible_head.html:2:4: executing "partials/plausible_head.html" at <partial "plausible_check.html" .>: error calling partial: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/divinerites/plausible-hugo@v1.17.2/layouts/partials/plausible_check.html:2:7": execute of template failed: template: partials/plausible_check.html:2:7: executing "partials/plausible_check.html" at <isset site.Params.plausible "analytics">: error calling isset: isset unable to use key of type string as index
ERROR 2022/08/16 07:54:57 render of "page" failed: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/wowchemy/wowchemy-hugo-themes/modules/wowchemy/v5@v5.6.0/layouts/_default/baseof.html:5:3": execute of template failed: template: _default/single.html:5:3: executing "_default/single.html" at <partial "site_head" .>: error calling partial: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/wowchemy/wowchemy-hugo-themes/modules/wowchemy/v5@v5.6.0/layouts/partials/site_head.html:319:5": execute of template failed: template: partials/site_head.html:319:5: executing "partials/site_head.html" at <partial "functions/get_hook" (dict "hook" "head-end" "context" .)>: error calling partial: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/wowchemy/wowchemy-hugo-themes/modules/wowchemy/v5@v5.6.0/layouts/partials/functions/get_hook.html:13:9": execute of template failed: template: partials/functions/get_hook.html:13:9: executing "partials/functions/get_hook.html" at <partial $partial_path $context>: error calling partial: "/Users/firasm/Sync/Personal/firas.moosvi.com/layouts/partials/hooks/head-end/custom.html:1:3": execute of template failed: template: partials/hooks/head-end/custom.html:1:3: executing "partials/hooks/head-end/custom.html" at <partial "plausible_head.html" .>: error calling partial: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/divinerites/plausible-hugo@v1.17.2/layouts/partials/plausible_head.html:2:4": execute of template failed: template: partials/plausible_head.html:2:4: executing "partials/plausible_head.html" at <partial "plausible_check.html" .>: error calling partial: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/divinerites/plausible-hugo@v1.17.2/layouts/partials/plausible_check.html:2:7": execute of template failed: template: partials/plausible_check.html:2:7: executing "partials/plausible_check.html" at <isset site.Params.plausible "analytics">: error calling isset: isset unable to use key of type string as index
ERROR 2022/08/16 07:54:57 render of "page" failed: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/wowchemy/wowchemy-hugo-themes/modules/wowchemy/v5@v5.6.0/layouts/_default/baseof.html:5:3": execute of template failed: template: _default/single.html:5:3: executing "_default/single.html" at <partial "site_head" .>: error calling partial: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/wowchemy/wowchemy-hugo-themes/modules/wowchemy/v5@v5.6.0/layouts/partials/site_head.html:319:5": execute of template failed: template: partials/site_head.html:319:5: executing "partials/site_head.html" at <partial "functions/get_hook" (dict "hook" "head-end" "context" .)>: error calling partial: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/wowchemy/wowchemy-hugo-themes/modules/wowchemy/v5@v5.6.0/layouts/partials/functions/get_hook.html:13:9": execute of template failed: template: partials/functions/get_hook.html:13:9: executing "partials/functions/get_hook.html" at <partial $partial_path $context>: error calling partial: "/Users/firasm/Sync/Personal/firas.moosvi.com/layouts/partials/hooks/head-end/custom.html:1:3": execute of template failed: template: partials/hooks/head-end/custom.html:1:3: executing "partials/hooks/head-end/custom.html" at <partial "plausible_head.html" .>: error calling partial: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/divinerites/plausible-hugo@v1.17.2/layouts/partials/plausible_head.html:2:4": execute of template failed: template: partials/plausible_head.html:2:4: executing "partials/plausible_head.html" at <partial "plausible_check.html" .>: error calling partial: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/divinerites/plausible-hugo@v1.17.2/layouts/partials/plausible_check.html:2:7": execute of template failed: template: partials/plausible_check.html:2:7: executing "partials/plausible_check.html" at <isset site.Params.plausible "analytics">: error calling isset: isset unable to use key of type string as index
ERROR 2022/08/16 07:54:57 render of "page" failed: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/wowchemy/wowchemy-hugo-themes/modules/wowchemy/v5@v5.6.0/layouts/_default/baseof.html:5:3": execute of template failed: template: _default/single.html:5:3: executing "_default/single.html" at <partial "site_head" .>: error calling partial: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/wowchemy/wowchemy-hugo-themes/modules/wowchemy/v5@v5.6.0/layouts/partials/site_head.html:319:5": execute of template failed: template: partials/site_head.html:319:5: executing "partials/site_head.html" at <partial "functions/get_hook" (dict "hook" "head-end" "context" .)>: error calling partial: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/wowchemy/wowchemy-hugo-themes/modules/wowchemy/v5@v5.6.0/layouts/partials/functions/get_hook.html:13:9": execute of template failed: template: partials/functions/get_hook.html:13:9: executing "partials/functions/get_hook.html" at <partial $partial_path $context>: error calling partial: "/Users/firasm/Sync/Personal/firas.moosvi.com/layouts/partials/hooks/head-end/custom.html:1:3": execute of template failed: template: partials/hooks/head-end/custom.html:1:3: executing "partials/hooks/head-end/custom.html" at <partial "plausible_head.html" .>: error calling partial: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/divinerites/plausible-hugo@v1.17.2/layouts/partials/plausible_head.html:2:4": execute of template failed: template: partials/plausible_head.html:2:4: executing "partials/plausible_head.html" at <partial "plausible_check.html" .>: error calling partial: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/divinerites/plausible-hugo@v1.17.2/layouts/partials/plausible_check.html:2:7": execute of template failed: template: partials/plausible_check.html:2:7: executing "partials/plausible_check.html" at <isset site.Params.plausible "analytics">: error calling isset: isset unable to use key of type string as index
Error: Error building site: failed to render pages: render of "page" failed: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/wowchemy/wowchemy-hugo-themes/modules/wowchemy/v5@v5.6.0/layouts/_default/baseof.html:5:3": execute of template failed: template: _default/single.html:5:3: executing "_default/single.html" at <partial "site_head" .>: error calling partial: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/wowchemy/wowchemy-hugo-themes/modules/wowchemy/v5@v5.6.0/layouts/partials/site_head.html:319:5": execute of template failed: template: partials/site_head.html:319:5: executing "partials/site_head.html" at <partial "functions/get_hook" (dict "hook" "head-end" "context" .)>: error calling partial: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/wowchemy/wowchemy-hugo-themes/modules/wowchemy/v5@v5.6.0/layouts/partials/functions/get_hook.html:13:9": execute of template failed: template: partials/functions/get_hook.html:13:9: executing "partials/functions/get_hook.html" at <partial $partial_path $context>: error calling partial: "/Users/firasm/Sync/Personal/firas.moosvi.com/layouts/partials/hooks/head-end/custom.html:1:3": execute of template failed: template: partials/hooks/head-end/custom.html:1:3: executing "partials/hooks/head-end/custom.html" at <partial "plausible_head.html" .>: error calling partial: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/divinerites/plausible-hugo@v1.17.2/layouts/partials/plausible_head.html:2:4": execute of template failed: template: partials/plausible_head.html:2:4: executing "partials/plausible_head.html" at <partial "plausible_check.html" .>: error calling partial: "/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/github.com/divinerites/plausible-hugo@v1.17.2/layouts/partials/plausible_check.html:2:7": execute of template failed: template: partials/plausible_check.html:2:7: executing "partials/plausible_check.html" at <isset site.Params.plausible "analytics">: error calling isset: isset unable to use key of type string as index
Built in 223 ms

Appreciate any assistance you can provide, but I suspect I'll have to troubleshoot this with Plausible instead.

firasm commented 2 years ago

Also, just to be clear, the code injection part works correctly because if I replace

{{ partial "plausible_head.html" . }} with <h1>Hello World</h1>>, the title is correctly embedded into the head of every page:

Screen Shot 2022-08-16 at 8 02 18 AM
divinerites commented 2 years ago

Please contact wowchemy help/support. I do think this has nothing to do with my module.

divinerites commented 2 years ago

And they already worked on something in wowchemy

See https://github.com/meson800/wowchemy-hugo-modules/commit/c98ecbe36068a7c423bb74059a90c81f6a1e330b