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) => {