Skip to content

Commit 80beb6b

Browse files
authored
Merge branch 'dev' into remove-axios
2 parents d0c6ec1 + a3a41a2 commit 80beb6b

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
# GOOGLE_API_KEY=
1717
# GOOGLE_CALENDAR_ID=
1818

19+
# Matomo environment (URL and site ID required for analytics)
20+
NEXT_PUBLIC_MATOMO_URL=
21+
NEXT_PUBLIC_MATOMO_SITE_ID=
22+
1923
# Used to avoid loading Matomo in our preview deploys
2024
IS_PREVIEW_DEPLOY=false
2125

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@docsearch/react": "^3.5.2",
2222
"@emotion/react": "^11.11.1",
2323
"@emotion/styled": "^11.11.0",
24+
"@socialgouv/matomo-next": "^1.8.0",
2425
"clipboard": "^2.0.11",
2526
"embla-carousel-react": "^7.0.0",
2627
"ethereum-blockies-base64": "^1.0.2",

src/lib/utils/matomo.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { push } from "@socialgouv/matomo-next"
2+
13
export const MATOMO_LS_KEY = "ethereum-org.matomo-opt-out"
24

35
export interface MatomoEventOptions {
@@ -13,15 +15,12 @@ export const trackCustomEvent = ({
1315
eventName,
1416
eventValue,
1517
}: MatomoEventOptions): void => {
16-
if (process.env.NODE_ENV !== "production" && !window.dev) return
18+
if (process.env.NODE_ENV !== "production") return
1719
const optedOutValue = localStorage.getItem(MATOMO_LS_KEY) || "false"
1820
const isOptedOut = JSON.parse(optedOutValue)
19-
if (!window._paq || isOptedOut) return
20-
21-
const { _paq, dev } = window
21+
if (isOptedOut) return
2222

23-
_paq.push([`trackEvent`, eventCategory, eventAction, eventName, eventValue])
24-
if (!dev) return
23+
push([`trackEvent`, eventCategory, eventAction, eventName, eventValue])
2524

2625
console.debug(
2726
`[Matomo] event tracked, category: ${eventCategory}, action: ${eventAction}, name: ${eventName}, value: ${eventValue}`

src/pages/_app.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { useEffect } from "react"
12
import { appWithTranslation } from "next-i18next"
23
// ChakraProvider import updated as recommended on https://github.com/chakra-ui/chakra-ui/issues/4975#issuecomment-1174234230
34
// to reduce bundle size. Should be reverted to "@chakra-ui/react" in case on theme issues
45
import { ChakraProvider } from "@chakra-ui/provider"
56
import { extendBaseTheme } from "@chakra-ui/react"
7+
import { init } from "@socialgouv/matomo-next"
68

79
import customTheme from "@/@chakra-ui/theme"
810

@@ -13,6 +15,15 @@ import { RootLayout } from "@/layouts"
1315
import { inter, mono } from "@/lib/fonts"
1416

1517
const App = ({ Component, pageProps }: AppPropsWithLayout) => {
18+
useEffect(() => {
19+
if (!process.env.IS_PREVIEW_DEPLOY) {
20+
init({
21+
url: process.env.NEXT_PUBLIC_MATOMO_URL!,
22+
siteId: process.env.NEXT_PUBLIC_MATOMO_SITE_ID!,
23+
})
24+
}
25+
}, [])
26+
1627
// Per-Page Layouts: https://nextjs.org/docs/pages/building-your-application/routing/pages-and-layouts#with-typescript
1728
// Use the layout defined at the page level, if available
1829
const getLayout = Component.getLayout ?? ((page) => page)

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3365,6 +3365,11 @@
33653365
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e"
33663366
integrity sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==
33673367

3368+
"@socialgouv/matomo-next@^1.8.0":
3369+
version "1.8.0"
3370+
resolved "https://registry.yarnpkg.com/@socialgouv/matomo-next/-/matomo-next-1.8.0.tgz#1dee455a440b84bc135381a85fef33d000698222"
3371+
integrity sha512-00EdsbW0u/VrKFa7DfVjnXV4oXA6Ag3kkCisSL2nFseRQhEsds5T8xsAgvNQAtiMW9AR6Mz3TNZt7A2/mIb9kA==
3372+
33683373
"@storybook/addon-actions@7.5.3":
33693374
version "7.5.3"
33703375
resolved "https://registry.yarnpkg.com/@storybook/addon-actions/-/addon-actions-7.5.3.tgz#e0d0d819488d1d19918b23469b3ea6610fee5f07"

0 commit comments

Comments
 (0)