From f45f7f581903ba8aa8c5d8fc214f4dd630226e9a Mon Sep 17 00:00:00 2001 From: Ewen Le Bihan Date: Sun, 17 Dec 2023 01:07:46 +0100 Subject: [PATCH] Make custom pageview data attribute prefix shorter Since we're on the script element, no need to namespace the attribute with "umami", using data-event-* is enough --- src/tracker/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/tracker/index.js b/src/tracker/index.js index c1efbc422..7adc42922 100644 --- a/src/tracker/index.js +++ b/src/tracker/index.js @@ -26,6 +26,7 @@ const endpoint = `${root}/api/send`; const screen = `${width}x${height}`; const eventRegex = /data-umami-event-([\w-_]+)/; + const pageviewCustomPropertyRegex = /data-event-([\w-_]+)/; const eventNameAttribute = _data + 'umami-event'; const delayDuration = 300; @@ -41,9 +42,9 @@ const getPageviewEventData = () => Object.fromEntries( [...currentScript.attributes] - .filter(attribute => eventRegex.match(attribute.name)) + .filter(attribute => pageviewCustomPropertyRegex.match(attribute.name)) .map(attribute => { - const match = attribute.name.match(eventRegex); + const match = pageviewCustomPropertyRegex.match(attribute.name); return [match[1], attribute.value] }) )