mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
Add support for Google Analytics v4
This commit is contained in:
@@ -1,6 +1,17 @@
|
||||
{{- $pc := .Site.Config.Privacy.GoogleAnalytics -}}
|
||||
{{- if not $pc.Disable -}}
|
||||
{{ with .Site.GoogleAnalytics }}
|
||||
{{- if not $pc.Disable }}{{ with .Site.GoogleAnalytics -}}
|
||||
{{ if hasPrefix . "G-"}}
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id={{ . }}"></script>
|
||||
<script>
|
||||
{{ template "__ga_js_set_doNotTrack" $ }}
|
||||
if (!doNotTrack) {
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
gtag('config', '{{ . }}', { 'anonymize_ip': {{- $pc.AnonymizeIP -}} });
|
||||
}
|
||||
</script>
|
||||
{{ else if hasPrefix . "UA-" }}
|
||||
<script type="application/javascript">
|
||||
{{ template "__ga_js_set_doNotTrack" $ }}
|
||||
if (!doNotTrack) {
|
||||
@@ -26,8 +37,9 @@ if (!doNotTrack) {
|
||||
ga('send', 'pageview');
|
||||
}
|
||||
</script>
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
{{- end }}{{ end -}}
|
||||
|
||||
{{- define "__ga_js_set_doNotTrack" -}}{{/* This is also used in the async version. */}}
|
||||
{{- $pc := .Site.Config.Privacy.GoogleAnalytics -}}
|
||||
{{- if not $pc.RespectDoNotTrack -}}
|
||||
|
Reference in New Issue
Block a user