From e53de577200caf3743ca2552113b8d3a5df9ac5b Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sun, 29 Oct 2023 01:26:02 +0800 Subject: [PATCH] refactor: change tracker path --- src/server/router/website.ts | 2 +- src/tracker/index.js | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/server/router/website.ts b/src/server/router/website.ts index ef545a6..bf2e56b 100644 --- a/src/server/router/website.ts +++ b/src/server/router/website.ts @@ -43,7 +43,7 @@ websiteRouter.post( .matches(/event|identify/i) ), async (req, res) => { - // https://github1s.com/umami-software/umami/blob/master/src/pages/api/send.ts + // Reference: https://github1s.com/umami-software/umami/blob/master/src/pages/api/send.ts const { type, payload } = req.body; const { diff --git a/src/tracker/index.js b/src/tracker/index.js index 4ff6d9d..446b1ce 100644 --- a/src/tracker/index.js +++ b/src/tracker/index.js @@ -47,10 +47,11 @@ }; const getPath = (url) => { - if (url.substring(0, 4) === 'http') { - return '/' + url.split('/').splice(3).join('/'); + try { + return new URL(url).pathname; + } catch (e) { + return url; } - return url; }; const getPayload = () => ({ @@ -199,7 +200,8 @@ headers, }) .then((res) => res.text()) - .then((text) => (cache = text)); + .then((text) => (cache = text)) + .catch(() => {}); }; const track = (obj, data) => {