Hi techies, I just got into Hugo, I directly referenced the Hugo blox template, but when I edited it locally I got the following error: ERROR deprecated: .Site.GoogleAnalytics was deprecated in Hugo v0.120.0 and will be removed in Hugo 0.134.0. Use .Site.Config.Services.GoogleAnalytics.ID instead.
I would like to know how to fix it.
Use your editor to search for “GoogleAnalytics” (no space) in your layout files. Those are the files in the folder layouts
. Once found, replace any occurrence of .Site.GoogleAnalytics
with .Site.Config.Services.GoogleAnalytics.ID
.
Then search within config
for GoogleAnalytics
and take note of your ID. Then add a new section (it’s hard to say where without knowing your config file, get back here if it doesn’t work, try adding it at the end) to your configuration:
[services.googleAnalytics]
id = 'GA-YOURID'
see Config | Hugo
You can probably remove the existing deprecated configuration if it’s there.
Then rebuild your site and see if it worked. If not, feel free to get back here with more explicit examples of the code where GoogleAnalytics
is used.
Thanks for the reply, but I didn’t search for the property named .Site.GoogleAnalytics. How should this be handled?
Check the template where you find GoogleAnalytics
and post here. It seems the theme developer uses the value of marketing.analytics
instead and you won’t need to delete anything.
For me this sounds like the theme is not compatible with your used hugo version.
-
Check your hugo version and the one the theme states. Use that one if yours is newer.
-
Maybe your module is not the theme is not up to date.
This for me means:
-
wait for the new hugo release where the mentioned issue is merged. Then update your theme.
-
use 132- for now
I wouldn’t hazzle with adjusting the theme templates unless you have an urgent need for 133+ features