@@ -2,30 +2,10 @@ import { push } from "@socialgouv/matomo-next"
22
33import type { MatomoEventOptions } from "@/lib/types"
44
5- import { DEFAULT_LOCALE , LOCALES_CODES } from "@/lib/constants"
6-
75import { IS_PROD } from "./env"
86
97export 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-
299export 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