From 4dfbd647fad7f019692e10d7edd6db75b17997fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 5 Nov 2025 10:58:54 +0100 Subject: [PATCH] Revert the minimal analytics changes (#3265) * Revert "theme: Move tracking to turbo:load" This reverts commit c369e534d2b31ec2a2edfcd85d9c5738734976ac. * Revert "theme: Move tracking to turbo:render" This reverts commit 88b451022d3f0c0509ce049896eb1c608836f707. * Revert "Move to minimalanalytics for GA tracking" This reverts commit 7040dc5eed88b498cee1d00b565a3366868152ee. --- .gitignore | 2 -- assets/js/main.js | 9 ------- assets/jsconfig.json | 10 ++++++++ go.mod | 5 ---- go.sum | 6 ++--- hugo.toml | 11 +++----- layouts/_partials/helpers/gtag.html | 27 ++++++++++++++++++++ layouts/_partials/layouts/head/head-js.html | 3 --- layouts/_partials/layouts/head/head.html | 3 +++ layouts/_partials/layouts/home/sponsors.html | 4 +++ 10 files changed, 50 insertions(+), 30 deletions(-) create mode 100644 assets/jsconfig.json create mode 100644 layouts/_partials/helpers/gtag.html diff --git a/.gitignore b/.gitignore index 8ab22c224..5208c5c3a 100644 --- a/.gitignore +++ b/.gitignore @@ -10,5 +10,3 @@ node_modules/ nohup.out package-lock.json trace.out -assets/jsconfig.json - diff --git a/assets/js/main.js b/assets/js/main.js index 8c8ea6247..c12be19fa 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -48,7 +48,6 @@ var debug = 0 ? console.log.bind(console, '[index]') : function () {}; { let containerScrollTops = {}; - let turboLoaded = false; // To preserve scroll position in scrolling elements on navigation add data-turbo-preserve-scroll-container="somename" to the scrolling container. addEventListener('turbo:click', () => { @@ -57,14 +56,6 @@ var debug = 0 ? console.log.bind(console, '[index]') : function () {}; }); }); - addEventListener('turbo:load', () => { - if (turboLoaded) { - // Minimal Analytics does not support SPA out of the box, so we need to manually track page views on Turbo navigation. - window.track('page_view'); - } - turboLoaded = true; - }); - addEventListener('turbo:render', () => { document.querySelectorAll('[data-turbo-preserve-scroll-container]').forEach((ele) => { const containerScrollTop = containerScrollTops[ele.dataset.turboPreserveScrollContainer]; diff --git a/assets/jsconfig.json b/assets/jsconfig.json new file mode 100644 index 000000000..377218ccb --- /dev/null +++ b/assets/jsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "*": [ + "*" + ] + } + } +} \ No newline at end of file diff --git a/go.mod b/go.mod index fa2ea19f8..4b9e0a369 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,3 @@ module github.com/gohugoio/hugoDocs go 1.22.0 - -require ( - github.com/bep/hugo-mod-minimalanalytics v0.3.0 // indirect - github.com/jahilldev/minimal-analytics v0.0.0-20220825110705-ee335ed38334 // indirect -) diff --git a/go.sum b/go.sum index f753f06a0..af9b5febf 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,2 @@ -github.com/bep/hugo-mod-minimalanalytics v0.3.0 h1:fctZN3nFOFrapX1dhPBszyCUKOGjEpBJmp1jBf3YkJE= -github.com/bep/hugo-mod-minimalanalytics v0.3.0/go.mod h1:3QVkKqSikBRTI+hS3dm/zCAfGukd+opSfAwfjkyxqIw= -github.com/jahilldev/minimal-analytics v0.0.0-20220825110705-ee335ed38334 h1:r8/jLqGw5uwSmgJ4eSGbxa1XBaSIkp3MY99GhY61NeE= -github.com/jahilldev/minimal-analytics v0.0.0-20220825110705-ee335ed38334/go.mod h1:w4l2fXZWGxmcVQfLLBdTqUT6HpSIA9FhmUtVArJFLYw= +github.com/gohugoio/gohugoioTheme v0.0.0-20250116152525-2d382cae7743 h1:gjoqq8+RnGwpuU/LQVYGGR/LsDplrfUjOabWwoROYsM= +github.com/gohugoio/gohugoioTheme v0.0.0-20250116152525-2d382cae7743/go.mod h1:GOYeAPQJ/ok8z7oz1cjfcSlsFpXrmx6VkzQ5RpnyhZM= diff --git a/hugo.toml b/hugo.toml index 3cd51c4e8..5e0b697ef 100644 --- a/hugo.toml +++ b/hugo.toml @@ -98,8 +98,6 @@ ignoreLogs = ['warning-frontmatter-params-overrides'] disableWatch = true source = "hugo_stats.json" target = "assets/notwatching/hugo_stats.json" - [[module.imports]] - path = "github.com/bep/hugo-mod-minimalanalytics" [outputFormats] [outputFormats.redir] @@ -122,11 +120,6 @@ ignoreLogs = ['warning-frontmatter-params-overrides'] [params] description = "The world’s fastest framework for building websites" ghrepo = "https://github.com/gohugoio/hugoDocs/" - - [params.minimalanalytics] - # GA4 tracking ID - tracking_id = "G-MBZGKNMDWC" - [params.render_hooks.link] errorLevel = 'warning' # ignore (default), warning, or error (fails the build) [params.social.mastodon] @@ -155,6 +148,10 @@ ignoreLogs = ['warning-frontmatter-params-overrides'] [[server.headers]] for = "/**.{css,js}" +[services] + [services.googleAnalytics] + ID = 'G-MBZGKNMDWC' + [taxonomies] category = 'categories' diff --git a/layouts/_partials/helpers/gtag.html b/layouts/_partials/helpers/gtag.html new file mode 100644 index 000000000..59bf36ba2 --- /dev/null +++ b/layouts/_partials/helpers/gtag.html @@ -0,0 +1,27 @@ +{{ with site.Config.Services.GoogleAnalytics.ID }} + + +{{ end }} diff --git a/layouts/_partials/layouts/head/head-js.html b/layouts/_partials/layouts/head/head-js.html index e24c10ce8..d83efcd0f 100644 --- a/layouts/_partials/layouts/head/head-js.html +++ b/layouts/_partials/layouts/head/head-js.html @@ -1,6 +1,3 @@ -{{ if or hugo.IsProduction (not hugo.IsDevelopment) }} - {{ partial "minimalanalytics.html" . }} -{{ end }} {{ $githubInfo := partialCached "helpers/funcs/get-github-info.html" . "-" }} {{ $opts := dict "minify" true }} {{ with resources.Get "js/head-early.js" | js.Build $opts }} diff --git a/layouts/_partials/layouts/head/head.html b/layouts/_partials/layouts/head/head.html index 7014e2c29..265d7ccd0 100644 --- a/layouts/_partials/layouts/head/head.html +++ b/layouts/_partials/layouts/head/head.html @@ -36,3 +36,6 @@ {{ partial "schema.html" . }} {{ partial "twitter_cards.html" . }} +{{ if hugo.IsProduction }} + {{ partial "helpers/gtag.html" . }} +{{ end }} diff --git a/layouts/_partials/layouts/home/sponsors.html b/layouts/_partials/layouts/home/sponsors.html index 5832e9770..1f391e1ec 100644 --- a/layouts/_partials/layouts/home/sponsors.html +++ b/layouts/_partials/layouts/home/sponsors.html @@ -15,9 +15,13 @@ {{ $url = printf "%s?%s%s" .link $query_params (querify "utm_source" (.utm_source | default $utmSource ) "utm_medium" (.utm_medium | default "banner") "utm_campaign" (.utm_campaign | default "hugosponsor") "utm_content" (.utm_content | default "gohugoio")) | safeURL }} {{ end }} {{ $logo := resources.Get .logo }} + {{ $gtagID := printf "Sponsor %s %s" .name $gtag | title }}