From faf1fb81c153987269d6b3fbfc3faba5a46f0a20 Mon Sep 17 00:00:00 2001 From: Ewen Le Bihan Date: Sat, 30 Mar 2024 21:27:22 +0100 Subject: [PATCH] Shorten custom pageview data attribute to just data-* --- src/tracker/index.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/tracker/index.js b/src/tracker/index.js index c517285621..96163a8624 100644 --- a/src/tracker/index.js +++ b/src/tracker/index.js @@ -26,7 +26,7 @@ const endpoint = `${root}/api/send`; const screen = `${width}x${height}`; const eventRegex = /data-umami-event-([\w-_]+)/; - const pageviewCustomPropertyRegex = /data-event-([\w-_]+)/; + const pageviewCustomPropertyRegex = /data-([\w-_]+)/; const eventNameAttribute = _data + 'umami-event'; const delayDuration = 300; @@ -40,14 +40,16 @@ } }; - const getPageviewEventData = () => Object.fromEntries( - Array.from(currentScript.attributes) - .filter(attribute => attribute.name.match(pageviewCustomPropertyRegex)) - .map(attribute => { - const match = attribute.name.match(pageviewCustomPropertyRegex); - return [match[1], attribute.value] - }) - ) + const getPageviewEventData = () => + Object.fromEntries( + Array.from(currentScript.attributes) + .filter(attribute => attribute.name.match(pageviewCustomPropertyRegex)) + .filter(attribute => attribute.name !== 'data-website-id') + .map(attribute => { + const match = attribute.name.match(pageviewCustomPropertyRegex); + return [match[1], attribute.value]; + }), + ); const getPayload = () => ({ website,