Peculiar issue with `partial "seo/google_analytics.html"`

I have not updated Hugo in a while. Still using the older version from a few months ago I think. I hadn’t changed any source since last time. Today I go to update/build my site, and I get this error:

$  hugo serve
Watching for changes in /home/stoned/websites/websites/psychedelicsdaily.com-hugo/{archetypes,assets,content,data,package.json,postcss.config.js,static,themes}
Watching for config changes in /home/stoned/websites/websites/psychedelicsdaily.com-hugo/config.toml
Start building sites … 
hugo v0.125.7-b1d808bc373f53ad37c8966bb02a6aea095db5f8+extended linux/amd64 BuildDate=2024-05-08T14:46:24Z VendorInfo=snap:0.125.7

ERROR render of "page" failed: "/home/stoned/websites/websites/psychedelicsdaily.com-hugo/themes/hugo-universal-theme/layouts/_default/single.html:92:11": execute of template failed: template: _default/single.html:92:11: executing "_default/single.html" at <partial "scripts.html" .>: error calling partial: "/home/stoned/websites/websites/psychedelicsdaily.com-hugo/themes/hugo-universal-theme/layouts/partials/scripts.html:68:4": execute of template failed: template: partials/scripts.html:68:4: executing "partials/scripts.html" at <partial "seo/google_analytics.html" .>: error calling partial: execute of template failed: html/template:partials/seo/google_analytics.html:7:12: no such template "__ga_js_set_doNotTrack"
ERROR render of "term" failed: "/home/stoned/websites/websites/psychedelicsdaily.com-hugo/themes/hugo-universal-theme/layouts/_default/list.html:132:7": execute of template failed: template: _default/list.html:132:7: executing "_default/list.html" at <partial "scripts.html" .>: error calling partial: "/home/stoned/websites/websites/psychedelicsdaily.com-hugo/themes/hugo-universal-theme/layouts/partials/scripts.html:68:4": execute of template failed: template: partials/scripts.html:68:4: executing "partials/scripts.html" at <partial "seo/google_analytics.html" .>: error calling partial: execute of template failed: html/template:partials/seo/google_analytics.html:7:12: no such template "__ga_js_set_doNotTrack"
Built in 807 ms
Error: error building site: render: failed to render pages: render of "404" failed: "/home/stoned/websites/websites/psychedelicsdaily.com-hugo/themes/hugo-universal-theme/layouts/404.html:46:7": execute of template failed: template: 404.html:46:7: executing "404.html" at <partial "scripts.html" .>: error calling partial: "/home/stoned/websites/websites/psychedelicsdaily.com-hugo/themes/hugo-universal-theme/layouts/partials/scripts.html:68:4": execute of template failed: template: partials/scripts.html:68:4: executing "partials/scripts.html" at <partial "seo/google_analytics.html" .>: error calling partial: execute of template failed: html/template:partials/seo/google_analytics.html:7:12: no such template "__ga_js_set_doNotTrack"

If I comment out the template, it builds the site, otherwise these errors.

Here is seo/google_analytics.html


{{- $pc := .Site.Config.Privacy.GoogleAnalytics -}}
{{- if not $pc.Disable -}}
{{ with .Site.GoogleAnalytics }}

<script>
{{ template "__ga_js_set_doNotTrack" $ }}
if (!doNotTrack) {
	window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
	{{- if $pc.UseSessionStorage }}
	if (window.sessionStorage) {
		var GA_SESSION_STORAGE_KEY = 'ga:clientId';
		ga('create', '{{ . }}', {
	    'storage': 'none',
	    'clientId': sessionStorage.getItem(GA_SESSION_STORAGE_KEY)
	   });
	   ga(function(tracker) {
	    sessionStorage.setItem(GA_SESSION_STORAGE_KEY, tracker.get('clientId'));
	   });
   }
	{{ else }}
	ga('create', '{{ . }}', 'auto');
	{{ end -}}
	{{ if $pc.AnonymizeIP }}ga('set', 'anonymizeIp', true);{{ end }}
	ga('send', 'pageview');
}
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>

{{ end }}
{{- end -}}

Here is the erroneous bit:

{{ template "__ga_js_set_doNotTrack" $ }}

What’s going on here? I should mention that this same config has worked for years, until today. I haven’t changed any source since my last build. I’m not sure what happened here.

I think the google analytics code has changed and is no longer the same as the template from Hugo that I’ve been using.

{{ with .Site.GoogleAnalytics }}

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{.}}"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', {{.}});
</script>

{{ end }}

And config toml has

googleAnalytics = "G-your code here"

Now it builds the site again. Please correct me if I’m wrong or I’m using the template wrong of if there is an internal template I should be using?

There is.

https://gohugo.io/templates/embedded/#google-analytics

Thanks. I’ll check that out.