chore: support services.googleAnalytics.ID (#173)

* chore: support `services.googleAnalytics.ID`

and deprecate `site.googleAnalytics`

* chore: remove warning
This commit is contained in:
Xin
2023-10-30 19:48:48 -04:00
committed by GitHub
parent de1286c7fc
commit e3f6069968
4 changed files with 16 additions and 6 deletions

View File

@ -1,4 +1,10 @@
{{ with .Site.GoogleAnalytics }}
{{/* site.GoogleAnalytics is deprecated in Hugo v0.120.0 */}}
{{/* it will be removed in a future version */}}
{{- $gtagID := "" -}}
{{- with site.GoogleAnalytics -}}{{ $gtagID = . }}{{- end -}}
{{- with site.Config.Services.GoogleAnalytics.ID -}}{{ $gtagID = . }}{{- end -}}
{{- with $gtagID }}
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ . }}"></script>
<script>
@ -10,4 +16,4 @@
gtag("config", "{{ . }}");
</script>
{{ end }}
{{ end -}}