Skip to content

Commit

Permalink
Shorten custom pageview data attribute to just data-*
Browse files Browse the repository at this point in the history
  • Loading branch information
ewen-lbh committed Mar 30, 2024
1 parent 3eae826 commit faf1fb8
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/tracker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
Expand Down

0 comments on commit faf1fb8

Please sign in to comment.