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