mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 06:37:18 +01:00
New page and referrer url filters.
This commit is contained in:
parent
1d977875be
commit
cf8ed13d1f
11 changed files with 133 additions and 50 deletions
|
|
@ -5,11 +5,15 @@ import { removeTrailingSlash } from './format';
|
|||
export const browserFilter = data =>
|
||||
data.map(({ x, ...props }) => ({ x: BROWSERS[x] || x, ...props }));
|
||||
|
||||
export const urlFilter = (data, { domain }) => {
|
||||
export const urlFilter = (data, { domain, raw }) => {
|
||||
const isValidUrl = url => {
|
||||
return url !== '' && !url.startsWith('#');
|
||||
};
|
||||
|
||||
if (raw) {
|
||||
return data.filter(({ x }) => isValidUrl(x));
|
||||
}
|
||||
|
||||
const cleanUrl = url => {
|
||||
try {
|
||||
const { pathname, searchParams } = new URL(url);
|
||||
|
|
@ -47,11 +51,16 @@ export const urlFilter = (data, { domain }) => {
|
|||
.sort(firstBy('y', -1).thenBy('x'));
|
||||
};
|
||||
|
||||
export const refFilter = (data, { domain, domainsOnly }) => {
|
||||
export const refFilter = (data, { domain, domainOnly, raw }) => {
|
||||
const isValidRef = ref => {
|
||||
return ref !== '' && !ref.startsWith('/') && !ref.startsWith('#');
|
||||
};
|
||||
|
||||
if (raw) {
|
||||
const regex = new RegExp(`http[s]?://([^.]+.)?${domain}`);
|
||||
return data.filter(({ x }) => isValidRef(x) && !regex.test(x));
|
||||
}
|
||||
|
||||
const cleanUrl = url => {
|
||||
try {
|
||||
const { hostname, origin, pathname, searchParams, protocol } = new URL(url);
|
||||
|
|
@ -60,7 +69,7 @@ export const refFilter = (data, { domain, domainsOnly }) => {
|
|||
return null;
|
||||
}
|
||||
|
||||
if (domainsOnly && hostname) {
|
||||
if (domainOnly && hostname) {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue