Skip to content

Commit

Permalink
chore: add matomo script
Browse files Browse the repository at this point in the history
  • Loading branch information
gary-van-woerkens committed Feb 2, 2024
1 parent a4bd83d commit 9995f37
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .kontinuous/env/dev/templates/carnets.configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ apiVersion: v1
metadata:
name: app
data:
NODE_ENV: "production"
NODE_ENV: "review"
2 changes: 1 addition & 1 deletion .kontinuous/env/preprod/templates/carnets.configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ apiVersion: v1
metadata:
name: app
data:
NODE_ENV: "production"
NODE_ENV: "preprod"
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"dependencies": {
"@codegouvfr/react-dsfr": "0.78.6",
"@socialgouv/matomo-next": "1.8.0",
"chart.js": "4.4.1",
"date-fns": "2.30.0",
"github-markdown-css": "5.5.0",
Expand Down
13 changes: 4 additions & 9 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getHtmlAttributes } from "@codegouvfr/react-dsfr/next-appdir/getHtmlAtt
import { StartDsfr } from "./start-dsfr";
import Header from "@/components/header";
import Footer from "@/components/footer";
import Matomo from "@/components/matomo";
import { defaultColorScheme } from "./default-color-scheme";
import authOptions from "@/app/api/auth/[...nextauth]/options";

Expand All @@ -24,18 +25,12 @@ export default async function Layout({ children }: { children: JSX.Element }) {
<DsfrHead
Link={Link}
preloadFonts={[
//"Marianne-Light",
//"Marianne-Light_Italic",
"Marianne-Regular",
//"Marianne-Regular_Italic",
"Marianne-Medium",
//"Marianne-Medium_Italic",
"Marianne-Bold",
//"Marianne-Bold_Italic",
//"Spectral-Regular",
//"Spectral-ExtraBold"
"Marianne-Medium",
"Marianne-Regular",
]}
/>
<Matomo />
</head>
<body>
<DsfrProvider lang={lang}>
Expand Down
34 changes: 34 additions & 0 deletions src/components/matomo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"use client";

import Script from "next/script";
import { NODE_ENV } from "@/utils/env";

export default function Matomo() {
return (
<>
{NODE_ENV === "production" ? (
<Script
id="matomo"
onReady={() => {
// @ts-ignore
var _paq = (window._paq = window._paq || []);
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
(function () {
var u = "https://matomo.fabrique.social.gouv.fr/";
_paq.push(["setTrackerUrl", u + "matomo.php"]);
_paq.push(["setSiteId", "24"]);
var d = document,
g = d.createElement("script"),
s = d.getElementsByTagName("script")[0];
g.async = true;
g.src = u + "matomo.js";
s.parentNode?.insertBefore(g, s);
})();
}}
/>
) : null}
</>
);
}
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,15 @@ __metadata:
languageName: node
linkType: hard

"@socialgouv/matomo-next@npm:1.8.0":
version: 1.8.0
resolution: "@socialgouv/matomo-next@npm:1.8.0"
peerDependencies:
next: ">= 9.5.5"
checksum: 0e0d9da2bfa155584fc8f10a034dc46e78af9affd22f31f6d6d0249578540b2faf87ac22df244c3d225b53da14f865bfec961271bfe569138392e5bd8471e60c
languageName: node
linkType: hard

"@swc/helpers@npm:0.5.2":
version: 0.5.2
resolution: "@swc/helpers@npm:0.5.2"
Expand Down Expand Up @@ -2560,6 +2569,7 @@ __metadata:
resolution: "carnets@workspace:."
dependencies:
"@codegouvfr/react-dsfr": "npm:0.78.6"
"@socialgouv/matomo-next": "npm:1.8.0"
"@testing-library/react": "npm:14.1.2"
"@types/jsonwebtoken": "npm:9.0.5"
"@types/node": "npm:20.10.4"
Expand Down

0 comments on commit 9995f37

Please sign in to comment.