Activate Google Analytics on environment other than production

My build command looks like this

hugo --environment testing --minify

and I have

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

in the head section of my html and

googleAnalytics = "UA-xxxxxxxx-x"

in my testing/config.toml but Google Analytics doesn’t show up in the source code of the webpage.

I read that Google Analytics only works on the production environment. How can I activate it for other environments like testing?

After changing the order in my config.toml like mentioned here Google Analytics works now perfectly in every environment. What a strange “bug”.

Hi Troy. I’m glad you were able to figure this out. The TOML specification, in the section about tables, states:

The top-level table, also called the root table, starts at the beginning of the document and ends just before the first table header (or EOF). Unlike other tables, it is nameless and cannot be relocated.

That means that this:

foo = "bar"

[table]
wibble = "wobble"

is not the same as this:

[table]
wibble = "wobble"

foo = "bar"

The last example can also be written:

[table]
  wibble = "wobble"
  foo = "bar"

because indentation and empty lines are irrelevant.

So, not a bug, but something to get used to with TOML. You can use YAML or JSON if you would prefer.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.