Closed vladimirdoroch closed 2 years ago
@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.
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?
@vladimirdoroch That seems like a smart solution. Feel free to send a PR and I will go ahead and merge it for you.
Created pull request #341
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.
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
config.toml
googleAnalytics = 'G-MEASUREMENT_ID'
hugo server -D
POST
messages togoogle-analytics.com
via Webdev Tools of your BrowserExpected 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.
In the example above:
Desktop (please complete the following information):
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.