add Matomo analytics wihtout cookies

This commit is contained in:
2025-11-06 13:26:04 +01:00
committed by owenrees
parent c27fffd1b2
commit 151d9fcb3d
6 changed files with 46 additions and 7 deletions
+30
View File
@@ -0,0 +1,30 @@
"use client";
import { trackAppRouter } from "@socialgouv/matomo-next";
import { usePathname, useSearchParams } from "next/navigation";
import { useEffect } from "react";
const MATOMO_URL = process.env.NEXT_PUBLIC_MATOMO_URL;
const MATOMO_SITE_ID = process.env.NEXT_PUBLIC_MATOMO_SITE_ID;
export function MatomoAnalytics() {
const pathname = usePathname();
const searchParams = useSearchParams();
useEffect(() => {
trackAppRouter({
url: MATOMO_URL || "",
siteId: MATOMO_SITE_ID || "",
pathname,
searchParams, // Pass URLSearchParams object directly
// Optional: Enable additional features
enableHeatmapSessionRecording: false,
enableHeartBeatTimer: true,
cleanUrl: true,
disableCookies: true,
debug: process.env.NODE_ENV === "development",
});
}, [pathname, searchParams]);
return null;
}