add Matomo analytics wihtout cookies

This commit is contained in:
2025-11-06 13:18:29 +01:00
committed by Owen Rees
parent c27fffd1b2
commit 151d9fcb3d
6 changed files with 46 additions and 7 deletions
+2
View File
@@ -1 +1,3 @@
NEXT_PUBLIC_URL=http://localhost:3000 NEXT_PUBLIC_URL=http://localhost:3000
NEXT_PUBLIC_MATOMO_URL=
NEXT_PUBLIC_MATOMO_SITE_ID=
+2
View File
@@ -1 +1,3 @@
NEXT_PUBLIC_URL=https://$NEXT_PUBLIC_VERCEL_URL NEXT_PUBLIC_URL=https://$NEXT_PUBLIC_VERCEL_URL
NEXT_PUBLIC_MATOMO_URL=https://analytics.owenrees.eu
NEXT_PUBLIC_MATOMO_SITE_ID=2
+1
View File
@@ -19,6 +19,7 @@
"@hookform/resolvers": "^3.9.0", "@hookform/resolvers": "^3.9.0",
"@infra-blocks/zod-utils": "^0.4.2", "@infra-blocks/zod-utils": "^0.4.2",
"@next/bundle-analyzer": "^14.0.4", "@next/bundle-analyzer": "^14.0.4",
"@socialgouv/matomo-next": "^1.10.0",
"@tanstack/react-query": "^5.29.0", "@tanstack/react-query": "^5.29.0",
"@trivago/prettier-plugin-sort-imports": "^4.2.0", "@trivago/prettier-plugin-sort-imports": "^4.2.0",
"@turf/boolean-point-in-polygon": "^7.0.0-alpha.114", "@turf/boolean-point-in-polygon": "^7.0.0-alpha.114",
+6 -7
View File
@@ -1,16 +1,16 @@
import { ReactNode } from "react"; import { ReactNode, Suspense } from "react";
import { NextIntlClientProvider } from "next-intl"; import { NextIntlClientProvider } from "next-intl";
import { getTranslations } from "next-intl/server"; import { getTranslations } from "next-intl/server";
import { Inter, Julius_Sans_One } from "next/font/google"; import { Inter, Julius_Sans_One } from "next/font/google";
import { notFound } from "next/navigation"; import { notFound } from "next/navigation";
import Script from "next/script";
import { LocaleChecker } from "@/components/LocaleChecker"; import { LocaleChecker } from "@/components/LocaleChecker";
import "@/css/globals.css"; import "@/css/globals.css";
import Providers from "@/providers"; import Providers from "@/providers";
import Footer from "./(main)/components/Footer"; import Footer from "./(main)/components/Footer";
import { MatomoAnalytics } from "@/components/MatomoAnalytics";
const inter = Inter({ subsets: ["latin"], variable: "--font-inter" }); const inter = Inter({ subsets: ["latin"], variable: "--font-inter" });
const title = Julius_Sans_One({ const title = Julius_Sans_One({
@@ -67,6 +67,7 @@ export default async function RootLayout({
<meta name="mobile-web-app-capable" content="yes" /> <meta name="mobile-web-app-capable" content="yes" />
<meta name="theme-color" content="#00A1F0" /> <meta name="theme-color" content="#00A1F0" />
<link rel="manifest" href="/manifest.webmanifest" /> <link rel="manifest" href="/manifest.webmanifest" />
<title>Échecs France</title>
</head> </head>
<body> <body>
<Providers> <Providers>
@@ -76,14 +77,12 @@ export default async function RootLayout({
{children} {children}
</div> </div>
</LocaleChecker> </LocaleChecker>
<Footer /> <Footer />
</NextIntlClientProvider> </NextIntlClientProvider>
{/*<Script*/} <Suspense fallback={null}>
{/* defer*/} <MatomoAnalytics />
{/* src="https://app.tinyanalytics.io/pixel/HyoumUokLr9exPgX"*/} </Suspense>
{/*/>*/}
</Providers> </Providers>
</body> </body>
</html> </html>
+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;
}
+5
View File
@@ -1785,6 +1785,11 @@
resolved "https://registry.yarnpkg.com/@rushstack/eslint-patch/-/eslint-patch-1.10.4.tgz#427d5549943a9c6fce808e39ea64dbe60d4047f1" resolved "https://registry.yarnpkg.com/@rushstack/eslint-patch/-/eslint-patch-1.10.4.tgz#427d5549943a9c6fce808e39ea64dbe60d4047f1"
integrity sha512-WJgX9nzTqknM393q1QJDJmoW28kUfEnybeTfVNcNAPnIx210RXm2DiXiHzfNPJNIUUb1tJnz/l4QGtJ30PgWmA== integrity sha512-WJgX9nzTqknM393q1QJDJmoW28kUfEnybeTfVNcNAPnIx210RXm2DiXiHzfNPJNIUUb1tJnz/l4QGtJ30PgWmA==
"@socialgouv/matomo-next@^1.10.0":
version "1.10.0"
resolved "https://registry.yarnpkg.com/@socialgouv/matomo-next/-/matomo-next-1.10.0.tgz#f3015865f767faa944eee927f8215c7d4ba283a7"
integrity sha512-Cp4EMnpzPO2JAinW56QrT6t+AJnM7pxUS3RUmfBWs9SIxHsqxivdmb+wSS8bUd/lkUXtLgBVw9dGOaK0EMwSEg==
"@surma/rollup-plugin-off-main-thread@^2.2.3": "@surma/rollup-plugin-off-main-thread@^2.2.3":
version "2.2.3" version "2.2.3"
resolved "https://registry.yarnpkg.com/@surma/rollup-plugin-off-main-thread/-/rollup-plugin-off-main-thread-2.2.3.tgz#ee34985952ca21558ab0d952f00298ad2190c053" resolved "https://registry.yarnpkg.com/@surma/rollup-plugin-off-main-thread/-/rollup-plugin-off-main-thread-2.2.3.tgz#ee34985952ca21558ab0d952f00298ad2190c053"