diff options
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | exampleSite/config.toml | 2 | ||||
| -rw-r--r-- | 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 @@ <script src="{{ $search.RelPermalink }}"></script> {{- end -}} -{{- with site.GoogleAnalytics -}} - {{- $ga := resources.Get "js/ga.js" | minify -}} - {{- if not site.Params.assets.disable_fingerprinting -}} - {{- $ga = $ga | fingerprint -}} - <script src="{{ $ga.RelPermalink }}" integrity="{{ $ga.Data.Integrity }}"></script> - {{- else -}} - <script src="{{ $ga.RelPermalink }}"></script> +{{- 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 -}} + <script src="{{ $ga.RelPermalink }}" integrity="{{ $ga.Data.Integrity }}"></script> + {{- else -}} + <script src="{{ $ga.RelPermalink }}"></script> + {{- end -}} {{- end -}} {{- end -}} |
