summaryrefslogtreecommitdiffstats
path: root/layouts/partials/seo/ga.html
blob: 1a3566ef2e3caa00c50519379f73938155974d6f (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" "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 -}}