From 638903353764fbcfc44b19f1d444d3b8060bcaa2 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Wed, 6 Jul 2022 00:17:05 +0200 Subject: Load ga.js only on production mode --- CHANGELOG.md | 1 + exampleSite/config.toml | 2 ++ layouts/partials/scripts.html | 16 +++++++++------- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68725cd..6dc5c11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Rename template to render JSON Feed from `list.json.json` to `list.jsonfeed.json` +- Load `ga.js` only on production mode ## [v0.4.0](https://github.com/sergeyklay/gohugo-theme-ed/compare/v0.3.0...v0.4.0) diff --git a/exampleSite/config.toml b/exampleSite/config.toml index e456f66..d5c17c9 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -28,6 +28,8 @@ refLinksErrorLevel = 'WARNING' disableKinds = ['RSS'] # Google Analytics Tracking ID. +# Set `HUGO_ENV` environment variable or `site.Params.env` configuration +# parameter to "production" to use Google Analytics. googleAnalytics = '' [minify] diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html index d01bd8b..ace6e45 100644 --- a/layouts/partials/scripts.html +++ b/layouts/partials/scripts.html @@ -35,12 +35,14 @@ {{- end -}} -{{- with site.GoogleAnalytics -}} - {{- $ga := resources.Get "js/ga.js" | minify -}} - {{- if not site.Params.assets.disable_fingerprinting -}} - {{- $ga = $ga | fingerprint -}} - - {{- else -}} - +{{- if or (eq (getenv "HUGO_ENV") "production") (eq site.Params.env "production") }} + {{- with site.GoogleAnalytics -}} + {{- $ga := resources.Get "js/ga.js" | minify -}} + {{- if not site.Params.assets.disable_fingerprinting -}} + {{- $ga = $ga | fingerprint -}} + + {{- else -}} + + {{- end -}} {{- end -}} {{- end -}} -- cgit v1.2.3