Skip to content

Commit

Permalink
Updated url and referrer logic in tracker.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Mar 26, 2024
1 parent 741c77d commit 2fa9544
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/tracker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
history,
} = window;
const { hostname, pathname, search } = location;
const { currentScript } = document;
const { currentScript, referrer } = document;

if (!currentScript) return;

Expand All @@ -19,7 +19,7 @@
const website = attr(_data + 'website-id');
const hostUrl = attr(_data + 'host-url');
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 domains = domain.split(',').map(n => n.trim());
const host =
Expand All @@ -32,12 +32,8 @@

/* Helper functions */

const getPath = url => {
try {
return new URL(url).pathname;
} catch (e) {
return url;
}
const parseURL = url => {
return excludeSearch ? url.split('?')[0] : url;
};

const getPayload = () => ({
Expand All @@ -56,7 +52,7 @@
if (!url) return;

currentRef = currentUrl;
currentUrl = getPath(url.toString());
currentUrl = parseURL(url.toString());

if (currentUrl !== currentRef) {
setTimeout(track, delayDuration);
Expand Down Expand Up @@ -222,8 +218,8 @@
};
}

let currentUrl = `${pathname}${stripSearch ? '' : search}`;
let currentRef = document.referrer;
let currentUrl = `${pathname}${search}`;
let currentRef = referrer !== hostname ? referrer : '';
let title = document.title;
let cache;
let initialized;
Expand Down

0 comments on commit 2fa9544

Please sign in to comment.