Wowchemy-hugo-modules: Google Analytics seems not working

Created on 30 Sep 2019  路  7Comments  路  Source: wowchemy/wowchemy-hugo-modules

It seems that after the update Google Analytics stopped collecting information (without using Google Tag Manager). I've tried both approaches:

  1. Through defining googleAnalytics parameter in config.toml:
googleAnalytics = "xxx"
  1. Through defining google_analytics parameter in params.toml:
[marketing]
  google_analytics = "xxx"
  google_tag_manager = ""

Most helpful comment

I fixed by:

  • commenting
    #google_tag_manager = ""
  • building the site with this command:
    env HUGO_ENV="production" hugo

All 7 comments

It appears that you are on the development (master) version. Did you get the last update - b028457?

Yes, I am on the development (master) version. Updated the theme using update.sh. I have this commit also, still there is no reaction in Google Analytics. If I view the sources of the page, I even don't see the script of google analytics.

Analytics data is now only sent in production (i.e. when HUGO_ENV = "production"). If you wish to test locally with Hugo Server then the appropriate HUGO_ENV can be declared when serving. More details on setting the environment can be found in Hugo's docs.

HUGO_ENV = "production" is defined, I use netlify to publish, so this is not a local test. This is a test on the production.

I have the latest version working fine with google_analytics in multiple production deployments, one of which is the Academic Documentation site (which has a public repo).

If the analytics script is not present on your site then, this statement is returning false for you: https://github.com/gcushen/hugo-academic/blob/b028457922e1c596c3c1bf993e6a28a6b645b127/layouts/partials/marketing/google_analytics.html#L4 .

If the analytics script is present on your site, and there's still an issue, then GA's gtag.js has some troubleshooting steps that might help - for example, checking that you GA site Property Settings has a URL which matches your baseURL.

It seems that the issue was in the netlify configuration. The structure of my web site is different from exampleSite: the root of my project contains the sources of the webpage while academic folder is in themes directory connected as a git submodule. It seems that after the update it is required to set baseUrl using -b flag for Hugo. Previously, my configuration did not have this option. So, @gcushen thank you for pointing on potential issues. If someone has the same structure, my netlify config is the following:

[build]
  command = "hugo --gc --minify -b $URL"
  # base    = "./"
  publish = "public"

[build.environment]
  HUGO_THEME = "academic"
  HUGO_VERSION = "0.58.3"
  HUGO_ENABLEGITINFO = "false"

[context.production.environment]
  HUGO_ENV = "production"

[context.deploy-preview]
  command = "hugo --gc --minify --buildFuture -b $DEPLOY_PRIME_URL"

[context.branch-deploy]
  command = "hugo --gc --minify -b $DEPLOY_PRIME_URL"

[[headers]]
  for = "*.webmanifest"
  [headers.values]
    Content-Type = "application/manifest+json; charset=UTF-8"

[[headers]]
  for = "index.xml"
  [headers.values]
    Content-Type = "application/rss+xml"

I fixed by:

  • commenting
    #google_tag_manager = ""
  • building the site with this command:
    env HUGO_ENV="production" hugo
Was this page helpful?
0 / 5 - 0 ratings

Related issues

eduardohenriquearnold picture eduardohenriquearnold  路  4Comments

anirbanbasu picture anirbanbasu  路  3Comments

petzi53 picture petzi53  路  4Comments

chris-prener picture chris-prener  路  3Comments

gcushen picture gcushen  路  4Comments