Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zerostaticthemes/hugo-serif-theme.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'layouts/partials/google-analytics.html')
-rw-r--r--layouts/partials/google-analytics.html27
1 files changed, 5 insertions, 22 deletions
diff --git a/layouts/partials/google-analytics.html b/layouts/partials/google-analytics.html
index 296d4af..8a58a62 100644
--- a/layouts/partials/google-analytics.html
+++ b/layouts/partials/google-analytics.html
@@ -1,10 +1,7 @@
-{{- if .Site.IsServer -}}
-<!-- Dont add Google analytics to localhost -->
-{{ else }}
-{{ $gid := (getenv "HUGO_GOOGLE_ANALYTICS_ID") }}
-{{ if $gid }}
+{{- if and (not .Site.IsServer) hugo.IsProduction -}}
+{{ with getenv "HUGO_GOOGLE_ANALYTICS_ID" | default .Site.Params.google_analytics_id }}
<!-- Global site tag (gtag.js) - Google Analytics -->
-<script async src="https://www.googletagmanager.com/gtag/js?id={{- $gid -}}"></script>
+<script async src="https://www.googletagmanager.com/gtag/js?id={{- . -}}"></script>
<script>
window.dataLayer = window.dataLayer || [];
@@ -12,21 +9,7 @@
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 -}}');
+ gtag('config', '{{ . }}');
</script>
{{ end }}
-{{ end}}
-{{ end }} \ No newline at end of file
+{{ end }}