mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Updated pixel/link endpoints. Added name to rawQuery.
This commit is contained in:
parent
b9fbbc6453
commit
8a977b0164
18 changed files with 913 additions and 810 deletions
|
|
@ -4,6 +4,8 @@ import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
|||
import prisma from '@/lib/prisma';
|
||||
import { QueryFilters } from '@/lib/types';
|
||||
|
||||
const FUNCTION_NAME = 'getEventMetrics';
|
||||
|
||||
export interface EventMetricParameters {
|
||||
type: string;
|
||||
limit?: string;
|
||||
|
|
@ -58,6 +60,7 @@ async function relationalQuery(
|
|||
offset ${offset}
|
||||
`,
|
||||
{ ...queryParams, ...parameters },
|
||||
FUNCTION_NAME,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -89,5 +92,6 @@ async function clickhouseQuery(
|
|||
offset ${offset}
|
||||
`,
|
||||
{ ...queryParams, ...parameters },
|
||||
FUNCTION_NAME,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { uuid } from '@/lib/crypto';
|
||||
import { EVENT_NAME_LENGTH, URL_LENGTH, EVENT_TYPE, PAGE_TITLE_LENGTH } from '@/lib/constants';
|
||||
import { EVENT_NAME_LENGTH, URL_LENGTH, PAGE_TITLE_LENGTH } from '@/lib/constants';
|
||||
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
||||
import clickhouse from '@/lib/clickhouse';
|
||||
import kafka from '@/lib/kafka';
|
||||
|
|
@ -66,10 +66,9 @@ async function relationalQuery({
|
|||
websiteId,
|
||||
sessionId,
|
||||
visitId,
|
||||
createdAt,
|
||||
eventType,
|
||||
createdAt,
|
||||
pageTitle,
|
||||
tag,
|
||||
hostname,
|
||||
urlPath,
|
||||
urlQuery,
|
||||
|
|
@ -78,6 +77,7 @@ async function relationalQuery({
|
|||
referrerDomain,
|
||||
eventName,
|
||||
eventData,
|
||||
tag,
|
||||
utmSource,
|
||||
utmMedium,
|
||||
utmCampaign,
|
||||
|
|
@ -154,9 +154,16 @@ async function clickhouseQuery({
|
|||
websiteId,
|
||||
sessionId,
|
||||
visitId,
|
||||
distinctId,
|
||||
eventType,
|
||||
createdAt,
|
||||
pageTitle,
|
||||
hostname,
|
||||
urlPath,
|
||||
urlQuery,
|
||||
referrerPath,
|
||||
referrerQuery,
|
||||
referrerDomain,
|
||||
distinctId,
|
||||
browser,
|
||||
os,
|
||||
device,
|
||||
|
|
@ -165,15 +172,9 @@ async function clickhouseQuery({
|
|||
country,
|
||||
region,
|
||||
city,
|
||||
tag,
|
||||
hostname,
|
||||
urlPath,
|
||||
urlQuery,
|
||||
referrerPath,
|
||||
referrerQuery,
|
||||
referrerDomain,
|
||||
eventName,
|
||||
eventData,
|
||||
tag,
|
||||
utmSource,
|
||||
utmMedium,
|
||||
utmCampaign,
|
||||
|
|
@ -215,7 +216,7 @@ async function clickhouseQuery({
|
|||
ttclid: ttclid,
|
||||
li_fat_id: lifatid,
|
||||
twclid: twclid,
|
||||
event_type: eventName ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
|
||||
event_type: eventType,
|
||||
event_name: eventName ? eventName?.substring(0, EVENT_NAME_LENGTH) : null,
|
||||
tag: tag,
|
||||
distinct_id: distinctId,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ import prisma from '@/lib/prisma';
|
|||
import clickhouse from '@/lib/clickhouse';
|
||||
import { runQuery, CLICKHOUSE, PRISMA } from '@/lib/db';
|
||||
|
||||
const FUNCTION_NAME = 'getActiveVisitors';
|
||||
|
||||
export async function getActiveVisitors(...args: [websiteId: string]) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
|
|
@ -22,6 +24,7 @@ async function relationalQuery(websiteId: string) {
|
|||
and created_at >= {{startDate}}
|
||||
`,
|
||||
{ websiteId, startDate },
|
||||
FUNCTION_NAME,
|
||||
);
|
||||
|
||||
return result?.[0] ?? null;
|
||||
|
|
@ -40,6 +43,7 @@ async function clickhouseQuery(websiteId: string): Promise<{ x: number }> {
|
|||
and created_at >= {startDate:DateTime64}
|
||||
`,
|
||||
{ websiteId, startDate },
|
||||
FUNCTION_NAME,
|
||||
);
|
||||
|
||||
return result[0] ?? null;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
|||
import prisma from '@/lib/prisma';
|
||||
import { QueryFilters } from '@/lib/types';
|
||||
|
||||
const FUNCTION_NAME = 'getChannelExpandedMetrics';
|
||||
|
||||
export interface ChannelExpandedMetricsParameters {
|
||||
limit?: number | string;
|
||||
offset?: number | string;
|
||||
|
|
@ -79,6 +81,7 @@ async function relationalQuery(
|
|||
order by y desc;
|
||||
`,
|
||||
queryParams,
|
||||
FUNCTION_NAME,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -145,6 +148,7 @@ async function clickhouseQuery(
|
|||
order by visitors desc, visits desc;
|
||||
`,
|
||||
queryParams,
|
||||
FUNCTION_NAME,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
|||
import prisma from '@/lib/prisma';
|
||||
import { QueryFilters } from '@/lib/types';
|
||||
|
||||
const FUNCTION_NAME = 'getChannelMetrics';
|
||||
|
||||
export async function getChannelMetrics(...args: [websiteId: string, filters?: QueryFilters]) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
|
|
@ -60,6 +62,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
|||
order by y desc;
|
||||
`,
|
||||
queryParams,
|
||||
FUNCTION_NAME,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -117,7 +120,7 @@ async function clickhouseQuery(
|
|||
order by y desc;
|
||||
`;
|
||||
|
||||
return rawQuery(sql, queryParams);
|
||||
return rawQuery(sql, queryParams, FUNCTION_NAME);
|
||||
}
|
||||
|
||||
function toClickHouseStringArray(arr: string[]): string {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ import clickhouse from '@/lib/clickhouse';
|
|||
import { runQuery, CLICKHOUSE, PRISMA } from '@/lib/db';
|
||||
import { QueryFilters } from '@/lib/types';
|
||||
|
||||
const FUNCTION_NAME = 'getRealtimeActivity';
|
||||
|
||||
export async function getRealtimeActivity(...args: [websiteId: string, filters: QueryFilters]) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
|
|
@ -40,6 +42,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
|||
limit 100
|
||||
`,
|
||||
queryParams,
|
||||
FUNCTION_NAME,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -71,5 +74,6 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters): Promis
|
|||
limit 100
|
||||
`,
|
||||
queryParams,
|
||||
FUNCTION_NAME,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ import clickhouse from '@/lib/clickhouse';
|
|||
import { runQuery, CLICKHOUSE, PRISMA } from '@/lib/db';
|
||||
import { QueryFilters } from '@/lib/types';
|
||||
|
||||
const FUNCTION_NAME = 'getValues';
|
||||
|
||||
export async function getValues(
|
||||
...args: [websiteId: string, column: string, filters: QueryFilters]
|
||||
) {
|
||||
|
|
@ -64,6 +66,7 @@ async function relationalQuery(websiteId: string, column: string, filters: Query
|
|||
search: `%${search}%`,
|
||||
...params,
|
||||
},
|
||||
FUNCTION_NAME,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -120,5 +123,6 @@ async function clickhouseQuery(websiteId: string, column: string, filters: Query
|
|||
search,
|
||||
...params,
|
||||
},
|
||||
FUNCTION_NAME,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
import clickhouse from '@/lib/clickhouse';
|
||||
import { EVENT_TYPE, FILTER_COLUMNS, GROUPED_DOMAINS, SESSION_COLUMNS } from '@/lib/constants';
|
||||
import { FILTER_COLUMNS, GROUPED_DOMAINS, SESSION_COLUMNS } from '@/lib/constants';
|
||||
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
||||
import prisma from '@/lib/prisma';
|
||||
import { QueryFilters } from '@/lib/types';
|
||||
|
||||
const FUNCTION_NAME = 'getPageviewExpandedMetrics';
|
||||
|
||||
export interface PageviewExpandedMetricsParameters {
|
||||
type: string;
|
||||
limit?: number | string;
|
||||
|
|
@ -40,7 +42,6 @@ async function relationalQuery(
|
|||
{
|
||||
...filters,
|
||||
websiteId,
|
||||
eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
|
||||
},
|
||||
{ joinSession: SESSION_COLUMNS.includes(type) },
|
||||
);
|
||||
|
|
@ -89,6 +90,7 @@ async function relationalQuery(
|
|||
offset ${offset}
|
||||
`,
|
||||
queryParams,
|
||||
FUNCTION_NAME,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -103,7 +105,6 @@ async function clickhouseQuery(
|
|||
const { filterQuery, cohortQuery, queryParams } = parseFilters({
|
||||
...filters,
|
||||
websiteId,
|
||||
eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
|
||||
});
|
||||
|
||||
let excludeDomain = '';
|
||||
|
|
@ -164,6 +165,7 @@ async function clickhouseQuery(
|
|||
offset ${offset}
|
||||
`,
|
||||
{ ...queryParams, ...parameters },
|
||||
FUNCTION_NAME,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
import clickhouse from '@/lib/clickhouse';
|
||||
import { EVENT_COLUMNS, EVENT_TYPE, FILTER_COLUMNS, SESSION_COLUMNS } from '@/lib/constants';
|
||||
import { EVENT_COLUMNS, FILTER_COLUMNS, SESSION_COLUMNS } from '@/lib/constants';
|
||||
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
||||
import prisma from '@/lib/prisma';
|
||||
import { QueryFilters } from '@/lib/types';
|
||||
|
||||
const FUNCTION_NAME = 'getPageviewMetrics';
|
||||
|
||||
export interface PageviewMetricsParameters {
|
||||
type: string;
|
||||
limit?: number | string;
|
||||
|
|
@ -36,7 +38,6 @@ async function relationalQuery(
|
|||
{
|
||||
...filters,
|
||||
websiteId,
|
||||
eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
|
||||
},
|
||||
{ joinSession: SESSION_COLUMNS.includes(type) },
|
||||
);
|
||||
|
|
@ -86,6 +87,7 @@ async function relationalQuery(
|
|||
offset ${offset}
|
||||
`,
|
||||
{ ...queryParams, ...parameters },
|
||||
FUNCTION_NAME,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -100,7 +102,6 @@ async function clickhouseQuery(
|
|||
const { filterQuery, cohortQuery, queryParams } = parseFilters({
|
||||
...filters,
|
||||
websiteId,
|
||||
eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
|
||||
});
|
||||
|
||||
let sql = '';
|
||||
|
|
@ -183,5 +184,5 @@ async function clickhouseQuery(
|
|||
`;
|
||||
}
|
||||
|
||||
return rawQuery(sql, { ...queryParams, ...parameters });
|
||||
return rawQuery(sql, { ...queryParams, ...parameters }, FUNCTION_NAME);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
import clickhouse from '@/lib/clickhouse';
|
||||
import { EVENT_COLUMNS, EVENT_TYPE, FILTER_COLUMNS, SESSION_COLUMNS } from '@/lib/constants';
|
||||
import { EVENT_COLUMNS, FILTER_COLUMNS, SESSION_COLUMNS } from '@/lib/constants';
|
||||
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
||||
import prisma from '@/lib/prisma';
|
||||
import { QueryFilters } from '@/lib/types';
|
||||
|
||||
const FUNCTION_NAME = 'getSessionMetrics';
|
||||
|
||||
export interface SessionMetricsParameters {
|
||||
type: string;
|
||||
limit?: number | string;
|
||||
|
|
@ -31,7 +33,6 @@ async function relationalQuery(
|
|||
{
|
||||
...filters,
|
||||
websiteId,
|
||||
eventType: EVENT_TYPE.pageView,
|
||||
},
|
||||
{
|
||||
joinSession: SESSION_COLUMNS.includes(type),
|
||||
|
|
@ -54,6 +55,7 @@ async function relationalQuery(
|
|||
${joinSessionQuery}
|
||||
where website_event.website_id = {{websiteId::uuid}}
|
||||
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||
and event_type != 2
|
||||
${filterQuery}
|
||||
group by 1
|
||||
${includeCountry ? ', 3' : ''}
|
||||
|
|
@ -62,6 +64,7 @@ async function relationalQuery(
|
|||
offset ${offset}
|
||||
`,
|
||||
{ ...queryParams, ...parameters },
|
||||
FUNCTION_NAME,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +79,6 @@ async function clickhouseQuery(
|
|||
const { filterQuery, cohortQuery, queryParams } = parseFilters({
|
||||
...filters,
|
||||
websiteId,
|
||||
eventType: EVENT_TYPE.pageView,
|
||||
});
|
||||
const includeCountry = column === 'city' || column === 'region';
|
||||
|
||||
|
|
@ -96,6 +98,7 @@ async function clickhouseQuery(
|
|||
${cohortQuery}
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
and event_type != 2
|
||||
${filterQuery}
|
||||
group by x
|
||||
${includeCountry ? ', country' : ''}
|
||||
|
|
@ -113,6 +116,7 @@ async function clickhouseQuery(
|
|||
${cohortQuery}
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
and event_type != 2
|
||||
${filterQuery}
|
||||
group by x
|
||||
${includeCountry ? ', country' : ''}
|
||||
|
|
@ -122,5 +126,5 @@ async function clickhouseQuery(
|
|||
`;
|
||||
}
|
||||
|
||||
return rawQuery(sql, { ...queryParams, ...parameters });
|
||||
return rawQuery(sql, { ...queryParams, ...parameters }, FUNCTION_NAME);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue