From 0acd2753c991d0d2c5fc6f1120289f69d3605a85 Mon Sep 17 00:00:00 2001 From: Pablo Pettinari Date: Wed, 3 Dec 2025 13:25:17 +0100 Subject: [PATCH] fix(matomo): remove /en prefix normalization for English content tracking --- src/components/Matomo.tsx | 8 ++------ src/lib/utils/matomo.ts | 24 +----------------------- 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/src/components/Matomo.tsx b/src/components/Matomo.tsx index d5f3bcf638b..9136e31f294 100644 --- a/src/components/Matomo.tsx +++ b/src/components/Matomo.tsx @@ -5,7 +5,6 @@ import { usePathname } from "next/navigation" import { init, push } from "@socialgouv/matomo-next" import { IS_PREVIEW_DEPLOY } from "@/lib/utils/env" -import { normalizePathForMatomo } from "@/lib/utils/matomo" export default function Matomo() { const pathname = usePathname() @@ -41,11 +40,8 @@ export default function Matomo() { return setPreviousPath(pathname) } - const normalizedPreviousPath = normalizePathForMatomo(previousPath) - const normalizedPathname = normalizePathForMatomo(pathname) - - push(["setReferrerUrl", normalizedPreviousPath]) - push(["setCustomUrl", normalizedPathname]) + push(["setReferrerUrl", previousPath]) + push(["setCustomUrl", pathname]) push(["deleteCustomVariables", "page"]) setPreviousPath(pathname) // In order to ensure that the page title had been updated, diff --git a/src/lib/utils/matomo.ts b/src/lib/utils/matomo.ts index 9804fac634e..112c93d637c 100644 --- a/src/lib/utils/matomo.ts +++ b/src/lib/utils/matomo.ts @@ -2,30 +2,10 @@ import { push } from "@socialgouv/matomo-next" import type { MatomoEventOptions } from "@/lib/types" -import { DEFAULT_LOCALE, LOCALES_CODES } from "@/lib/constants" - import { IS_PROD } from "./env" export const MATOMO_LS_KEY = "ethereum-org.matomo-opt-out" -/** - * Normalizes paths to ensure consistent Matomo tracking. - * With localePrefix: "as-needed", English paths don't have /en prefix, - * but we want to track them as /en paths for analytics consistency. - */ -export const normalizePathForMatomo = (pathname: string): string => { - const hasLocalePrefix = LOCALES_CODES.some((locale) => - pathname.startsWith(`/${locale}/`) - ) - - if (hasLocalePrefix) { - return pathname - } - - // For paths without locale prefix (English content), add /en prefix - return `/${DEFAULT_LOCALE}${pathname}` -} - export const trackCustomEvent = ({ eventCategory, eventAction, @@ -43,9 +23,7 @@ export const trackCustomEvent = ({ // Set custom URL removing any query params or hash fragments if (window) { - const normalizedPathname = normalizePathForMatomo(window.location.pathname) - const normalizedUrl = window.location.origin + normalizedPathname - push([`setCustomUrl`, normalizedUrl]) + push([`setCustomUrl`, window.location.href.split(/[?#]/)[0]]) } push([`trackEvent`, eventCategory, eventAction, eventName, eventValue]) }