forked from drowl87/hextra_mirror
chore: support services.googleAnalytics.ID
(#173)
* chore: support `services.googleAnalytics.ID` and deprecate `site.googleAnalytics` * chore: remove warning
This commit is contained in:
parent
de1286c7fc
commit
e3f6069968
@ -252,8 +252,10 @@ excludeSearch: true
|
|||||||
|
|
||||||
### Google Analytics
|
### Google Analytics
|
||||||
|
|
||||||
To enable Google Analytics, set the `googleAnalytics` parameter in the config file:
|
To enable [Google Analytics](https://marketingplatform.google.com/about/analytics/), set `services.googleAnalytics.ID` flag in `hugo.yaml`:
|
||||||
|
|
||||||
```yaml {filename="hugo.yaml"}
|
```yaml {filename="hugo.yaml"}
|
||||||
googleAnalytics: G-XXXXXXXXXX
|
services:
|
||||||
|
googleAnalytics:
|
||||||
|
ID: G-MEASUREMENT_ID
|
||||||
```
|
```
|
||||||
|
@ -7,7 +7,9 @@ enableGitInfo: true
|
|||||||
# enableEmoji: false
|
# enableEmoji: false
|
||||||
hasCJKLanguage: true
|
hasCJKLanguage: true
|
||||||
|
|
||||||
# googleAnalytics: G-XXXXXXXXXX
|
# services:
|
||||||
|
# googleAnalytics:
|
||||||
|
# ID: G-MEASUREMENT_ID
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
home: [HTML]
|
home: [HTML]
|
||||||
|
@ -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 -->
|
<!-- Global site tag (gtag.js) - Google Analytics -->
|
||||||
<script async src="https://www.googletagmanager.com/gtag/js?id={{ . }}"></script>
|
<script async src="https://www.googletagmanager.com/gtag/js?id={{ . }}"></script>
|
||||||
<script>
|
<script>
|
||||||
@ -10,4 +16,4 @@
|
|||||||
|
|
||||||
gtag("config", "{{ . }}");
|
gtag("config", "{{ . }}");
|
||||||
</script>
|
</script>
|
||||||
{{ end }}
|
{{ end -}}
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<!-- Google Analytics -->
|
<!-- Google Analytics -->
|
||||||
{{- if and .Site.GoogleAnalytics (eq hugo.Environment "production") }}
|
{{- if and (eq hugo.Environment "production") (or .Site.GoogleAnalytics .Site.Config.Services.GoogleAnalytics.ID) }}
|
||||||
<link rel="preconnect" href="https://www.googletagmanager.com" crossorigin />
|
<link rel="preconnect" href="https://www.googletagmanager.com" crossorigin />
|
||||||
{{ partial "google-analytics.html" . }}
|
{{ partial "google-analytics.html" . }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user