Revert the minimal analytics changes (#3265)

* Revert "theme: Move tracking to turbo:load"

This reverts commit c369e534d2.

* Revert "theme: Move tracking to turbo:render"

This reverts commit 88b451022d.

* Revert "Move to minimalanalytics for GA tracking"

This reverts commit 7040dc5eed.
This commit is contained in:
Bjørn Erik Pedersen
2025-11-05 10:58:54 +01:00
committed by GitHub
parent c369e534d2
commit 4dfbd647fa
10 changed files with 50 additions and 30 deletions
-2
View File
@@ -10,5 +10,3 @@ node_modules/
nohup.out
package-lock.json
trace.out
assets/jsconfig.json
-9
View File
@@ -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];
+10
View File
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": [
"*"
]
}
}
}
-5
View File
@@ -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
)
+2 -4
View File
@@ -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=
+4 -7
View File
@@ -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 worlds 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'
+27
View File
@@ -0,0 +1,27 @@
{{ with site.Config.Services.GoogleAnalytics.ID }}
<script
async
src="https://www.googletagmanager.com/gtag/js?id={{ . }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
{{ $site := site.BaseURL | replaceRE "^https?://(www\\.)?([^/]+).*" "$2" }}
gtag('config', '{{ . }}', {'anonymize_ip': true, 'dimension1': '{{ $site }}', 'dimension2': '{{ getenv "BRANCH" }}'});
/**
* Function that tracks a click on an outbound link in Analytics.
* Setting the transport method to 'beacon' lets the hit be sent
* using 'navigator.sendBeacon' in browser that support it.
*/
var trackOutboundLink = function(id, url) {
gtag('event', 'click', {
'event_category': 'outbound',
'event_label': id,
'transport_type': 'beacon'
});
}
</script>
{{ end }}
@@ -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 }}
+3
View File
@@ -36,3 +36,6 @@
{{ partial "schema.html" . }}
{{ partial "twitter_cards.html" . }}
{{ if hugo.IsProduction }}
{{ partial "helpers/gtag.html" . }}
{{ end }}
@@ -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 }}
<a
href="{{ $url }}"
title="{{ .title | default .name }}"
{{ if hugo.IsProduction }}
onclick="trackOutboundLink({{ printf "'%s', '%s'" $gtagID $url | safeJS }});"
{{ end }}
class="group inline-block w-full h-full shadow-md dark:shadow-gray-600"
{{ with .link_attr }}{{ . | safeHTMLAttr }}{{ end }}>
<div