Built-in templates for Google Analytics are enabled on localhost, aka development server.
Disable GA templates as done in Disqus if localhost is detected.
hugo version)?$ hugo version v0.71.1
Yes
I'm more than happy to send a patch fixing this, as long as someone says it's ok to do so.
I think you can accomplish this with configuration settings. See https://gohugo.io/getting-started/configuration/#configuration-directory.
โโโ config
โย ย โโโ _default
โย ย โย ย โโโ config.toml
โย ย โโโ production
โย ย โโโ config.toml
config/_default/config.toml:
googleAnalytics = ""
config/production/config.toml:
googleAnalytics = "your-live-code-here"
I'm sure _someone_ is running hugo locally behind a proxy in a production environment. While we don't recommend that setup, this feature request would break that setup. I'd prefer to see you use the existing configuration options mentioned above by @jmooring.
That needs some documentation I think at the place of the analytics documentation. At least a little notice :)
Actually, it's easier than I originally proposed. Two methods:
Conditionally include the template in baseof.html or wherever:
{{ if not .Site.IsServer }}
{{ template "_internal/google_analytics.html" . }}
{{ end }}
The template will not be rendered if googleAnalytics is not present in config.toml. So...
โโโ config
โ โโโ _default
โ โ โโโ config.toml
โ โโโ production
โ โโโ config.toml
config/_default/config.toml:
# googleAnalytics = "your-live-code-here" (or eliminate the entry)
config/production/config.toml:
googleAnalytics = "your-live-code-here"
Thanks for getting in touch, but it feels like this is a question that would be better suited to the Hugo Discussion Forum. We prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug. You may also find the answers you search for in Hugo Documentation.
All comments are valid, but as I mentioned, Disqus does this in the Javascript side, so, why one and not others? :thinking:
Keeping behavior equal across multiple items is desired.
Most helpful comment
I think you can accomplish this with configuration settings. See https://gohugo.io/getting-started/configuration/#configuration-directory.
config/_default/config.toml:
config/production/config.toml: