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

urfree pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pulsar-site.git


The following commit(s) were added to refs/heads/main by this push:
     new 9bdfbd2c1a6 add matomo agent (#278)
9bdfbd2c1a6 is described below

commit 9bdfbd2c1a606d32c85c99b7d68230669e4f272d
Author: tison <[email protected]>
AuthorDate: Wed Nov 9 17:22:32 2022 +0800

    add matomo agent (#278)
---
 site2/website-next/docusaurus.config.js      |  2 ++
 site2/website-next/matomoClientModule.js     | 16 ++++++++++++++++
 site2/website-next/static/js/matomo-agent.js | 13 +++++++++++++
 3 files changed, 31 insertions(+)

diff --git a/site2/website-next/docusaurus.config.js 
b/site2/website-next/docusaurus.config.js
index 2f67001d16c..26c5f55b8a4 100644
--- a/site2/website-next/docusaurus.config.js
+++ b/site2/website-next/docusaurus.config.js
@@ -450,5 +450,7 @@ module.exports = {
       src: "/js/sine-waves.min.js",
       async: true,
     },
+    "/js/matomo-agent.js",
   ],
+  clientModules: [require.resolve('./matomoClientModule.js')],
 };
diff --git a/site2/website-next/matomoClientModule.js 
b/site2/website-next/matomoClientModule.js
new file mode 100644
index 00000000000..853acb838bc
--- /dev/null
+++ b/site2/website-next/matomoClientModule.js
@@ -0,0 +1,16 @@
+import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
+
+export function onRouteDidUpdate({location, previousLocation}) {
+    if (ExecutionEnvironment.canUseDOM) {
+        if (location.pathname != previousLocation?.pathname) {
+          setTimeout(() => {
+            if (previousLocation) {
+              _paq.push(['setReferrerUrl', previousLocation.pathname])
+            }
+            _paq.push(['setCustomUrl', location.pathname])
+            _paq.push(['setDocumentTitle', document.title])
+            _paq.push(['trackPageView'])
+          })
+        }
+      }
+}
diff --git a/site2/website-next/static/js/matomo-agent.js 
b/site2/website-next/static/js/matomo-agent.js
new file mode 100644
index 00000000000..61341c56841
--- /dev/null
+++ b/site2/website-next/static/js/matomo-agent.js
@@ -0,0 +1,13 @@
+var _paq = window._paq = window._paq || [];
+/* tracker methods like "setCustomDimension" should be called before 
"trackPageView" */
+/* We explicitly disable cookie tracking to avoid privacy issues */
+_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', '32']);
+  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);
+})();

Reply via email to