Skip to content

Commit

Permalink
Merge pull request #2679 from CediGasser/fix/track-only-path-on-pushs…
Browse files Browse the repository at this point in the history
…tate

Fix: Properly parse url and respect data-exclude-search attribute in tracker
  • Loading branch information
mikecao committed Apr 16, 2024
2 parents 0ef62d0 + 6c8fe9f commit a83a71a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/tracker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
document,
history,
} = window;
const { hostname, pathname, search } = location;
const { hostname, href } = location;
const { currentScript, referrer } = document;

if (!currentScript) return;
Expand Down Expand Up @@ -52,6 +52,12 @@
};

const parseURL = url => {
try {
const { pathname, search } = new URL(url);
url = pathname + search;
} catch {
/* empty */
}
return excludeSearch ? url.split('?')[0] : url;
};

Expand Down Expand Up @@ -238,7 +244,7 @@
};
}

let currentUrl = `${pathname}${search}`;
let currentUrl = parseURL(href);
let currentRef = referrer !== hostname ? referrer : '';
let title = document.title;
let cache;
Expand Down

0 comments on commit a83a71a

Please sign in to comment.