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

Address GA.ID param deprecation warning #1879

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions layouts/_internal/google_analytics_gtag.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@

specifically this version:

https://github.com/gohugoio/hugo/blob/f7e00c039ff3cea5f991b05c1e325666004cf129/tpl/tplimpl/embedded/templates/google_analytics.html
https://github.com/gohugoio/hugo/blob/8d32ca223def4031aa26f98e8efc1a8b4e7b7546/tpl/tplimpl/embedded/templates/google_analytics.html

The only differences between this copy and the original are that we've dropped:

- The `{{ if hasPrefix . "G-"}}` condition
- The `{{ else }}` block
- The `{{ else ... }}` block
- The `anonymize_ip` argument to the `gtag()` call, since it is superfluous.
For details, see https://github.com/gohugoio/hugo/issues/10093.

*/}}

{{- $pc := .Site.Config.Privacy.GoogleAnalytics -}}
{{- if not $pc.Disable }}{{ with .Site.GoogleAnalytics -}}
{{- if not $pc.Disable }}{{ with .Site.Config.Services.GoogleAnalytics.ID -}}
<script async src="https://www.googletagmanager.com/gtag/js?id={{ . }}"></script>
<script>
{{ template "__ga_js_set_doNotTrack" $ }}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
{{/* To comply with GDPR, cookie consent scripts places in head-end must execute before Google Analytics is enabled */ -}}
{{ if hugo.IsProduction -}}
{{ $enableGtagForUniversalAnalytics := not .Site.Params.disableGtagForUniversalAnalytics -}}
{{ if (or $enableGtagForUniversalAnalytics (hasPrefix .Site.GoogleAnalytics "G-")) -}}
{{ if (or $enableGtagForUniversalAnalytics (hasPrefix .Site.Config.Services.GoogleAnalytics.ID "G-")) -}}
{{ template "_internal/google_analytics_gtag.html" . -}}
{{ else -}}
{{ template "_internal/google_analytics_async.html" . -}}
Expand Down
14 changes: 9 additions & 5 deletions userguide/content/en/docs/adding-content/feedback.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,21 @@ params:
{{< /tab >}}
{{< /tabpane >}}

{{% alert title="Warning" color="warning" %}}
{{% alert title="Deprecation note and warning" color="warning" %}}
<!-- Remove this warning once the Hugo docs have been updated to include it. -->

You can configure your project's analytics ID by setting either the top-level
`googleAnalytics` config parameter or `services.googleAnalytics.id`. **Do not
define both,** otherwise this can result in [unexpected behavior][]. For
details, see [Is services.googleAnalytics.id an alias for
While you can configure your project's analytics ID by setting either the
top-level `googleAnalytics` config parameter or `services.googleAnalytics.id`,
**`googleAnalytics` was [deprecated in Hugo 0.120.0][v0.120.0]** and
will be removed in a future release.

**Do not define both parameters,** otherwise this can result in [unexpected
behavior][]. For details, see [Is services.googleAnalytics.id an alias for
googleAnalytics][alias-discussion].

[alias-discussion]: https://discourse.gohugo.io/t/config-is-services-googleanalytics-id-an-alias-for-googleanalytics/39469
[unexpected behavior]: https://github.com/google/docsy/issues/921
[v0.120.0]: https://github.com/gohugoio/hugo/releases/tag/v0.120.0

{{% /alert %}}

Expand Down
4 changes: 0 additions & 4 deletions userguide/hugo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ menu:
post: <sup><i class="ps-1 fa-solid fa-up-right-from-square fa-xs"
aria-hidden="true"></i></sup>

services:
googleAnalytics:
# id: G-XXXXXXXXX # Waiting on https://github.com/google/docsy/issues/1097

languages:
en:
languageName: English
Expand Down