mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-01 12:29:35 +01:00
commit
be7f69fd5d
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "umami",
|
||||
"version": "2.11.0",
|
||||
"version": "2.11.1",
|
||||
"description": "A simple, fast, privacy-focused alternative to Google Analytics.",
|
||||
"author": "Umami Software, Inc. <hello@umami.is>",
|
||||
"license": "MIT",
|
||||
|
@ -55,6 +55,8 @@ export function FilterParameters() {
|
||||
<FilterSelectForm
|
||||
websiteId={websiteId}
|
||||
fields={fields.filter(({ name }) => !filters.find(f => f.name === name))}
|
||||
startDate={dateRange?.startDate}
|
||||
endDate={dateRange?.endDate}
|
||||
onChange={handleAdd}
|
||||
/>
|
||||
</PopupForm>
|
||||
|
@ -1,11 +1,12 @@
|
||||
import { useState } from 'react';
|
||||
import FieldSelectForm from './FieldSelectForm';
|
||||
import FieldFilterEditForm from './FieldFilterEditForm';
|
||||
import { useDateRange } from 'components/hooks';
|
||||
|
||||
export interface FilterSelectFormProps {
|
||||
websiteId?: string;
|
||||
fields: any[];
|
||||
startDate?: Date;
|
||||
endDate?: Date;
|
||||
onChange?: (filter: { name: string; type: string; operator: string; value: string }) => void;
|
||||
allowFilterSelect?: boolean;
|
||||
}
|
||||
@ -13,11 +14,12 @@ export interface FilterSelectFormProps {
|
||||
export default function FilterSelectForm({
|
||||
websiteId,
|
||||
fields,
|
||||
startDate,
|
||||
endDate,
|
||||
onChange,
|
||||
allowFilterSelect,
|
||||
}: FilterSelectFormProps) {
|
||||
const [field, setField] = useState<{ name: string; label: string; type: string }>();
|
||||
const [{ startDate, endDate }] = useDateRange(websiteId);
|
||||
|
||||
if (!field) {
|
||||
return <FieldSelectForm fields={fields} onSelect={setField} showType={false} />;
|
||||
|
@ -2,7 +2,7 @@ import classNames from 'classnames';
|
||||
import { Button, Icon, Icons, Popup, PopupTrigger, Text } from 'react-basics';
|
||||
import PopupForm from 'app/(main)/reports/[reportId]/PopupForm';
|
||||
import FilterSelectForm from 'app/(main)/reports/[reportId]/FilterSelectForm';
|
||||
import { useFields, useMessages, useNavigation } from 'components/hooks';
|
||||
import { useFields, useMessages, useNavigation, useDateRange } from 'components/hooks';
|
||||
import { OPERATOR_PREFIXES } from 'lib/constants';
|
||||
import styles from './WebsiteFilterButton.module.css';
|
||||
|
||||
@ -16,6 +16,7 @@ export function WebsiteFilterButton({
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { renderUrl, router } = useNavigation();
|
||||
const { fields } = useFields();
|
||||
const [{ startDate, endDate }] = useDateRange(websiteId);
|
||||
|
||||
const handleAddFilter = ({ name, operator, value }) => {
|
||||
const prefix = OPERATOR_PREFIXES[operator];
|
||||
@ -38,6 +39,8 @@ export function WebsiteFilterButton({
|
||||
<FilterSelectForm
|
||||
websiteId={websiteId}
|
||||
fields={fields}
|
||||
startDate={startDate}
|
||||
endDate={endDate}
|
||||
onChange={value => {
|
||||
handleAddFilter(value);
|
||||
close();
|
||||
|
@ -93,6 +93,13 @@ function getTimestampDiffQuery(field1: string, field2: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
function getSearchQuery(column: string): string {
|
||||
const db = getDatabaseType();
|
||||
const like = db === POSTGRESQL ? 'ilike' : 'like';
|
||||
|
||||
return `and ${column} ${like} {{search}}`;
|
||||
}
|
||||
|
||||
function mapFilter(column: string, operator: string, name: string, type: string = '') {
|
||||
const db = getDatabaseType();
|
||||
const like = db === POSTGRESQL ? 'ilike' : 'like';
|
||||
@ -253,6 +260,7 @@ export default {
|
||||
getFilterQuery,
|
||||
getSearchParameters,
|
||||
getTimestampDiffQuery,
|
||||
getSearchQuery,
|
||||
getQueryMode,
|
||||
pagedQuery,
|
||||
parseFilters,
|
||||
|
@ -87,7 +87,7 @@ export default async (
|
||||
}
|
||||
|
||||
if (SESSION_COLUMNS.includes(type)) {
|
||||
const data = await getSessionMetrics(websiteId, column, filters, limit, offset);
|
||||
const data = await getSessionMetrics(websiteId, type, filters, limit, offset);
|
||||
|
||||
if (type === 'language') {
|
||||
const combined = {};
|
||||
|
@ -18,11 +18,11 @@ async function relationalQuery(
|
||||
endDate: Date,
|
||||
search: string,
|
||||
) {
|
||||
const { rawQuery } = prisma;
|
||||
const { rawQuery, getSearchQuery } = prisma;
|
||||
let searchQuery = '';
|
||||
|
||||
if (search) {
|
||||
searchQuery = `and ${column} LIKE {{search}}`;
|
||||
searchQuery = getSearchQuery(column);
|
||||
}
|
||||
|
||||
return rawQuery(
|
||||
|
@ -1,17 +1,11 @@
|
||||
import prisma from 'lib/prisma';
|
||||
import clickhouse from 'lib/clickhouse';
|
||||
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
|
||||
import { EVENT_TYPE, SESSION_COLUMNS } from 'lib/constants';
|
||||
import { EVENT_TYPE, FILTER_COLUMNS, SESSION_COLUMNS } from 'lib/constants';
|
||||
import { QueryFilters } from 'lib/types';
|
||||
|
||||
export async function getSessionMetrics(
|
||||
...args: [
|
||||
websiteId: string,
|
||||
column: string,
|
||||
filters: QueryFilters,
|
||||
limit?: number,
|
||||
offset?: number,
|
||||
]
|
||||
...args: [websiteId: string, type: string, filters: QueryFilters, limit?: number, offset?: number]
|
||||
) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
@ -21,11 +15,12 @@ export async function getSessionMetrics(
|
||||
|
||||
async function relationalQuery(
|
||||
websiteId: string,
|
||||
column: string,
|
||||
type: string,
|
||||
filters: QueryFilters,
|
||||
limit: number = 500,
|
||||
offset: number = 0,
|
||||
) {
|
||||
const column = FILTER_COLUMNS[type] || type;
|
||||
const { parseFilters, rawQuery } = prisma;
|
||||
const { filterQuery, joinSession, params } = await parseFilters(
|
||||
websiteId,
|
||||
@ -34,7 +29,7 @@ async function relationalQuery(
|
||||
eventType: EVENT_TYPE.pageView,
|
||||
},
|
||||
{
|
||||
joinSession: SESSION_COLUMNS.includes(column),
|
||||
joinSession: SESSION_COLUMNS.includes(type),
|
||||
},
|
||||
);
|
||||
const includeCountry = column === 'city' || column === 'subdivision1';
|
||||
@ -63,11 +58,12 @@ async function relationalQuery(
|
||||
|
||||
async function clickhouseQuery(
|
||||
websiteId: string,
|
||||
column: string,
|
||||
type: string,
|
||||
filters: QueryFilters,
|
||||
limit: number = 500,
|
||||
offset: number = 0,
|
||||
): Promise<{ x: string; y: number }[]> {
|
||||
const column = FILTER_COLUMNS[type] || type;
|
||||
const { parseFilters, rawQuery } = clickhouse;
|
||||
const { filterQuery, params } = await parseFilters(websiteId, {
|
||||
...filters,
|
||||
|
Loading…
Reference in New Issue
Block a user