Google Analytics on Hugo Zen theme is not working

I added the google Analytic code into zen theme by adding parameter like below:

params:
  GoogleAnalytics: 3XXXXXXXXX

Now, tried to check on my Google Analytic account whether it is working properly or not. And I found under realtime reports of Google Analytic noting is showing.

If anybody implemented Google Analtics on Hugo Zen theme, can you share whether did you follow any other techniques or code to make it workable?

Another thing. anybody knows whether zen theme supports old google analytics or the new google analytics or both?

the universal analytic is like UA-123456789-1 but still its not showing the report. Do you know for zen them do i need any other configuration like adding some extra code beside adding the parameter in the config.yaml file?

Which theme?

frjo/hugo-theme-zen: A fast and clean Hugo base theme with css-grid and Hugo pipes support. (github.com)

rakuishi/hugo-zen: Hugo Zen is a minimal hugo theme. (github.com)

The former says it does “Analytics with Matamo (Piwik)”
The latter requires it to be set in the config as

googleanalytics = "UA-12345678-9"

Use your text editor, search the config and layouts for “google”, see if it is there and if so how it is loaded.

Which theme? => hugo-theme-zen theme. GitHub - frjo/hugo-theme-zen: A fast and clean Hugo base theme with css-grid and Hugo pipes support.

For that used the param value like this:

params:
   GoogleAnalytics: UA-123456789-1

But its not working. Just wondering any other location do i need to update the code?

If you are just implementing GA in your theme, give up with Universal Analytics and do GA4 instead. UA is set to end mid this year hence is no point to gather data through UA in 2023 anymore.

1 Like
params:
  superman: true

My website won’t fly.

Did you do this?
The answer for me is found by doing that, you find the following in the layouts/tracking.html partial

{{ if site.GoogleAnalytics -}}
{{ $script := resources.Get "js/tracking.js" | js.Build $opts | fingerprint -}}
<script src="{{ $script.RelPermalink }}"></script>
{{ template "_internal/google_analytics.html" . }}
{{ end -}} 

Make sure it is turned on, so this is true: {{ if site.GoogleAnalytics -}}
Then see what the internal template needs in terms of param setting:
Internal Templates | Hugo (gohugo.io)

This is not correct, GoogleAnalytics is a global Hugo setting and not a theme parameter. See Configure Hugo | Hugo.

based on the doc, i also tried:

params:
  googleAnalytics: G-1234567890

But no luck! Its not producing any data. Moreover, if i try to check the code by right clicking on the browser(chrome browser) and if I try to search the id for google analytics, its also missing there.

I am using hugo version

hugo v0.109.0+extended darwin/amd64 BuildDate=unknown

Not sure I need to update to the latest version of hugo.

Please read the reply from frjo again. Carefully.

hi, its a little bit confusing for me. still i am trying to tell, the approach i tried lastly to implement this:

as google analytic is the default hugo settings so if i can add it under parameter of config.toml/yaml/json file it should work. i am using yaml format and I have only one config.yaml file where I added all the settings for the hugo site

But still after building/deploying i dont see any changes. My site is very small and there is no such subfolder of configuration. just one config.yaml file.

so, not sure what steps do i need to do. may be i am new for hugo, thats why i am not understanding properly. if possible can you tell me what step i am missing ?

thanks

The key/value pair belongs in the root of your configuration file, not under the params key.

baseURL: 'https://example.org/'
languageCode: en-us
title: '@@TITLE@@'
googleAnalytics: something

just used that at root of the configuration file as

googleAnalytics: "G-1213121212"

still same issue. in the report noting is coming.

I found one link Add Minimal Analytics (Google Analytics v4) to Hugo - #18 by tut. if i apply its working but the global settings of analytics are not working at all if i follow that way.

The Zen theme with GA works fine for me. Here’s an example site I put up to verify:

https://github.com/jmooring/hugo-forum-topic-42571

I installed the theme, added the GA measurement ID, and published the site with GitHub pages:
https://jmooring.github.io/hugo-forum-topic-42571/

image

Hi @jmooring i tried now form the scratch. now i found its working.

Steps I did, I updated hugo to latest version and the theme folder. Finally tried and its working.

I have no idea how it resolved but it is working perfectly! :smiley:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.