mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 06:37:18 +01:00
Fix filter issue for metrics. Closes #1268
This commit is contained in:
parent
25d97fca95
commit
ba1e28f082
4 changed files with 37 additions and 10 deletions
|
|
@ -94,6 +94,8 @@ export const CLICKHOUSE_DATE_FORMATS = {
|
|||
year: '%Y-01-01',
|
||||
};
|
||||
|
||||
export const FILTER_IGNORED = Symbol.for('filter-ignored');
|
||||
|
||||
export const DOMAIN_REGEX =
|
||||
/^(localhost(:[1-9]\d{0,4})?|((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63})$/;
|
||||
|
||||
|
|
|
|||
17
lib/db.js
17
lib/db.js
|
|
@ -8,6 +8,7 @@ import {
|
|||
POSTGRESQL_DATE_FORMATS,
|
||||
CLICKHOUSE,
|
||||
RELATIONAL,
|
||||
FILTER_IGNORED,
|
||||
} from 'lib/constants';
|
||||
import moment from 'moment-timezone';
|
||||
import { CLICKHOUSE_DATE_FORMATS } from './constants';
|
||||
|
|
@ -156,9 +157,9 @@ export function getTimestampInterval(field) {
|
|||
|
||||
export function getFilterQuery(table, column, filters = {}, params = []) {
|
||||
const query = Object.keys(filters).reduce((arr, key) => {
|
||||
const value = filters[key];
|
||||
const filter = filters[key];
|
||||
|
||||
if (value === undefined) {
|
||||
if (filter === undefined || filter === FILTER_IGNORED) {
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
|
@ -166,7 +167,7 @@ export function getFilterQuery(table, column, filters = {}, params = []) {
|
|||
case 'url':
|
||||
if (table === 'pageview' || table === 'event') {
|
||||
arr.push(`and ${table}.${key}=$${params.length + 1}`);
|
||||
params.push(decodeURIComponent(value));
|
||||
params.push(decodeURIComponent(filter));
|
||||
console.log(params);
|
||||
}
|
||||
break;
|
||||
|
|
@ -177,21 +178,21 @@ export function getFilterQuery(table, column, filters = {}, params = []) {
|
|||
case 'country':
|
||||
if (table === 'session') {
|
||||
arr.push(`and ${table}.${key}=$${params.length + 1}`);
|
||||
params.push(decodeURIComponent(value));
|
||||
params.push(decodeURIComponent(filter));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'event_type':
|
||||
if (table === 'event') {
|
||||
arr.push(`and ${table}.${key}=$${params.length + 1}`);
|
||||
params.push(decodeURIComponent(value));
|
||||
params.push(decodeURIComponent(filter));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'referrer':
|
||||
if (table === 'pageview') {
|
||||
if (table === 'pageview' || table === 'event') {
|
||||
arr.push(`and ${table}.referrer like $${params.length + 1}`);
|
||||
params.push(`%${decodeURIComponent(value)}%`);
|
||||
params.push(`%${decodeURIComponent(filter)}%`);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -199,7 +200,7 @@ export function getFilterQuery(table, column, filters = {}, params = []) {
|
|||
if (table === 'pageview') {
|
||||
arr.push(`and ${table}.referrer not like $${params.length + 1}`);
|
||||
arr.push(`and ${table}.referrer not like '/%'`);
|
||||
params.push(`%://${value}/%`);
|
||||
params.push(`%://${filter}/%`);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue