summaryrefslogtreecommitdiffstats
path: root/tpl/tplimpl/embedded/templates/google_analytics.html
blob: b8930d4bd277b70f9eeca76cd63df1fe281a82db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{{ if not site.Config.Privacy.GoogleAnalytics.Disable }}
  {{ with site.Config.Services.GoogleAnalytics.ID }}
    {{ if strings.HasPrefix (lower .) "ua-" }}
      {{ warnf "Google Analytics 4 (GA4) replaced Google Universal Analytics (UA) effective 1 July 2023. See https://support.google.com/analytics/answer/11583528. Create a GA4 property and data stream, then replace the Google Analytics ID in your site configuration with the new value." }}
    {{ else }}
      <script async src="https://www.googletagmanager.com/gtag/js?id={{ . }}"></script>
      <script>
        var doNotTrack = false;
        if ({{ site.Config.Privacy.GoogleAnalytics.RespectDoNotTrack }}) {
          var dnt = (navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack);
          var doNotTrack = (dnt == "1" || dnt == "yes");
        }
        if (!doNotTrack) {
          window.dataLayer = window.dataLayer || [];
          function gtag(){dataLayer.push(arguments);}
          gtag('js', new Date());
          gtag('config', '{{ . }}');
        }
      </script>
    {{ end }}
  {{ end }}
{{ end }}