Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
Added option to exclude hash.
Mike Cao4ddf8d0d5654
diff --git a/src/pages/api/send.ts b/src/pages/api/send.tsindex ddaaca94f..e2a450b72 100644--- a/src/pages/api/send.ts+++ b/src/pages/api/send.ts@@ -7,7 +7,6 @@ import {methodNotAllowed,ok,safeDecodeURI,- send,} from 'next-basics';import { COLLECTION_TYPE, HOSTNAME_REGEX, IP_REGEX } from 'lib/constants';import { secret, visitSalt, uuid } from 'lib/crypto';@@ -103,7 +102,7 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {const session = req.session;- if (!session?.id) {+ if (!session?.id || !session?.websiteId) {return;}@@ -162,9 +161,9 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {});}- const token = createToken(session, secret());+ const cache = createToken(session, secret());- return send(res, token);+ return ok(res, { cache });}return methodNotAllowed(res);diff --git a/src/tracker/index.js b/src/tracker/index.jsindex 9fa560e6d..14a5cb684 100644--- a/src/tracker/index.js+++ b/src/tracker/index.js@@ -21,6 +21,7 @@const tag = attr(_data + 'tag');const autoTrack = attr(_data + 'auto-track') !== _false;const excludeSearch = attr(_data + 'exclude-search') === _true;+ const excludeHash = attr(_data + 'exclude-hash') === _true;const domain = attr(_data + 'domains') || '';const domains = domain.split(',').map(n => n.trim());const host =@@ -53,13 +54,12 @@const parseURL = url => {try {- // use location.origin as the base to handle cases where the url is a relative pathconst { pathname, search, hash } = new URL(url, location.href);- url = pathname + search + hash;++ return pathname + (excludeSearch ? '' : search) + (excludeHash ? '' : hash);} catch (e) {- /* empty */+ return url;}- return excludeSearch ? url.split('?')[0] : url;};const getPayload = () => ({@@ -194,6 +194,7 @@/* Tracking functions */const trackingDisabled = () =>+ disabled ||!website ||(localStorage && localStorage.getItem('umami.disabled')) ||(domain && !domains.includes(hostname));@@ -215,9 +216,11 @@body: JSON.stringify({ type, payload }),headers,});- const text = await res.text();- return (cache = text);+ const data = await res.json();++ disabled = res.status === 429;+ cache = data?.cache;} catch (e) {/* empty */}@@ -264,6 +267,7 @@let title = document.title;let cache;let initialized;+ let disabled = false;if (autoTrack && !trackingDisabled()) {if (document.readyState === 'complete') {