Skip to content

Commit

Permalink
Set up Matomo via matomo-next
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Herrmann committed Aug 21, 2023
1 parent b09e0af commit 60dafff
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
API_BASE_URL=http://localhost:3000/api

NEXT_PUBLIC_MATOMO_URL=https://piwik.technologiestiftung-berlin.de
NEXT_PUBLIC_MATOMO_SITE_ID=1234
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"dependencies": {
"@emotion/react": "11.11.1",
"@emotion/styled": "11.11.0",
"@socialgouv/matomo-next": "1.6.1",
"lucide-react": "^0.263.1",
"next": "13.4.7",
"next-intl": "^2.17.5",
Expand Down
14 changes: 14 additions & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { init } from "@socialgouv/matomo-next";
import { NextIntlClientProvider } from "next-intl";
import type { AppProps } from "next/app";
import { useEffect, useRef } from "react";
import "react-tooltip/dist/react-tooltip.css";
import GlobalStyles from "../components/GlobalStyles";

const MATOMO_URL = process.env.NEXT_PUBLIC_MATOMO_URL as string;
const MATOMO_SITE_ID = process.env.NEXT_PUBLIC_MATOMO_SITE_ID as string;

type CustomPageProps = {
messages: IntlMessages;
};

export default function App({ Component, pageProps }: AppProps<CustomPageProps>) {
const matomoInitialized = useRef(false);
useEffect(() => {
if (MATOMO_URL && MATOMO_SITE_ID && matomoInitialized.current === false) {
init({ url: MATOMO_URL, siteId: MATOMO_SITE_ID });
}
return () => {
matomoInitialized.current = true;
};
}, []);
return (
<NextIntlClientProvider messages={pageProps.messages}>
<GlobalStyles />
Expand Down

0 comments on commit 60dafff

Please sign in to comment.