chalin
July 12, 2022, 9:37pm
1
I don’t see a section on services
under Configure Hugo | Hugo and yet it seems that adding the following to my project’s Docsy-based config.toml
[services.googleAnalytics]
id = "UA-00000000-0"
has the same effect as adding a top-level googleAnalytics
param like this:
googleAnalytics = "UA-00000000-0"
That is, in either case, the ID’s value is accessible via .Site.GoogleAnalytics
.
So my questions are:
Are services.googleAnalytics.id
and googleAnalytics
config aliases?
Where are services
config details documented?
Which other params can I define under services.googleAnalytics
?
Maybe services.googleAnalytics
is historical and has been superseded by a top-level param? It seems to show up in some tests: Search · services.googleAnalytics · GitHub
Thanks!
For context, I stumbled on this behavior while investigating the following issue:
opened 01:14AM - 09 Mar 22 UTC
user guide
There are two documentation sources on getting Google Analytics working in Hugo/… Docsy
- The [Hugo google-analytics documenation](https://gohugo.io/templates/internal/#google-analytics)
- The [Docsy google-analytics documentation](https://www.docsy.dev/docs/adding-content/feedback/)
Its unclear how these two techniques interact. They seem to use different `config.toml` variables and I found that using both at the same time created problems. There is also the possible added confusion between the concepts of general page hit tracking vs. the Docsy [params.ui.feedback] feature - can I have one or the other or both? Finally the references to the now outdated "UA-00000000-0" `tracking id` caused me some confusion as I could not generate one, as Google Analytics does not allocate these anymore (unless you burrow down into advanced settings somewhere) - instead a ‘G-xxxxxxxxxx’ style `measurement id` is now allocated by default, and its not clear if such a measurement id can be used instead in the config. For these reasons, the Docsy documentation referred to by #92 I think needs clarification on some or all of these questions.
## Repro
To get Google Analytic page hits working, the [Hugo doco](https://gohugo.io/templates/internal/#google-analytics) says to create and set a `googleAnalytics` variable in `config.toml` e.g.
googleAnalytics = 'G-MEASUREMENT_ID'
This failed to work for me - it turns out it was because of the following default Docsy config in `config.toml`
```toml
[services]
[services.googleAnalytics]
# Comment out the next line to disable GA tracking. Also disables the feature described in [params.ui.feedback].
id = "UA-00000000-0"
```
Leaving the ‘id’ uncommented (as is the default) seems to prevent Hugo’s official `googleAnalytics` variable from working and thus no hits will be recorded by Google Analytics. Or rather, the HTML that gets generated is old style `UA-xxxxxxxx` script referring to "UA-00000000-0". Of course "UA-00000000-0" needs to be replaced with a real UA-xxxxxx number, which may seem obvious, but since Google does not allocate these anymore (unless you burrow down into advanced settings somewhere) then a new user might decide to leave the line unchanged, thinking "UA-00000000-0" has a special meaning or something.
What ended up working for me was setting `googleAnalytics` and commenting out `id`
```toml
googleAnalytics = 'G-xxxxxxxxxxx'
# id = "UA-00000000-0"
```
## My later discoveries
It seems that using `[services.googleAnalytics] id=` overrides the plain `googleAnalytics` variable, leading me to think they are somehow two ways of setting the same thing.
It turns out you don't need to set `googleAnalytics` variable (despite what the Hugo analytics documentation says) you can simply set `[services.googleAnalytics] id=` to either an old style `UA-xxxxxxxx` tracking code or a newer `G-xxxxxxxxxxx` measurement id.
## Documentation Suggestion
It might be helpful if the default `config.toml` relating to Google Analytics was updated to contain something like
```toml
[services]
[services.googleAnalytics]
# Comment out the 'id' line to disable GA tracking. Also disables the feature described in [params.ui.feedback].
# There is no need to set another config variable called 'googleAnalytics'
# Set id to either an old style `UA-xxxxxxxx` tracking code or a newer `G-xxxxxxxxxxx` measurement id
# Note tracking codes are deprecated, though can still be generate it under google analytics advanced options
id = "G-xxxxxxxxx"
```
with assocated changes to the [Docsy google-analytics documentation](https://www.docsy.dev/docs/adding-content/feedback/)
https://github.com/gohugoio/hugo/blob/master/config/services/servicesConfig.go#L83-L87
If it can’t find services.googleAnalytics.id
it falls back to googleAnalytics
(in the root) to provide backwards compatibility for a change that was made 4 years ago.
The only documentation reference that I could find to the services
configuration key is:
https://gohugo.io/about/hugo-and-gdpr/
1 Like
chalin
July 13, 2022, 3:22pm
3
Thanks @jmooring . Just to be clear: which parameter should be considered the new canonical one?
services.googleAnalytics.id
chalin
July 13, 2022, 3:52pm
5
Oh! So, in your opinion, should the docs be updated to say, for example, that the top-level googleAnalytics
param is:
Deprecated in favor of services.googleAnalytics.id
(while adding a section about the new services
parameters)?
Or at least mention that it is a shorthand?
Warning to not set both (otherwise strange behavior can result )?
I’d be glad to open an issue to that effect if you think it would be helpful.
1 Like
Yes, please create an issue in the docs repository. We should fully document the services key, and note the preferred way to configure the Google Analytics ID, the Disqus Shortname, and the RSS limit.
I’m not sure I would use the term deprecated , because programmatically the root settings have not been deprecated—that’s a separate issue that would affect a lot of sites and themes.
I also wouldn’t describe the root settings as shorthand —the values are stored separately.
2 Likes
chalin
July 14, 2022, 2:27pm
7
Done. I’ve created two issues because I think that it will be better to address them separately:
1 Like
system
Closed
July 16, 2022, 2:28pm
8
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.