From ec8f709bfb9b2a98285125df9fb3f3fe02e08a9e Mon Sep 17 00:00:00 2001 From: Nina Zakharenko Date: Sat, 13 Jul 2019 19:07:32 -0700 Subject: Don't use google analytics when running on built-in server --- README.md | 2 ++ layouts/partials/head.html | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 63657e9..7afbdac 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,8 @@ comments: To add Google Analytics, simply sign up to [Google Analytics](https://www.google.com/analytics/) to obtain your Google Tracking ID, and add this tracking ID to the `googleAnalytics` parameter in `config.toml`. +Note that the Google Analytics tracking code will only be inserted into the page when the site isn't served on Hugo's built-in server, to prevent tracking from local testing environments. + ### Commit SHA on the footer If the source of your site is in a Git repo, the SHA corresponding to the commit the site is built from can be shown on the footer. To do so, two environment variables have to be set (`GIT_COMMIT_SHA` and `GIT_COMMIT_SHA_SHORT`) and parameter `commit` has to be defined in the config file: diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 2c872b4..02c3928 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -108,4 +108,6 @@ {{- end -}} {{- partial "head_custom.html" . }} -{{ template "_internal/google_analytics_async.html" . }} +{{- if not .Site.IsServer -}} + {{ template "_internal/google_analytics_async.html" . }} +{{- end -}} \ No newline at end of file -- cgit v1.2.3