summaryrefslogtreecommitdiff
path: root/themes/hugo-whisper-theme/layouts/partials/google-analytics.html
blob: 63c84abd3303c48189344b4a77c3719ac5ceb4ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{{- if .Site.IsServer -}}
  <!-- Dont add Google analytics to localhost -->
{{ else }}
  {{ $gid := (getenv "HUGO_GOOGLE_ANALYTICS_ID") }}
  {{ if $gid }}
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id={{- $gid -}}"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', '{{- $gid -}}');
    </script>
  {{ else }}
    {{ if .Site.Params.google_analytics_id }}
      <!-- Global site tag (gtag.js) - Google Analytics -->
      <script async src="https://www.googletagmanager.com/gtag/js?id={{- .Site.Params.google_analytics_id -}}"></script>
      <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', '{{- .Site.Params.google_analytics_id -}}');
      </script>
    {{ end }}
  {{ end}}
{{ end }}