You are viewing a plain text version of this content. The canonical link for it is here.
Posted to geb-notifications@groovy.apache.org by sd...@apache.org on 2025/02/12 09:20:14 UTC

(groovy-geb) 01/01: reple google analytics with matomo in old manuals

This is an automated email from the ASF dual-hosted git repository.

sdelamo pushed a commit to branch remove-analytics
in repository https://gitbox.apache.org/repos/asf/groovy-geb.git

commit 5be139160cf54ce6f8001b3be53a3853f5c4a788
Author: Sergio del Amo <se...@softamo.com>
AuthorDate: Wed Feb 12 10:20:04 2025 +0100

    reple google analytics with matomo in old manuals
---
 doc/site/site.gradle | 38 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/doc/site/site.gradle b/doc/site/site.gradle
index 071420eb..3852136f 100644
--- a/doc/site/site.gradle
+++ b/doc/site/site.gradle
@@ -70,6 +70,42 @@ tasks.generateIndex {
     inputs.files(file("templates/main.html"))
 }
 
+tasks.register("replaceAnalyticsWithMatomo") {
+    group = "website"
+    description = "Replace Google Analytics with Matomo in manuals"
+    dependsOn("generateResources")
+    doLast {
+        File baseDir = file("${project.projectDir}/src/main/resources/public/manual")
+        baseDir.eachFileRecurse(groovy.io.FileType.FILES) { file ->
+            if (file.name == 'index.html') {
+                String html = file.text
+                String ga = '''
+<script type="text/javascript">
+
+    var _gaq = _gaq || [];
+    _gaq.push(['_setAccount', 'UA-15031038-2']);
+    _gaq.push(['_trackPageview', location.pathname + location.hash]);
+
+    window.onhashchange = function() {
+        _gaq.push(['_trackPageview', location.pathname + location.hash]);
+    };
+
+    (function() {
+        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+    })();
+
+</script>
+'''
+                String matomo = new File("${project.rootDir}/doc/manual/src/docs/asciidoc/docinfo.html").text
+                file.text = html.replace(ga, matomo)
+                // Add your processing logic here
+            }
+        }
+    }
+}
+
 tasks.register("placeIndex", Copy) {
     group = "website"
     description = "move the generated src/main/resources/index.html to src/main/resources/public/index.html and deletes it from src/main/resources"
@@ -90,7 +126,7 @@ tasks.register("copyPublicResources", Copy) {
 
 tasks.register("generatePublic") {
     group = "website"
-    dependsOn("copyPublicResources", "generateResources", "placeIndex")
+    dependsOn("copyPublicResources", "generateResources", "placeIndex", "replaceAnalyticsWithMatomo")
 }
 processResources.dependsOn("generatePublic")
 test.dependsOn("generatePublic")