summaryrefslogtreecommitdiffstats
path: root/layouts/partials/head/analytics.html
blob: 74d045dc2c8c0c8c90d07f763e7efd40c45e34a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{{- if eq hugo.Environment "production" }}
    {{- if not site.Params.Privacy.GoogleTagManager.Disable }}{{/* First check GTM */}}
        {{- with site.Params.Services.GoogleTagManager }}
            {{- $gtmParams := dict "gtmCode" (.ID) -}}
            {{- $gtmParams = merge $gtmParams (dict "respectDoNotTrack" site.Params.Privacy.GoogleTagManager.RespectDoNotTrack | default true) }}

            {{- $gtmScript := slice -}}
            {{- $gtmScript = $gtmScript | append (resources.Get "js/gtm.js") -}}
            {{- $gtmScript = $gtmScript | resources.Concat "js/analytics.js" -}}
            {{- $gtmScript = $gtmScript | js.Build (dict "format" "iife" "target" "es2015" "minify" true "params" $gtmParams) -}}

            {{- if site.Params.assets.disable_fingerprinting }}
                <script src="{{ $gtmScript.RelPermalink }}"></script>
            {{- else -}}
                {{- $gtmScript = $gtmScript | fingerprint -}}
                <script src="{{ $gtmScript.RelPermalink }}" integrity="{{ $gtmScript.Data.Integrity }}" crossorigin="anonymous"></script>
            {{- end -}}
        {{- end -}}
    {{ else }}{{/* If GTM is disabled delegate the rest to Hugo */}}
        {{ template "_internal/google_analytics.html" . }}
    {{ end }}
{{ end }}