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
This commit is contained in:
Ewen Le Bihan 2023-12-17 01:07:46 +01:00
parent 1fd997c374
commit f45f7f5819

View file

@ -26,6 +26,7 @@
const endpoint = `${root}/api/send`; const endpoint = `${root}/api/send`;
const screen = `${width}x${height}`; const screen = `${width}x${height}`;
const eventRegex = /data-umami-event-([\w-_]+)/; const eventRegex = /data-umami-event-([\w-_]+)/;
const pageviewCustomPropertyRegex = /data-event-([\w-_]+)/;
const eventNameAttribute = _data + 'umami-event'; const eventNameAttribute = _data + 'umami-event';
const delayDuration = 300; const delayDuration = 300;
@ -41,9 +42,9 @@
const getPageviewEventData = () => Object.fromEntries( const getPageviewEventData = () => Object.fromEntries(
[...currentScript.attributes] [...currentScript.attributes]
.filter(attribute => eventRegex.match(attribute.name)) .filter(attribute => pageviewCustomPropertyRegex.match(attribute.name))
.map(attribute => { .map(attribute => {
const match = attribute.name.match(eventRegex); const match = pageviewCustomPropertyRegex.match(attribute.name);
return [match[1], attribute.value] return [match[1], attribute.value]
}) })
) )