Hugo-coder: disable google Analytics for local render

Created on 20 Jul 2020  路  4Comments  路  Source: luizdepra/hugo-coder

I had google analytics enabled for my site and I have the following line in Single.html.

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

I have now updated it to
{{ if not (in (.Site.BaseURL | string) "localhost") }}
{{ template "_internal/google_analytics_async.html" . }}
{{ end }}

so that it does not load GA for localhost. Is this good enough? In F12 developer options, I still see GA loading on the page.

All 4 comments

Hi @rchaganti, you should use this instead {{ if .Site.IsServer }}.

You meant like this?

        {{ if not .Site.IsServer }}
          {{ template "_internal/google_analytics_async.html" . }}
        {{ end }}

I have this in both layouts/blog/single.html and layouts/index.html. I still see the GA related elements in the generated HTML.
ga

I have the following line in Single.html.

I didn't saw that, you have to update the baseof.html file, not this one. The GA line is already written(line 116), you just have to surround it with the condition.

Perfect! Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

swarnalee picture swarnalee  路  4Comments

Mike-E-angelo picture Mike-E-angelo  路  3Comments

mauricioabreu picture mauricioabreu  路  5Comments

paskal picture paskal  路  6Comments

M-Brody picture M-Brody  路  6Comments