mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-11-18 07:22:06 +00:00
fix: disable Matomo if not URL and SITE ID exist
This commit is contained in:
@@ -1,23 +1,26 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
import { trackAppRouter } from "@socialgouv/matomo-next";
|
import { trackAppRouter } from "@socialgouv/matomo-next";
|
||||||
import { usePathname, useSearchParams } from "next/navigation";
|
import { usePathname, useSearchParams } from "next/navigation";
|
||||||
import { useEffect } from "react";
|
|
||||||
|
|
||||||
const MATOMO_URL = process.env.NEXT_PUBLIC_MATOMO_URL;
|
const MATOMO_URL = process.env.NEXT_PUBLIC_MATOMO_URL;
|
||||||
const MATOMO_SITE_ID = process.env.NEXT_PUBLIC_MATOMO_SITE_ID;
|
const MATOMO_SITE_ID = process.env.NEXT_PUBLIC_MATOMO_SITE_ID;
|
||||||
|
const isMatomoEnabled = Boolean(MATOMO_URL && MATOMO_SITE_ID);
|
||||||
|
|
||||||
export function MatomoAnalytics() {
|
export function MatomoAnalytics() {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!isMatomoEnabled) return;
|
||||||
|
|
||||||
trackAppRouter({
|
trackAppRouter({
|
||||||
url: MATOMO_URL || "",
|
url: MATOMO_URL as string,
|
||||||
siteId: MATOMO_SITE_ID || "",
|
siteId: MATOMO_SITE_ID as string,
|
||||||
pathname,
|
pathname,
|
||||||
searchParams, // Pass URLSearchParams object directly
|
searchParams,
|
||||||
// Optional: Enable additional features
|
|
||||||
enableHeatmapSessionRecording: false,
|
enableHeatmapSessionRecording: false,
|
||||||
enableHeartBeatTimer: true,
|
enableHeartBeatTimer: true,
|
||||||
cleanUrl: true,
|
cleanUrl: true,
|
||||||
@@ -27,4 +30,4 @@ export function MatomoAnalytics() {
|
|||||||
}, [pathname, searchParams]);
|
}, [pathname, searchParams]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user