Skip to content

Commit 25a7b20

Browse files
committed
simplify pathname normalization
1 parent 9abbf1e commit 25a7b20

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/components/Matomo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default function Matomo() {
4444
const normalizedPreviousPath = normalizePathForMatomo(previousPath)
4545
const normalizedPathname = normalizePathForMatomo(pathname)
4646

47-
push(["setReferrerUrl", `${normalizedPreviousPath}`])
47+
push(["setReferrerUrl", normalizedPreviousPath])
4848
push(["setCustomUrl", normalizedPathname])
4949
push(["deleteCustomVariables", "page"])
5050
setPreviousPath(pathname)

src/lib/utils/matomo.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@ export const MATOMO_LS_KEY = "ethereum-org.matomo-opt-out"
1212
* but we want to track them as /en paths for analytics consistency.
1313
*/
1414
export const normalizePathForMatomo = (pathname: string): string => {
15-
// If already has a locale prefix (like /es/, /fr/), keep it as is
16-
const hasLocalePrefix = LOCALES_CODES.some(
17-
(locale) => locale !== DEFAULT_LOCALE && pathname.startsWith(`/${locale}/`)
15+
const hasLocalePrefix = LOCALES_CODES.some((locale) =>
16+
pathname.startsWith(`/${locale}/`)
1817
)
1918

2019
if (hasLocalePrefix) {
2120
return pathname
2221
}
2322

2423
// For paths without locale prefix (English content), add /en prefix
25-
return pathname === "/" ? "/en" : `/en${pathname}`
24+
return `/${DEFAULT_LOCALE}${pathname}`
2625
}
2726

2827
export interface MatomoEventOptions {

0 commit comments

Comments
 (0)