mirror of
https://github.com/umami-software/umami.git
synced 2026-02-11 08:07:12 +01:00
Added option to exclude hash.
This commit is contained in:
parent
2d2733387d
commit
4ddf8d0d56
2 changed files with 13 additions and 10 deletions
|
|
@ -7,7 +7,6 @@ import {
|
||||||
methodNotAllowed,
|
methodNotAllowed,
|
||||||
ok,
|
ok,
|
||||||
safeDecodeURI,
|
safeDecodeURI,
|
||||||
send,
|
|
||||||
} from 'next-basics';
|
} from 'next-basics';
|
||||||
import { COLLECTION_TYPE, HOSTNAME_REGEX, IP_REGEX } from 'lib/constants';
|
import { COLLECTION_TYPE, HOSTNAME_REGEX, IP_REGEX } from 'lib/constants';
|
||||||
import { secret, visitSalt, uuid } from 'lib/crypto';
|
import { secret, visitSalt, uuid } from 'lib/crypto';
|
||||||
|
|
@ -103,7 +102,7 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
|
||||||
|
|
||||||
const session = req.session;
|
const session = req.session;
|
||||||
|
|
||||||
if (!session?.id) {
|
if (!session?.id || !session?.websiteId) {
|
||||||
return;
|
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);
|
return methodNotAllowed(res);
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
const tag = attr(_data + 'tag');
|
const tag = attr(_data + 'tag');
|
||||||
const autoTrack = attr(_data + 'auto-track') !== _false;
|
const autoTrack = attr(_data + 'auto-track') !== _false;
|
||||||
const excludeSearch = attr(_data + 'exclude-search') === _true;
|
const excludeSearch = attr(_data + 'exclude-search') === _true;
|
||||||
|
const excludeHash = attr(_data + 'exclude-hash') === _true;
|
||||||
const domain = attr(_data + 'domains') || '';
|
const domain = attr(_data + 'domains') || '';
|
||||||
const domains = domain.split(',').map(n => n.trim());
|
const domains = domain.split(',').map(n => n.trim());
|
||||||
const host =
|
const host =
|
||||||
|
|
@ -53,13 +54,12 @@
|
||||||
|
|
||||||
const parseURL = url => {
|
const parseURL = url => {
|
||||||
try {
|
try {
|
||||||
// use location.origin as the base to handle cases where the url is a relative path
|
|
||||||
const { pathname, search, hash } = new URL(url, location.href);
|
const { pathname, search, hash } = new URL(url, location.href);
|
||||||
url = pathname + search + hash;
|
|
||||||
|
return pathname + (excludeSearch ? '' : search) + (excludeHash ? '' : hash);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
/* empty */
|
return url;
|
||||||
}
|
}
|
||||||
return excludeSearch ? url.split('?')[0] : url;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getPayload = () => ({
|
const getPayload = () => ({
|
||||||
|
|
@ -194,6 +194,7 @@
|
||||||
/* Tracking functions */
|
/* Tracking functions */
|
||||||
|
|
||||||
const trackingDisabled = () =>
|
const trackingDisabled = () =>
|
||||||
|
disabled ||
|
||||||
!website ||
|
!website ||
|
||||||
(localStorage && localStorage.getItem('umami.disabled')) ||
|
(localStorage && localStorage.getItem('umami.disabled')) ||
|
||||||
(domain && !domains.includes(hostname));
|
(domain && !domains.includes(hostname));
|
||||||
|
|
@ -215,9 +216,11 @@
|
||||||
body: JSON.stringify({ type, payload }),
|
body: JSON.stringify({ type, payload }),
|
||||||
headers,
|
headers,
|
||||||
});
|
});
|
||||||
const text = await res.text();
|
|
||||||
|
|
||||||
return (cache = text);
|
const data = await res.json();
|
||||||
|
|
||||||
|
disabled = res.status === 429;
|
||||||
|
cache = data?.cache;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
/* empty */
|
/* empty */
|
||||||
}
|
}
|
||||||
|
|
@ -264,6 +267,7 @@
|
||||||
let title = document.title;
|
let title = document.title;
|
||||||
let cache;
|
let cache;
|
||||||
let initialized;
|
let initialized;
|
||||||
|
let disabled = false;
|
||||||
|
|
||||||
if (autoTrack && !trackingDisabled()) {
|
if (autoTrack && !trackingDisabled()) {
|
||||||
if (document.readyState === 'complete') {
|
if (document.readyState === 'complete') {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue