Updated url and referrer logic in tracker.

This commit is contained in:
Mike Cao 2024-03-25 22:50:03 -07:00
parent 741c77d9f8
commit 2fa95448e0

View File

@ -8,7 +8,7 @@
history, history,
} = window; } = window;
const { hostname, pathname, search } = location; const { hostname, pathname, search } = location;
const { currentScript } = document; const { currentScript, referrer } = document;
if (!currentScript) return; if (!currentScript) return;
@ -19,7 +19,7 @@
const website = attr(_data + 'website-id'); const website = attr(_data + 'website-id');
const hostUrl = attr(_data + 'host-url'); const hostUrl = attr(_data + 'host-url');
const autoTrack = attr(_data + 'auto-track') !== _false; const autoTrack = attr(_data + 'auto-track') !== _false;
const stripSearch = attr(_data + 'strip-search') === _true; const excludeSearch = attr(_data + 'exclude-search') === _true;
const domain = attr(_data + 'domains') || ''; const domain = attr(_data + 'domains') || '';
const domains = domain.split(',').map(n => n.trim()); const domains = domain.split(',').map(n => n.trim());
const host = const host =
@ -32,12 +32,8 @@
/* Helper functions */ /* Helper functions */
const getPath = url => { const parseURL = url => {
try { return excludeSearch ? url.split('?')[0] : url;
return new URL(url).pathname;
} catch (e) {
return url;
}
}; };
const getPayload = () => ({ const getPayload = () => ({
@ -56,7 +52,7 @@
if (!url) return; if (!url) return;
currentRef = currentUrl; currentRef = currentUrl;
currentUrl = getPath(url.toString()); currentUrl = parseURL(url.toString());
if (currentUrl !== currentRef) { if (currentUrl !== currentRef) {
setTimeout(track, delayDuration); setTimeout(track, delayDuration);
@ -222,8 +218,8 @@
}; };
} }
let currentUrl = `${pathname}${stripSearch ? '' : search}`; let currentUrl = `${pathname}${search}`;
let currentRef = document.referrer; let currentRef = referrer !== hostname ? referrer : '';
let title = document.title; let title = document.title;
let cache; let cache;
let initialized; let initialized;