Filter out all reserved data- fields on tracker before sending custom pageview data

This commit is contained in:
Ewen Le Bihan 2024-03-30 21:40:10 +01:00
parent faf1fb81c1
commit 9f449c73cb

View file

@ -27,6 +27,7 @@
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-([\w-_]+)/; const pageviewCustomPropertyRegex = /data-([\w-_]+)/;
const reservedDataAttributes = ['website-id', 'domains', 'umami-event', 'auto-track', 'host-url'];
const eventNameAttribute = _data + 'umami-event'; const eventNameAttribute = _data + 'umami-event';
const delayDuration = 300; const delayDuration = 300;
@ -44,7 +45,10 @@
Object.fromEntries( Object.fromEntries(
Array.from(currentScript.attributes) Array.from(currentScript.attributes)
.filter(attribute => attribute.name.match(pageviewCustomPropertyRegex)) .filter(attribute => attribute.name.match(pageviewCustomPropertyRegex))
.filter(attribute => attribute.name !== 'data-website-id') .filter(
attribute =>
!reservedDataAttributes.some(reserved => _data + reserved === attribute.name),
)
.map(attribute => { .map(attribute => {
const match = attribute.name.match(pageviewCustomPropertyRegex); const match = attribute.name.match(pageviewCustomPropertyRegex);
return [match[1], attribute.value]; return [match[1], attribute.value];