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

hubcio pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iggy-website.git


The following commit(s) were added to refs/heads/main by this push:
     new a334ca1f2 chore(site): restore Matomo analytics after the Fumadocs 
migration (#70)
a334ca1f2 is described below

commit a334ca1f2b9c8c195385d0f3bd8b653089b93279
Author: Justin Mclean <[email protected]>
AuthorDate: Tue Sep 1 16:51:10 2026 +1000

    chore(site): restore Matomo analytics after the Fumadocs migration (#70)
---
 src/app/layout.tsx        | 18 ++++++++++++
 src/components/matomo.tsx | 72 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+)

diff --git a/src/app/layout.tsx b/src/app/layout.tsx
index 234332470..f0c4be748 100644
--- a/src/app/layout.tsx
+++ b/src/app/layout.tsx
@@ -19,6 +19,8 @@
 
 import { RootProvider } from "fumadocs-ui/provider/next";
 import type { Metadata } from "next";
+import Script from "next/script";
+import { Matomo } from "@/components/matomo";
 import "./global.css";
 
 export const metadata: Metadata = {
@@ -41,6 +43,22 @@ export default function Layout({ children }: { children: 
React.ReactNode }) {
         >
           {children}
         </RootProvider>
+        {/* Snippet supplied by the Apache Privacy Team */}
+        <Script id="matomo" strategy="afterInteractive">
+          {`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', '80']);
+  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);
+})();`}
+        </Script>
+        <Matomo />
       </body>
     </html>
   );
diff --git a/src/components/matomo.tsx b/src/components/matomo.tsx
new file mode 100644
index 000000000..4db8c62ef
--- /dev/null
+++ b/src/components/matomo.tsx
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+"use client";
+
+import { usePathname, useSearchParams } from "next/navigation";
+import { Suspense, useEffect, useRef } from "react";
+
+declare global {
+  interface Window {
+    _paq?: unknown[][];
+  }
+}
+
+/**
+ * Records a page view on client-side navigation.
+ *
+ * The tracking snippet in the root layout fires one trackPageView on the
+ * initial load. This site is a Next.js app, so every subsequent move between
+ * pages is client-side routing and produces no further page view, which would
+ * leave Matomo reporting entry pages only. This records the rest.
+ *
+ * The first render is skipped: the snippet has already counted it.
+ */
+function MatomoRouteTracker() {
+  const pathname = usePathname();
+  const searchParams = useSearchParams();
+  const initialLoad = useRef(true);
+
+  useEffect(() => {
+    if (initialLoad.current) {
+      initialLoad.current = false;
+      return;
+    }
+
+    const query = searchParams.toString();
+    const url = window.location.origin + pathname + (query ? `?${query}` : "");
+
+    window._paq = window._paq || [];
+    window._paq.push(["setReferrerUrl", document.referrer]);
+    window._paq.push(["setCustomUrl", url]);
+    window._paq.push(["setDocumentTitle", document.title]);
+    window._paq.push(["trackPageView"]);
+    window._paq.push(["enableLinkTracking"]);
+  }, [pathname, searchParams]);
+
+  return null;
+}
+
+export function Matomo() {
+  return (
+    <Suspense fallback={null}>
+      <MatomoRouteTracker />
+    </Suspense>
+  );
+}

Reply via email to