summaryrefslogtreecommitdiffstats
path: root/layouts/partials/seo/ga.html
blob: a9703b3607c3afa664b8c1b5473fd6bc2e1d1b90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{{- if (or (eq (getenv "HUGO_ENV") "production") (eq site.Params.env "production")) -}}
    {{- with site.GoogleAnalytics -}}
        {{- $gaParams := dict "analyticsCode" (site.GoogleAnalytics | default "") "anonymizeIp" (site.Params.anonymizeIp | default true) -}}

        {{- $gaScript := slice -}}
        {{- $gaScript = $gaScript | append (resources.Get "js/ga.js") -}}
        {{- $gaScript = $gaScript | resources.Concat "js/analytics-bundle.js" -}}

        {{- $gaScript = $gaScript | js.Build (dict "format" "iife" "minify" true "params" $gaParams) -}}

        {{- if site.Params.assets.disable_fingerprinting }}
            <script src="{{ $gaScript.RelPermalink }}"></script>
        {{- else -}}
            {{- $gaScript = $gaScript | fingerprint }}
            <script src="{{ $gaScript.RelPermalink }}" integrity="{{ $gaScript.Data.Integrity }}"></script>
        {{- end -}}
    {{- end -}}
{{- end -}}