Skip to content

Commit af47079

Browse files
authored
Merge pull request #16775 from ethereum/fix-matomo-default-locale
fix(matomo): remove /en prefix normalization for English content
2 parents f1624c1 + 0acd275 commit af47079

File tree

2 files changed

+3
-29
lines changed

2 files changed

+3
-29
lines changed

src/components/Matomo.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { usePathname } from "next/navigation"
55
import { init, push } from "@socialgouv/matomo-next"
66

77
import { IS_PREVIEW_DEPLOY } from "@/lib/utils/env"
8-
import { normalizePathForMatomo } from "@/lib/utils/matomo"
98

109
export default function Matomo() {
1110
const pathname = usePathname()
@@ -41,11 +40,8 @@ export default function Matomo() {
4140
return setPreviousPath(pathname)
4241
}
4342

44-
const normalizedPreviousPath = normalizePathForMatomo(previousPath)
45-
const normalizedPathname = normalizePathForMatomo(pathname)
46-
47-
push(["setReferrerUrl", normalizedPreviousPath])
48-
push(["setCustomUrl", normalizedPathname])
43+
push(["setReferrerUrl", previousPath])
44+
push(["setCustomUrl", pathname])
4945
push(["deleteCustomVariables", "page"])
5046
setPreviousPath(pathname)
5147
// In order to ensure that the page title had been updated,

src/lib/utils/matomo.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,10 @@ import { push } from "@socialgouv/matomo-next"
22

33
import type { MatomoEventOptions } from "@/lib/types"
44

5-
import { DEFAULT_LOCALE, LOCALES_CODES } from "@/lib/constants"
6-
75
import { IS_PROD } from "./env"
86

97
export const MATOMO_LS_KEY = "ethereum-org.matomo-opt-out"
108

11-
/**
12-
* Normalizes paths to ensure consistent Matomo tracking.
13-
* With localePrefix: "as-needed", English paths don't have /en prefix,
14-
* but we want to track them as /en paths for analytics consistency.
15-
*/
16-
export const normalizePathForMatomo = (pathname: string): string => {
17-
const hasLocalePrefix = LOCALES_CODES.some((locale) =>
18-
pathname.startsWith(`/${locale}/`)
19-
)
20-
21-
if (hasLocalePrefix) {
22-
return pathname
23-
}
24-
25-
// For paths without locale prefix (English content), add /en prefix
26-
return `/${DEFAULT_LOCALE}${pathname}`
27-
}
28-
299
export const trackCustomEvent = ({
3010
eventCategory,
3111
eventAction,
@@ -43,9 +23,7 @@ export const trackCustomEvent = ({
4323

4424
// Set custom URL removing any query params or hash fragments
4525
if (window) {
46-
const normalizedPathname = normalizePathForMatomo(window.location.pathname)
47-
const normalizedUrl = window.location.origin + normalizedPathname
48-
push([`setCustomUrl`, normalizedUrl])
26+
push([`setCustomUrl`, window.location.href.split(/[?#]/)[0]])
4927
}
5028
push([`trackEvent`, eventCategory, eventAction, eventName, eventValue])
5129
}

0 commit comments

Comments
 (0)