From 5bade7136038c478b4552dea8db59693af7c2c8e Mon Sep 17 00:00:00 2001 From: Patrice Chalin Date: Thu, 16 May 2024 10:54:12 -0400 Subject: [PATCH] Cleanup of analytics templates --- layouts/_internal/google_analytics.html | 30 +++++++++++++ layouts/_internal/google_analytics_gtag.html | 42 ------------------- layouts/partials/head.html | 7 +--- .../en/docs/adding-content/feedback.md | 24 ----------- 4 files changed, 31 insertions(+), 72 deletions(-) create mode 100644 layouts/_internal/google_analytics.html delete mode 100644 layouts/_internal/google_analytics_gtag.html diff --git a/layouts/_internal/google_analytics.html b/layouts/_internal/google_analytics.html new file mode 100644 index 000000000..495e57b5e --- /dev/null +++ b/layouts/_internal/google_analytics.html @@ -0,0 +1,30 @@ +{{/* + + This is a copy of https://github.com/gohugoio/hugo/pull/12505, + which changes all `{{- ... }}` to `{{- ... }}. Drop this file if + and once it is merged. + +*/ -}} + +{{ if not site.Config.Privacy.GoogleAnalytics.Disable }} + {{- with site.Config.Services.GoogleAnalytics.ID }} + {{- if strings.HasPrefix (lower .) "ua-" }} + {{- warnf "Google Analytics 4 (GA4) replaced Google Universal Analytics (UA) effective 1 July 2023. See https://support.google.com/analytics/answer/11583528. Create a GA4 property and data stream, then replace the Google Analytics ID in your site configuration with the new value." }} + {{- else }} + + + {{- end }} + {{- end }} +{{- end -}} \ No newline at end of file diff --git a/layouts/_internal/google_analytics_gtag.html b/layouts/_internal/google_analytics_gtag.html deleted file mode 100644 index 2c9c7da90..000000000 --- a/layouts/_internal/google_analytics_gtag.html +++ /dev/null @@ -1,42 +0,0 @@ -{{/* - - This is a modified copy of - - https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/google_analytics.html, - - specifically this version: - - 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 `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.Config.Services.GoogleAnalytics.ID -}} - - -{{- end }}{{ end -}} - -{{- define "__ga_js_set_doNotTrack" -}}{{/* This is also used in the async version. */}} -{{- $pc := .Site.Config.Privacy.GoogleAnalytics -}} -{{- if not $pc.RespectDoNotTrack -}} -var doNotTrack = false; -{{- else -}} -var dnt = (navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack); -var doNotTrack = (dnt == "1" || dnt == "yes"); -{{- end -}} -{{- end -}} \ No newline at end of file diff --git a/layouts/partials/head.html b/layouts/partials/head.html index ec4525daf..e4a6012a9 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -46,12 +46,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.Config.Services.GoogleAnalytics.ID "G-")) -}} - {{ template "_internal/google_analytics_gtag.html" . -}} - {{ else -}} - {{ template "_internal/google_analytics.html" . -}} - {{ end -}} + {{ template "_internal/google_analytics.html" . -}} {{ end -}} {{ define "algolia/head" -}} diff --git a/userguide/content/en/docs/adding-content/feedback.md b/userguide/content/en/docs/adding-content/feedback.md index edde20dab..cadb23622 100644 --- a/userguide/content/en/docs/adding-content/feedback.md +++ b/userguide/content/en/docs/adding-content/feedback.md @@ -33,30 +33,6 @@ started** section of [Introducing Google Analytics 4 (GA4)][ga4-intro]. Enable Google Analytics by adding your project's analytics ID to the site configuration file. For details, see [Configure Google Analytics][]. -By default, Docsy uses the [gtag.js][] analytics library for both GA4 (which -_requires_ `gtag.js`) and Universal Analytics (UA) site tags. If you prefer using -the older `analytics.js` library for your UA site tag, then set -`params.disableGtagForUniversalAnalytics` to `true` in your project's [configuration file]. - -{{< tabpane >}} -{{< tab header="Configuration file:" disabled=true />}} -{{< tab header="hugo.toml" lang="toml" >}} -[params] -disableGtagForUniversalAnalytics = true -{{< /tab >}} -{{< tab header="hugo.yaml" lang="yaml" >}} -params: - disableGtagForUniversalAnalytics: true -{{< /tab >}} -{{< tab header="hugo.json" lang="json" >}} -{ - "params": { - "disableGtagForUniversalAnalytics": true - } -} -{{< /tab >}} -{{< /tabpane >}} - {{% alert title="Deprecation note and warning" color="warning" %}}