Skip to content

Commit

Permalink
fix: matomo (#2076)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonat75 authored Jan 29, 2024
1 parent 3bb1c05 commit 3ad606f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/app/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const RootLayout = ({ children }: PropsWithChildren) => {
<meta property="csp-nonce" content={nonce} />

<Suspense>
<Matomo env={config.env} nonce={nonce} />
<Matomo env={config.env} nonce={nonce} matomo={config.matomo} />
</Suspense>
</head>
<body>
Expand Down
10 changes: 5 additions & 5 deletions packages/app/src/components/utils/Matomo.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
"use client";

import { config } from "@common/config";
import { type config } from "@common/config";
import { init, push } from "@socialgouv/matomo-next";
import { usePathname, useSearchParams } from "next/navigation";
import { useEffect, useState } from "react";

import { useConsent } from "../../app/consentManagement";

export type MatomoProps = Pick<typeof config, "env"> & { nonce?: string };
export type MatomoProps = Pick<typeof config, "env"> & Pick<typeof config, "matomo"> & { nonce?: string };

/**
* Handle Matomo init and consent.
*
* Uses `useSearchParams()` internally, must be Suspense-d in server component.
*/
export const Matomo = ({ env, nonce }: MatomoProps) => {
export const Matomo = ({ env, nonce, matomo }: MatomoProps) => {
const pathname = usePathname();
const searchParams = useSearchParams();
const { finalityConsent } = useConsent();
Expand All @@ -29,7 +29,7 @@ export const Matomo = ({ env, nonce }: MatomoProps) => {

if (!inited) {
init({
...config.matomo,
...matomo,
nonce,
onInitialization: () => {
push(["optUserOut"]);
Expand All @@ -51,7 +51,7 @@ export const Matomo = ({ env, nonce }: MatomoProps) => {
push(["forgetCookieConsentGiven"]);
}
// eslint-disable-next-line react-hooks/exhaustive-deps -- don't listen on inited
}, [env, matomoConsent]);
}, [env, matomoConsent, matomo]);

/* The @socialgouv/matomo-next does not work with next 13 */
useEffect(() => {
Expand Down

0 comments on commit 3ad606f

Please sign in to comment.