From 4983790fcabd3af3503ac85947e7d5e417a64a24 Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Tue, 16 Apr 2024 17:06:40 +0200 Subject: [PATCH 1/4] Configure cookieless analytics with Matomo --- package-lock.json | 30 ++++++++++++++++++++++++++++++ package.json | 1 + src/theme/Root.tsx | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 src/theme/Root.tsx diff --git a/package-lock.json b/package-lock.json index 882f56f0..d46b1846 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "api-docs", "version": "0.0.0", "dependencies": { + "@datapunt/matomo-tracker-react": "^0.5.1", "@docusaurus/core": "^3.2.1", "@docusaurus/preset-classic": "^3.2.1", "@mdx-js/react": "^3.0.0", @@ -2142,6 +2143,22 @@ "node": ">=0.1.90" } }, + "node_modules/@datapunt/matomo-tracker-js": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/@datapunt/matomo-tracker-js/-/matomo-tracker-js-0.5.1.tgz", + "integrity": "sha512-9/MW9vt/BA5Db7tO6LqCeQKtuvBNjyq51faF3AzUmPMlYsJCnASIxcut3VqJKiribhUoey7aYbPIYuj9x4DLPA==" + }, + "node_modules/@datapunt/matomo-tracker-react": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/@datapunt/matomo-tracker-react/-/matomo-tracker-react-0.5.1.tgz", + "integrity": "sha512-lrNYM9hFL6XK0VAdtMb7MwZrLWhaAconx4c7gOGAMvoWuoVm+ZZIYFuKtfYdYMeBf0avxWtmKRwjZEg7T8jV2A==", + "dependencies": { + "@datapunt/matomo-tracker-js": "^0.5.1" + }, + "peerDependencies": { + "react": ">= 16.8.0" + } + }, "node_modules/@discoveryjs/json-ext": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz", @@ -17056,6 +17073,19 @@ "integrity": "sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==", "optional": true }, + "@datapunt/matomo-tracker-js": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/@datapunt/matomo-tracker-js/-/matomo-tracker-js-0.5.1.tgz", + "integrity": "sha512-9/MW9vt/BA5Db7tO6LqCeQKtuvBNjyq51faF3AzUmPMlYsJCnASIxcut3VqJKiribhUoey7aYbPIYuj9x4DLPA==" + }, + "@datapunt/matomo-tracker-react": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/@datapunt/matomo-tracker-react/-/matomo-tracker-react-0.5.1.tgz", + "integrity": "sha512-lrNYM9hFL6XK0VAdtMb7MwZrLWhaAconx4c7gOGAMvoWuoVm+ZZIYFuKtfYdYMeBf0avxWtmKRwjZEg7T8jV2A==", + "requires": { + "@datapunt/matomo-tracker-js": "^0.5.1" + } + }, "@discoveryjs/json-ext": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz", diff --git a/package.json b/package.json index 122301fb..05bf5301 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "format": "prettier --write docs i18n src" }, "dependencies": { + "@datapunt/matomo-tracker-react": "^0.5.1", "@docusaurus/core": "^3.2.1", "@docusaurus/preset-classic": "^3.2.1", "@mdx-js/react": "^3.0.0", diff --git a/src/theme/Root.tsx b/src/theme/Root.tsx new file mode 100644 index 00000000..67325158 --- /dev/null +++ b/src/theme/Root.tsx @@ -0,0 +1,34 @@ +import React, { PropsWithChildren, useEffect } from "react"; +import { createInstance, MatomoProvider, useMatomo } from "@datapunt/matomo-tracker-react"; +import { useLocation } from "@docusaurus/router"; + +function PageViewTracker({ children }: PropsWithChildren<{}>) { + const { trackPageView } = useMatomo(); + const location = useLocation(); + + useEffect(() => { + console.log("tracking pageview", location.pathname); + trackPageView({}); + }, [location]); + + return children; +} + +export default function Root({ children }: PropsWithChildren<{}>) { + const matomoInstance = createInstance({ + urlBase: "https://developer.mittwald.de/stats/", + siteId: 1, + configurations: { + disableCookies: true + // setSecureCookie: true, + } + }); + + return ( + + + {children} + + + ); +} \ No newline at end of file From 63b9b57d27e18153f58d5067303e9d5ca5d27fa1 Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Tue, 16 Apr 2024 17:44:25 +0200 Subject: [PATCH 2/4] Update src/theme/Root.tsx Signed-off-by: Martin Helmich --- src/theme/Root.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/theme/Root.tsx b/src/theme/Root.tsx index 67325158..05141d29 100644 --- a/src/theme/Root.tsx +++ b/src/theme/Root.tsx @@ -20,7 +20,7 @@ export default function Root({ children }: PropsWithChildren<{}>) { siteId: 1, configurations: { disableCookies: true - // setSecureCookie: true, + setSecureCookie: true, } }); From 8a33f5a1d9c86a80c2f238817166b9a77b6cc954 Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Tue, 16 Apr 2024 18:35:28 +0200 Subject: [PATCH 3/4] Update src/theme/Root.tsx Signed-off-by: Martin Helmich --- src/theme/Root.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/theme/Root.tsx b/src/theme/Root.tsx index 05141d29..095a5fa9 100644 --- a/src/theme/Root.tsx +++ b/src/theme/Root.tsx @@ -19,7 +19,7 @@ export default function Root({ children }: PropsWithChildren<{}>) { urlBase: "https://developer.mittwald.de/stats/", siteId: 1, configurations: { - disableCookies: true + disableCookies: true, setSecureCookie: true, } }); From afc4b57e4d0f1023a8c663db70a037f69f49e0d9 Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Tue, 16 Apr 2024 18:59:49 +0200 Subject: [PATCH 4/4] Update src/theme/Root.tsx Signed-off-by: Martin Helmich --- src/theme/Root.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/theme/Root.tsx b/src/theme/Root.tsx index 095a5fa9..1f8feb52 100644 --- a/src/theme/Root.tsx +++ b/src/theme/Root.tsx @@ -7,7 +7,6 @@ function PageViewTracker({ children }: PropsWithChildren<{}>) { const location = useLocation(); useEffect(() => { - console.log("tracking pageview", location.pathname); trackPageView({}); }, [location]);