Skip to content

Commit b250bc4

Browse files
committed
feat: optimized way to normalize # in URLs for referrer classification
1 parent ed06336 commit b250bc4

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

facets.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,18 @@ export const facets = {
158158
.filter((evt) => evt.checkpoint === 'enter')
159159
.map((evt) => evt.source)
160160
.filter((source) => source)
161-
.map((source) => source.replace(/\/#$/, ''))
161+
.map((source) => {
162+
try {
163+
const url = new URL(source);
164+
url.hash = ''; // Remove the hash
165+
return url.href;
166+
} catch (e) {
167+
// eslint-disable-next-line no-console
168+
console.error(`Invalid URL: ${source}`);
169+
return null;
170+
}
171+
})
172+
.filter((source) => source)
162173
.map((source) => {
163174
const referrerClass = classifyReferrer(source);
164175
return referrerClass ? [
@@ -169,6 +180,7 @@ export const facets = {
169180
] : source;
170181
})
171182
.flat(),
183+
172184
/**
173185
* Extracts the target of the media view event from the bundle. This
174186
* is typically the URL of an image or video, and the URL is stripped

0 commit comments

Comments
 (0)