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

hsluoyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/casbin-website.git

commit 7df28c061d1bb4b02a54b23b9aa878d7a876fc9a
Author: Yang Luo <[email protected]>
AuthorDate: Mon Oct 12 00:26:59 2026 +0800

    feat: add Matomo analytics
---
 docusaurus.config.js        | 22 ++++++++++++++++++++++
 src/clientModules/matomo.js | 17 +++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/docusaurus.config.js b/docusaurus.config.js
index 998f759f6..219986285 100644
--- a/docusaurus.config.js
+++ b/docusaurus.config.js
@@ -17,6 +17,28 @@ module.exports = {
     },
   },
   favicon: "img/favicon.png",
+  // ASF Matomo (analytics.apache.org), cookies disabled. Production builds 
only.
+  headTags: process.env.NODE_ENV === "production" ? [
+    {
+      tagName: "script",
+      attributes: {},
+      innerHTML: `
+        var _paq = window._paq = window._paq || [];
+        _paq.push(["setDoNotTrack", true]);
+        _paq.push(["disableCookies"]);
+        _paq.push(["trackPageView"]);
+        _paq.push(["enableLinkTracking"]);
+        (function() {
+          var u = "https://analytics.apache.org/";;
+          _paq.push(["setTrackerUrl", u + "matomo.php"]);
+          _paq.push(["setSiteId", "91"]);
+          var d = document, g = d.createElement("script"), s = 
d.getElementsByTagName("script")[0];
+          g.async = true; g.src = u + "matomo.js"; 
s.parentNode.insertBefore(g, s);
+        })();
+      `,
+    },
+  ] : [],
+  clientModules: [require.resolve("./src/clientModules/matomo.js")],
   organizationName: "apache", // Usually your GitHub org/user name.
   projectName: "casbin-website", // Usually your repo name.
   themeConfig: {
diff --git a/src/clientModules/matomo.js b/src/clientModules/matomo.js
new file mode 100644
index 000000000..d330166a6
--- /dev/null
+++ b/src/clientModules/matomo.js
@@ -0,0 +1,17 @@
+// Docusaurus is a single-page app: the tracking code in <head> records the 
first page, later navigations are recorded here.
+export function onRouteDidUpdate({location, previousLocation}) {
+  if (!previousLocation || location.pathname === previousLocation.pathname) {
+    return;
+  }
+  const paq = window._paq;
+  if (!paq) {
+    return;
+  }
+  const referrer = window.location.origin + previousLocation.pathname + 
previousLocation.search;
+  setTimeout(() => {
+    paq.push(["setReferrerUrl", referrer]);
+    paq.push(["setCustomUrl", window.location.href]);
+    paq.push(["setDocumentTitle", document.title]);
+    paq.push(["trackPageView"]);
+  }, 0);
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to