Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Analytics v4 requires different internal Template than currently used #339

Closed
vladimirdoroch opened this issue Mar 29, 2022 · 4 comments · Fixed by #341
Closed

Google Analytics v4 requires different internal Template than currently used #339

vladimirdoroch opened this issue Mar 29, 2022 · 4 comments · Fixed by #341
Assignees
Labels
bug Something isn't working

Comments

@vladimirdoroch
Copy link
Contributor

Describe the bug
GA client script does not send proper analytics metrics to Google.
This happens if one uses the anatole template and sets a Google Analytics v4 tracking Id in the config file.

image

As shown in the picture, a client side script is run but does not send any metrics via Post ("Kein Inhalt für diese Anfrage" = "No content for request").

To Reproduce

  1. Go to config.toml
  2. Set googleAnalytics = 'G-MEASUREMENT_ID'
  3. Start hugo server hugo server -D
  4. Start a Webbrowser of choice and browse to lokal instance
  5. Check POST messages to google-analytics.com via Webdev Tools of your Browser

Expected behavior
According to Hugo Docs setting a GA v4 ID is sufficient to configure the internal template properly.

The client side GA script should transmit some metrics to Google via POST messages.
image

In the example above:

en=page_view&ep.anonymize_ip=false
en=page_view&_et=1&ep.anonymize_ip=false
en=user_engagement&_et=4818&ep.anonymize_ip=false

Desktop (please complete the following information):

  • OS: macOS 12.2.1
  • Browser: Safari, Firefox (doesn't matter)
  • Version of the Theme: 1.8.0
  • Version of Hugo: 0.95.0

Additional context
My current work around is a custom partial for footer.html which uses _internal/google_analytics.html template instead of _internal/google_analytics_async.html as specified in Hugo Docs.

@vladimirdoroch vladimirdoroch added the bug Something isn't working label Mar 29, 2022
@lxndrblz
Copy link
Owner

@vladimirdoroch If I read the docs correctly, we would need to distinguish between a GAv4 and the v3. In case of the former we should load google_analytics.html and not _internal/google_analytics_async.html. Right now, I am not sure how this distinction could be made programmatically.

@vladimirdoroch
Copy link
Contributor Author

Maybe one can load the appropriate template based on the prefix of the tracking Id.
As I understand v3 (UA-XXXXXXX-X) and v4 (G-XXXXXXXX) tracking Ids can by identified that way.

This could be catched by something like {{ if hasPrefix . "G-"}}. What do you think?

@lxndrblz
Copy link
Owner

@vladimirdoroch That seems like a smart solution. Feel free to send a PR and I will go ahead and merge it for you.

@vladimirdoroch
Copy link
Contributor Author

Created pull request #341

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants