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

Cleanup of Google analytics templates #2006

Merged
merged 1 commit into from
May 16, 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
30 changes: 30 additions & 0 deletions layouts/_internal/google_analytics.html
Original file line number Diff line number Diff line change
@@ -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 }}
<script async src="https://www.googletagmanager.com/gtag/js?id={{- . }}"></script>
<script>
var doNotTrack = false;
if ({{ site.Config.Privacy.GoogleAnalytics.RespectDoNotTrack }}) {
var dnt = (navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack);
var doNotTrack = (dnt == "1" || dnt == "yes");
}
if (!doNotTrack) {
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ . }}');
}
</script>
{{- end }}
{{- end }}
{{- end -}}
42 changes: 0 additions & 42 deletions layouts/_internal/google_analytics_gtag.html

This file was deleted.

7 changes: 1 addition & 6 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -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" -}}
Expand Down
24 changes: 0 additions & 24 deletions userguide/content/en/docs/adding-content/feedback.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" %}}
<!-- Remove this warning once the Hugo docs have been updated to include it. -->

Expand Down