mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-01 12:29:35 +01:00
Resolve issues in event data
This commit is contained in:
parent
38445fce7a
commit
c3e261fc50
@ -36,6 +36,7 @@ export function EventDataValueTable({ data = [], event }) {
|
|||||||
<GridColumn name="dataType" label={formatMessage(labels.type)}>
|
<GridColumn name="dataType" label={formatMessage(labels.type)}>
|
||||||
{row => DATA_TYPES[row.dataType]}
|
{row => DATA_TYPES[row.dataType]}
|
||||||
</GridColumn>
|
</GridColumn>
|
||||||
|
<GridColumn name="fieldValue" label={formatMessage(labels.value)} />
|
||||||
<GridColumn name="total" label={formatMessage(labels.totalRecords)} width="200px">
|
<GridColumn name="total" label={formatMessage(labels.totalRecords)} width="200px">
|
||||||
{({ total }) => total.toLocaleString()}
|
{({ total }) => total.toLocaleString()}
|
||||||
</GridColumn>
|
</GridColumn>
|
||||||
|
@ -5,18 +5,18 @@ import { EventDataMetricsBar } from 'components/pages/event-data/EventDataMetric
|
|||||||
import { useDateRange, useApi, usePageQuery } from 'hooks';
|
import { useDateRange, useApi, usePageQuery } from 'hooks';
|
||||||
import styles from './WebsiteEventData.module.css';
|
import styles from './WebsiteEventData.module.css';
|
||||||
|
|
||||||
function useData(websiteId, eventName) {
|
function useData(websiteId, event) {
|
||||||
const [dateRange] = useDateRange(websiteId);
|
const [dateRange] = useDateRange(websiteId);
|
||||||
const { startDate, endDate } = dateRange;
|
const { startDate, endDate } = dateRange;
|
||||||
const { get, useQuery } = useApi();
|
const { get, useQuery } = useApi();
|
||||||
const { data, error, isLoading } = useQuery(
|
const { data, error, isLoading } = useQuery(
|
||||||
['event-data:events', { websiteId, startDate, endDate, eventName }],
|
['event-data:events', { websiteId, startDate, endDate, event }],
|
||||||
() =>
|
() =>
|
||||||
get('/event-data/events', {
|
get('/event-data/events', {
|
||||||
websiteId,
|
websiteId,
|
||||||
startAt: +startDate,
|
startAt: +startDate,
|
||||||
endAt: +endDate,
|
endAt: +endDate,
|
||||||
eventName,
|
event,
|
||||||
}),
|
}),
|
||||||
{ enabled: !!(websiteId && startDate && endDate) },
|
{ enabled: !!(websiteId && startDate && endDate) },
|
||||||
);
|
);
|
||||||
|
@ -126,13 +126,8 @@ export interface WebsiteEventMetric {
|
|||||||
y: number;
|
y: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WebsiteEventDataStats {
|
export interface WebsiteEventData {
|
||||||
fieldName: string;
|
eventName?: string;
|
||||||
dataType: number;
|
|
||||||
total: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface WebsiteEventDataFields {
|
|
||||||
fieldName: string;
|
fieldName: string;
|
||||||
dataType: number;
|
dataType: number;
|
||||||
fieldValue?: string;
|
fieldValue?: string;
|
||||||
|
@ -5,16 +5,17 @@ import { NextApiResponse } from 'next';
|
|||||||
import { ok, methodNotAllowed, unauthorized } from 'next-basics';
|
import { ok, methodNotAllowed, unauthorized } from 'next-basics';
|
||||||
import { getEventDataEvents } from 'queries';
|
import { getEventDataEvents } from 'queries';
|
||||||
|
|
||||||
export interface EventDataFieldsRequestBody {
|
export interface EventDataEventsRequestQuery {
|
||||||
websiteId: string;
|
websiteId: string;
|
||||||
dateRange: {
|
dateRange: {
|
||||||
startDate: string;
|
startDate: string;
|
||||||
endDate: string;
|
endDate: string;
|
||||||
};
|
};
|
||||||
|
event?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async (
|
export default async (
|
||||||
req: NextApiRequestQueryBody<any, EventDataFieldsRequestBody>,
|
req: NextApiRequestQueryBody<EventDataEventsRequestQuery>,
|
||||||
res: NextApiResponse<any>,
|
res: NextApiResponse<any>,
|
||||||
) => {
|
) => {
|
||||||
await useCors(req, res);
|
await useCors(req, res);
|
||||||
|
@ -5,7 +5,7 @@ import { NextApiResponse } from 'next';
|
|||||||
import { ok, methodNotAllowed, unauthorized } from 'next-basics';
|
import { ok, methodNotAllowed, unauthorized } from 'next-basics';
|
||||||
import { getEventDataFields } from 'queries';
|
import { getEventDataFields } from 'queries';
|
||||||
|
|
||||||
export interface EventDataFieldsRequestBody {
|
export interface EventDataFieldsRequestQuery {
|
||||||
websiteId: string;
|
websiteId: string;
|
||||||
dateRange: {
|
dateRange: {
|
||||||
startDate: string;
|
startDate: string;
|
||||||
@ -15,7 +15,7 @@ export interface EventDataFieldsRequestBody {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default async (
|
export default async (
|
||||||
req: NextApiRequestQueryBody<any, EventDataFieldsRequestBody>,
|
req: NextApiRequestQueryBody<EventDataFieldsRequestQuery>,
|
||||||
res: NextApiResponse<any>,
|
res: NextApiResponse<any>,
|
||||||
) => {
|
) => {
|
||||||
await useCors(req, res);
|
await useCors(req, res);
|
||||||
|
@ -5,7 +5,7 @@ import { NextApiResponse } from 'next';
|
|||||||
import { ok, methodNotAllowed, unauthorized } from 'next-basics';
|
import { ok, methodNotAllowed, unauthorized } from 'next-basics';
|
||||||
import { getEventDataFields } from 'queries';
|
import { getEventDataFields } from 'queries';
|
||||||
|
|
||||||
export interface EventDataRequestBody {
|
export interface EventDataStatsRequestQuery {
|
||||||
websiteId: string;
|
websiteId: string;
|
||||||
dateRange: {
|
dateRange: {
|
||||||
startDate: string;
|
startDate: string;
|
||||||
@ -15,7 +15,7 @@ export interface EventDataRequestBody {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default async (
|
export default async (
|
||||||
req: NextApiRequestQueryBody<any, EventDataRequestBody>,
|
req: NextApiRequestQueryBody<EventDataStatsRequestQuery>,
|
||||||
res: NextApiResponse<any>,
|
res: NextApiResponse<any>,
|
||||||
) => {
|
) => {
|
||||||
await useCors(req, res);
|
await useCors(req, res);
|
||||||
@ -32,18 +32,18 @@ export default async (
|
|||||||
const endDate = new Date(+endAt);
|
const endDate = new Date(+endAt);
|
||||||
|
|
||||||
const results = await getEventDataFields(websiteId, { startDate, endDate });
|
const results = await getEventDataFields(websiteId, { startDate, endDate });
|
||||||
const events = new Set();
|
const fields = new Set();
|
||||||
|
|
||||||
const data = results.reduce(
|
const data = results.reduce(
|
||||||
(obj, row) => {
|
(obj, row) => {
|
||||||
events.add(row.fieldName);
|
fields.add(row.fieldName);
|
||||||
obj.records += Number(row.total);
|
obj.records += Number(row.total);
|
||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
{ fields: results.length, records: 0 },
|
{ events: results.length, records: 0 },
|
||||||
);
|
);
|
||||||
|
|
||||||
return ok(res, { ...data, events: events.size });
|
return ok(res, { ...data, fields: fields.size });
|
||||||
}
|
}
|
||||||
|
|
||||||
return methodNotAllowed(res);
|
return methodNotAllowed(res);
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import prisma from 'lib/prisma';
|
import prisma from 'lib/prisma';
|
||||||
import clickhouse from 'lib/clickhouse';
|
import clickhouse from 'lib/clickhouse';
|
||||||
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
||||||
import { QueryFilters, WebsiteEventDataFields } from 'lib/types';
|
import { QueryFilters, WebsiteEventData } from 'lib/types';
|
||||||
|
|
||||||
export async function getEventDataEvents(
|
export async function getEventDataEvents(
|
||||||
...args: [websiteId: string, filters: QueryFilters]
|
...args: [websiteId: string, filters: QueryFilters]
|
||||||
): Promise<WebsiteEventDataFields[]> {
|
): Promise<WebsiteEventData[]> {
|
||||||
return runQuery({
|
return runQuery({
|
||||||
[PRISMA]: () => relationalQuery(...args),
|
[PRISMA]: () => relationalQuery(...args),
|
||||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||||
@ -24,7 +24,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
|||||||
website_event.event_name as "eventName",
|
website_event.event_name as "eventName",
|
||||||
event_data.event_key as "fieldName",
|
event_data.event_key as "fieldName",
|
||||||
event_data.data_type as "dataType",
|
event_data.data_type as "dataType",
|
||||||
event_data.string_value as "value",
|
event_data.string_value as "fieldValue",
|
||||||
count(*) as "total"
|
count(*) as "total"
|
||||||
from event_data
|
from event_data
|
||||||
inner join website_event
|
inner join website_event
|
||||||
@ -71,7 +71,7 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters) {
|
|||||||
event_name as eventName,
|
event_name as eventName,
|
||||||
event_key as fieldName,
|
event_key as fieldName,
|
||||||
data_type as dataType,
|
data_type as dataType,
|
||||||
string_value as value,
|
string_value as fieldValue,
|
||||||
count(*) as total
|
count(*) as total
|
||||||
from event_data
|
from event_data
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import prisma from 'lib/prisma';
|
import prisma from 'lib/prisma';
|
||||||
import clickhouse from 'lib/clickhouse';
|
import clickhouse from 'lib/clickhouse';
|
||||||
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
||||||
import { QueryFilters, WebsiteEventDataFields } from 'lib/types';
|
import { QueryFilters, WebsiteEventData } from 'lib/types';
|
||||||
|
|
||||||
export async function getEventDataFields(
|
export async function getEventDataFields(
|
||||||
...args: [websiteId: string, filters: QueryFilters & { field?: string }]
|
...args: [websiteId: string, filters: QueryFilters & { field?: string }]
|
||||||
): Promise<WebsiteEventDataFields[]> {
|
): Promise<WebsiteEventData[]> {
|
||||||
return runQuery({
|
return runQuery({
|
||||||
[PRISMA]: () => relationalQuery(...args),
|
[PRISMA]: () => relationalQuery(...args),
|
||||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||||
|
Loading…
Reference in New Issue
Block a user