How to Exclude Google Analytics When Running Under Hugo Local Server

OK, I was able to find it. Was searching for googleanalytics rather than google_analytics.

I changed this reference

{{ template "_internal/google_analytics.html" . }}

to this:

{{ if not .Site.BuildDrafts }}
  {{ template "_internal/google_analytics.html" . }}
{{ end }}

Given that I have no need to customize the actual google analytics code call itself - does this seem like an effective way to prevent google anayltics from being triggered during site previews with hugo internal webserver on my local machine?

1 Like