mirror of
https://github.com/umami-software/umami.git
synced 2026-02-09 07:07:17 +01:00
udpate constants and references to filter groups
This commit is contained in:
parent
5ffafc71fc
commit
657ae8ebdb
6 changed files with 39 additions and 22 deletions
|
|
@ -105,6 +105,22 @@ function getFilterQuery(filters: QueryFilters = {}, options: QueryOptions = {})
|
|||
return query.join('\n');
|
||||
}
|
||||
|
||||
function getCohortQuery(filters: QueryFilters = {}, options: QueryOptions = {}) {
|
||||
const query = filtersToArray(filters, options).reduce((arr, { name, column, operator }) => {
|
||||
if (column) {
|
||||
arr.push(`and ${mapFilter(column, operator, name)}`);
|
||||
|
||||
if (name === 'referrer') {
|
||||
arr.push(`and referrer_domain != hostname`);
|
||||
}
|
||||
}
|
||||
|
||||
return arr;
|
||||
}, []);
|
||||
|
||||
return query.join('\n');
|
||||
}
|
||||
|
||||
function getDateQuery(filters: QueryFilters = {}) {
|
||||
const { startDate, endDate, timezone } = filters;
|
||||
|
||||
|
|
@ -146,6 +162,7 @@ async function parseFilters(websiteId: string, filters: QueryFilters = {}, optio
|
|||
websiteId,
|
||||
startDate: maxDate(filters.startDate, new Date(website?.resetAt)),
|
||||
},
|
||||
cohortQuery: getCohortQuery(filters),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,10 @@ export const SESSION_COLUMNS = [
|
|||
'host',
|
||||
];
|
||||
|
||||
export const FILTER_GROUPS = ['segment', 'cohort'];
|
||||
export const FILTER_GROUPS = {
|
||||
segment: 'segment',
|
||||
cohort: 'cohort',
|
||||
};
|
||||
|
||||
export const FILTER_COLUMNS = {
|
||||
url: 'url_path',
|
||||
|
|
@ -66,8 +69,6 @@ export const FILTER_COLUMNS = {
|
|||
language: 'language',
|
||||
event: 'event_name',
|
||||
tag: 'tag',
|
||||
segment: 'segment',
|
||||
cohort: 'cohort',
|
||||
};
|
||||
|
||||
export const COLLECTION_TYPE = {
|
||||
|
|
|
|||
|
|
@ -91,16 +91,19 @@ export async function getRequestFilters(query: Record<string, any>, websiteId?:
|
|||
for (const key of Object.keys(FILTER_COLUMNS)) {
|
||||
const value = query[key];
|
||||
if (value !== undefined) {
|
||||
if (FILTER_GROUPS.includes(key)) {
|
||||
const segment = await getWebsiteSegment(websiteId, key, value);
|
||||
if (key === 'segment') {
|
||||
// merge filters into result
|
||||
Object.assign(result, segment.parameters);
|
||||
} else {
|
||||
result[key] = segment.parameters;
|
||||
}
|
||||
result[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
for (const key of Object.keys(FILTER_GROUPS)) {
|
||||
const value = query[key];
|
||||
if (value !== undefined) {
|
||||
const segment = await getWebsiteSegment(websiteId, key, value);
|
||||
if (key === 'segment') {
|
||||
// merge filters into result
|
||||
Object.assign(result, segment.parameters);
|
||||
} else {
|
||||
result[key] = value;
|
||||
result[key] = segment.parameters;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue