1
+ {{/*
2
+
3
+ This is a modified copy of
4
+
5
+ https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/google_analytics.html,
6
+
7
+ specifically this version:
8
+
9
+ https://github.com/gohugoio/hugo/blob/f7e00c039ff3cea5f991b05c1e325666004cf129/tpl/tplimpl/embedded/templates/google_analytics.html
10
+
11
+ The only differences between this copy and the original are that we've dropped:
12
+
13
+ - The `{{ if hasPrefix . "G-"}}` condition
14
+ - The `{{ else }}` block
15
+ - The `anonymize_ip` argument to the `gtag()` call, since it is superfluous.
16
+ For details, see https://github.com/gohugoio/hugo/issues/10093.
17
+
18
+ */}}
19
+
20
+ {{- $pc := .Site.Config.Privacy.GoogleAnalytics -}}
21
+ {{- if not $pc.Disable }}{{ with .Site.GoogleAnalytics -}}
22
+ < script async src ="https://www.googletagmanager.com/gtag/js?id={{ . }} "> </ script >
23
+ < script >
24
+ { { template "__ga_js_set_doNotTrack" $ } }
25
+ if ( ! doNotTrack ) {
26
+ window . dataLayer = window . dataLayer || [ ] ;
27
+ function gtag ( ) { dataLayer . push ( arguments ) ; }
28
+ gtag ( 'js' , new Date ( ) ) ;
29
+ gtag ( 'config' , '{{ . }}' ) ;
30
+ }
31
+ </ script >
32
+ {{- end }}{{ end -}}
33
+
34
+ {{- define "__ga_js_set_doNotTrack" -}}{{/* This is also used in the async version. */}}
35
+ {{- $pc := .Site.Config.Privacy.GoogleAnalytics -}}
36
+ {{- if not $pc.RespectDoNotTrack -}}
37
+ var doNotTrack = false;
38
+ {{- else -}}
39
+ var dnt = (navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack);
40
+ var doNotTrack = (dnt == "1" || dnt == "yes");
41
+ {{- end -}}
42
+ {{- end -}}
0 commit comments