mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
fix event type queries for pixels/links. remove hardcoded event types
This commit is contained in:
parent
f86c21b25b
commit
1809959b99
14 changed files with 42 additions and 51 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
import { PixelPage } from './PixelPage';
|
import { PixelPage } from './PixelPage';
|
||||||
import { Metadata } from 'next';
|
import { Metadata } from 'next';
|
||||||
|
|
||||||
export default function ({ params }: { params: { pixelId: string } }) {
|
export default async function ({ params }: { params: { pixelId: string } }) {
|
||||||
const { pixelId } = params;
|
const { pixelId } = await params;
|
||||||
|
|
||||||
return <PixelPage pixelId={pixelId} />;
|
return <PixelPage pixelId={pixelId} />;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import { canViewWebsite } from '@/permissions';
|
import { EVENT_COLUMNS, EVENT_TYPE, SESSION_COLUMNS } from '@/lib/constants';
|
||||||
import { EVENT_COLUMNS, EVENT_TYPE, FILTER_COLUMNS, SESSION_COLUMNS } from '@/lib/constants';
|
|
||||||
import { getQueryFilters, parseRequest } from '@/lib/request';
|
import { getQueryFilters, parseRequest } from '@/lib/request';
|
||||||
import { badRequest, json, unauthorized } from '@/lib/response';
|
import { badRequest, json, unauthorized } from '@/lib/response';
|
||||||
import { dateRangeParams, filterParams, searchParams } from '@/lib/schema';
|
import { dateRangeParams, filterParams, searchParams } from '@/lib/schema';
|
||||||
|
import { canViewWebsite } from '@/permissions';
|
||||||
import {
|
import {
|
||||||
getChannelExpandedMetrics,
|
getChannelExpandedMetrics,
|
||||||
getEventExpandedMetrics,
|
getEventExpandedMetrics,
|
||||||
|
|
@ -50,13 +50,8 @@ export async function GET(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EVENT_COLUMNS.includes(type)) {
|
if (EVENT_COLUMNS.includes(type)) {
|
||||||
const column = FILTER_COLUMNS[type] || type;
|
|
||||||
|
|
||||||
if (column === 'event_name') {
|
|
||||||
filters.eventType = EVENT_TYPE.customEvent;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type === 'event') {
|
if (type === 'event') {
|
||||||
|
filters.eventType = EVENT_TYPE.customEvent;
|
||||||
return json(await getEventExpandedMetrics(websiteId, { type, limit, offset }, filters));
|
return json(await getEventExpandedMetrics(websiteId, { type, limit, offset }, filters));
|
||||||
} else {
|
} else {
|
||||||
return json(await getPageviewExpandedMetrics(websiteId, { type, limit, offset }, filters));
|
return json(await getPageviewExpandedMetrics(websiteId, { type, limit, offset }, filters));
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
import { canViewWebsite } from '@/permissions';
|
import { EVENT_COLUMNS, EVENT_TYPE, SESSION_COLUMNS } from '@/lib/constants';
|
||||||
import { EVENT_COLUMNS, EVENT_TYPE, FILTER_COLUMNS, SESSION_COLUMNS } from '@/lib/constants';
|
|
||||||
import { getQueryFilters, parseRequest } from '@/lib/request';
|
import { getQueryFilters, parseRequest } from '@/lib/request';
|
||||||
import { badRequest, json, unauthorized } from '@/lib/response';
|
import { badRequest, json, unauthorized } from '@/lib/response';
|
||||||
|
import { dateRangeParams, filterParams, searchParams } from '@/lib/schema';
|
||||||
|
import { canViewWebsite } from '@/permissions';
|
||||||
import {
|
import {
|
||||||
getChannelMetrics,
|
getChannelMetrics,
|
||||||
getEventMetrics,
|
getEventMetrics,
|
||||||
|
|
@ -9,7 +10,6 @@ import {
|
||||||
getSessionMetrics,
|
getSessionMetrics,
|
||||||
} from '@/queries/sql';
|
} from '@/queries/sql';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { dateRangeParams, filterParams, searchParams } from '@/lib/schema';
|
|
||||||
|
|
||||||
export async function GET(
|
export async function GET(
|
||||||
request: Request,
|
request: Request,
|
||||||
|
|
@ -50,13 +50,8 @@ export async function GET(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EVENT_COLUMNS.includes(type)) {
|
if (EVENT_COLUMNS.includes(type)) {
|
||||||
const column = FILTER_COLUMNS[type] || type;
|
|
||||||
|
|
||||||
if (column === 'event_name') {
|
|
||||||
filters.eventType = EVENT_TYPE.customEvent;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type === 'event') {
|
if (type === 'event') {
|
||||||
|
filters.eventType = EVENT_TYPE.customEvent;
|
||||||
return json(await getEventMetrics(websiteId, { type, limit, offset }, filters));
|
return json(await getEventMetrics(websiteId, { type, limit, offset }, filters));
|
||||||
} else {
|
} else {
|
||||||
return json(await getPageviewMetrics(websiteId, { type, limit, offset }, filters));
|
return json(await getPageviewMetrics(websiteId, { type, limit, offset }, filters));
|
||||||
|
|
|
||||||
|
|
@ -157,12 +157,7 @@ export function parseDateRange(value: string, locale = 'en-US'): DateRange {
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const dateLocale = getDateLocale(locale);
|
const dateLocale = getDateLocale(locale);
|
||||||
const { unit } = parseDateValue(value);
|
const { num = 1, unit } = parseDateValue(value);
|
||||||
let { num = 1 } = parseDateValue(value);
|
|
||||||
|
|
||||||
if (value === '7day') {
|
|
||||||
num--;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (unit) {
|
switch (unit) {
|
||||||
case 'hour':
|
case 'hour':
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@ async function clickhouseQuery(
|
||||||
const { filterQuery, cohortQuery, queryParams } = parseFilters({
|
const { filterQuery, cohortQuery, queryParams } = parseFilters({
|
||||||
...filters,
|
...filters,
|
||||||
websiteId,
|
websiteId,
|
||||||
|
eventType: EVENT_TYPE.customEvent,
|
||||||
});
|
});
|
||||||
|
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import clickhouse from '@/lib/clickhouse';
|
import clickhouse from '@/lib/clickhouse';
|
||||||
import {
|
import {
|
||||||
EMAIL_DOMAINS,
|
EMAIL_DOMAINS,
|
||||||
EVENT_TYPE,
|
|
||||||
PAID_AD_PARAMS,
|
PAID_AD_PARAMS,
|
||||||
SEARCH_DOMAINS,
|
SEARCH_DOMAINS,
|
||||||
SHOPPING_DOMAINS,
|
SHOPPING_DOMAINS,
|
||||||
|
|
@ -45,7 +44,6 @@ async function relationalQuery(
|
||||||
const { queryParams, filterQuery, joinSessionQuery, cohortQuery, dateQuery } = parseFilters({
|
const { queryParams, filterQuery, joinSessionQuery, cohortQuery, dateQuery } = parseFilters({
|
||||||
...filters,
|
...filters,
|
||||||
websiteId,
|
websiteId,
|
||||||
eventType: EVENT_TYPE.pageView,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
|
|
@ -68,7 +66,8 @@ async function relationalQuery(
|
||||||
from website_event
|
from website_event
|
||||||
${cohortQuery}
|
${cohortQuery}
|
||||||
${joinSessionQuery}
|
${joinSessionQuery}
|
||||||
where website_id = {{websiteId::uuid}}
|
where website_event.website_id = {{websiteId::uuid}}
|
||||||
|
and website_event.event_type != 2
|
||||||
${dateQuery}
|
${dateQuery}
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by 1, 2
|
group by 1, 2
|
||||||
|
|
@ -93,7 +92,6 @@ async function clickhouseQuery(
|
||||||
const { queryParams, filterQuery, cohortQuery } = parseFilters({
|
const { queryParams, filterQuery, cohortQuery } = parseFilters({
|
||||||
...filters,
|
...filters,
|
||||||
websiteId,
|
websiteId,
|
||||||
eventType: EVENT_TYPE.pageView,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
|
|
@ -140,6 +138,7 @@ async function clickhouseQuery(
|
||||||
${cohortQuery}
|
${cohortQuery}
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
|
and event_type != 2
|
||||||
and name != ''
|
and name != ''
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by prefix, name, session_id, visit_id
|
group by prefix, name, session_id, visit_id
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import clickhouse from '@/lib/clickhouse';
|
import clickhouse from '@/lib/clickhouse';
|
||||||
import {
|
import {
|
||||||
EMAIL_DOMAINS,
|
EMAIL_DOMAINS,
|
||||||
EVENT_TYPE,
|
|
||||||
PAID_AD_PARAMS,
|
PAID_AD_PARAMS,
|
||||||
SEARCH_DOMAINS,
|
SEARCH_DOMAINS,
|
||||||
SHOPPING_DOMAINS,
|
SHOPPING_DOMAINS,
|
||||||
|
|
@ -26,7 +25,6 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
||||||
const { queryParams, filterQuery, joinSessionQuery, cohortQuery, dateQuery } = parseFilters({
|
const { queryParams, filterQuery, joinSessionQuery, cohortQuery, dateQuery } = parseFilters({
|
||||||
...filters,
|
...filters,
|
||||||
websiteId,
|
websiteId,
|
||||||
eventType: EVENT_TYPE.pageView,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
|
|
@ -49,7 +47,8 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
||||||
from website_event
|
from website_event
|
||||||
${cohortQuery}
|
${cohortQuery}
|
||||||
${joinSessionQuery}
|
${joinSessionQuery}
|
||||||
where website_id = {{websiteId::uuid}}
|
where website_event.website_id = {{websiteId::uuid}}
|
||||||
|
and website_event.event_type != 2
|
||||||
${dateQuery}
|
${dateQuery}
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by 1, 2
|
group by 1, 2
|
||||||
|
|
@ -74,7 +73,6 @@ async function clickhouseQuery(
|
||||||
const { queryParams, filterQuery, cohortQuery, dateQuery } = parseFilters({
|
const { queryParams, filterQuery, cohortQuery, dateQuery } = parseFilters({
|
||||||
...filters,
|
...filters,
|
||||||
websiteId,
|
websiteId,
|
||||||
eventType: EVENT_TYPE.pageView,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const sql = `
|
const sql = `
|
||||||
|
|
@ -108,6 +106,7 @@ async function clickhouseQuery(
|
||||||
from website_event
|
from website_event
|
||||||
${cohortQuery}
|
${cohortQuery}
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
|
and event_type != 2
|
||||||
${dateQuery}
|
${dateQuery}
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by 1, 2
|
group by 1, 2
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
import clickhouse from '@/lib/clickhouse';
|
import clickhouse from '@/lib/clickhouse';
|
||||||
import { EVENT_TYPE } from '@/lib/constants';
|
import { EVENT_COLUMNS } from '@/lib/constants';
|
||||||
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
||||||
import prisma from '@/lib/prisma';
|
import prisma from '@/lib/prisma';
|
||||||
import { QueryFilters } from '@/lib/types';
|
import { QueryFilters } from '@/lib/types';
|
||||||
import { EVENT_COLUMNS } from '@/lib/constants';
|
|
||||||
|
|
||||||
export interface WebsiteStatsData {
|
export interface WebsiteStatsData {
|
||||||
pageviews: number;
|
pageviews: number;
|
||||||
|
|
@ -30,7 +29,6 @@ async function relationalQuery(
|
||||||
const { filterQuery, joinSessionQuery, cohortQuery, queryParams } = parseFilters({
|
const { filterQuery, joinSessionQuery, cohortQuery, queryParams } = parseFilters({
|
||||||
...filters,
|
...filters,
|
||||||
websiteId,
|
websiteId,
|
||||||
eventType: EVENT_TYPE.pageView,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
|
|
@ -53,6 +51,7 @@ async function relationalQuery(
|
||||||
${joinSessionQuery}
|
${joinSessionQuery}
|
||||||
where website_event.website_id = {{websiteId::uuid}}
|
where website_event.website_id = {{websiteId::uuid}}
|
||||||
and website_event.created_at between {{startDate}} and {{endDate}}
|
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||||
|
and website_event.event_type != 2
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by 1, 2
|
group by 1, 2
|
||||||
) as t
|
) as t
|
||||||
|
|
@ -69,7 +68,6 @@ async function clickhouseQuery(
|
||||||
const { filterQuery, cohortQuery, queryParams } = parseFilters({
|
const { filterQuery, cohortQuery, queryParams } = parseFilters({
|
||||||
...filters,
|
...filters,
|
||||||
websiteId,
|
websiteId,
|
||||||
eventType: EVENT_TYPE.pageView,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let sql = '';
|
let sql = '';
|
||||||
|
|
@ -93,6 +91,7 @@ async function clickhouseQuery(
|
||||||
${cohortQuery}
|
${cohortQuery}
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
|
and event_type != 2
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by session_id, visit_id
|
group by session_id, visit_id
|
||||||
) as t;
|
) as t;
|
||||||
|
|
@ -115,6 +114,7 @@ async function clickhouseQuery(
|
||||||
${cohortQuery}
|
${cohortQuery}
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
|
and event_type != 2
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by session_id, visit_id
|
group by session_id, visit_id
|
||||||
) as t;
|
) as t;
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ async function relationalQuery(
|
||||||
from website_event
|
from website_event
|
||||||
where website_event.website_id = {{websiteId::uuid}}
|
where website_event.website_id = {{websiteId::uuid}}
|
||||||
and website_event.created_at between {{startDate}} and {{endDate}}
|
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||||
and event_type = {{eventType}}
|
and website_event.event_type != 2
|
||||||
group by visit_id
|
group by visit_id
|
||||||
) x
|
) x
|
||||||
on x.visit_id = website_event.visit_id
|
on x.visit_id = website_event.visit_id
|
||||||
|
|
@ -82,6 +82,7 @@ async function relationalQuery(
|
||||||
${entryExitQuery}
|
${entryExitQuery}
|
||||||
where website_event.website_id = {{websiteId::uuid}}
|
where website_event.website_id = {{websiteId::uuid}}
|
||||||
and website_event.created_at between {{startDate}} and {{endDate}}
|
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||||
|
and website_event.event_type != 2
|
||||||
${excludeDomain}
|
${excludeDomain}
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by 1
|
group by 1
|
||||||
|
|
@ -127,7 +128,7 @@ async function clickhouseQuery(
|
||||||
from website_event
|
from website_event
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
and event_type = {eventType:UInt32}
|
and event_type != 2
|
||||||
group by visit_id) x
|
group by visit_id) x
|
||||||
ON x.visit_id = website_event.visit_id`;
|
ON x.visit_id = website_event.visit_id`;
|
||||||
}
|
}
|
||||||
|
|
@ -154,6 +155,7 @@ async function clickhouseQuery(
|
||||||
${entryExitQuery}
|
${entryExitQuery}
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
|
and event_type != 2
|
||||||
and name != ''
|
and name != ''
|
||||||
${excludeDomain}
|
${excludeDomain}
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ async function relationalQuery(
|
||||||
from website_event
|
from website_event
|
||||||
where website_event.website_id = {{websiteId::uuid}}
|
where website_event.website_id = {{websiteId::uuid}}
|
||||||
and website_event.created_at between {{startDate}} and {{endDate}}
|
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||||
and event_type = {{eventType}}
|
and website_event.event_type != 2
|
||||||
order by visit_id, created_at ${order}
|
order by visit_id, created_at ${order}
|
||||||
) x
|
) x
|
||||||
on x.visit_id = website_event.visit_id
|
on x.visit_id = website_event.visit_id
|
||||||
|
|
@ -79,6 +79,7 @@ async function relationalQuery(
|
||||||
${entryExitQuery}
|
${entryExitQuery}
|
||||||
where website_event.website_id = {{websiteId::uuid}}
|
where website_event.website_id = {{websiteId::uuid}}
|
||||||
and website_event.created_at between {{startDate}} and {{endDate}}
|
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||||
|
and website_event.event_type != 2
|
||||||
${excludeDomain}
|
${excludeDomain}
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by 1
|
group by 1
|
||||||
|
|
@ -124,7 +125,7 @@ async function clickhouseQuery(
|
||||||
from website_event
|
from website_event
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
and event_type = {eventType:UInt32}
|
and event_type != 2
|
||||||
group by visit_id) x
|
group by visit_id) x
|
||||||
ON x.visit_id = website_event.visit_id`;
|
ON x.visit_id = website_event.visit_id`;
|
||||||
}
|
}
|
||||||
|
|
@ -137,6 +138,7 @@ async function clickhouseQuery(
|
||||||
${entryExitQuery}
|
${entryExitQuery}
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
|
and event_type != 2
|
||||||
${excludeDomain}
|
${excludeDomain}
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by x
|
group by x
|
||||||
|
|
@ -174,6 +176,7 @@ async function clickhouseQuery(
|
||||||
${cohortQuery}
|
${cohortQuery}
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
|
and event_type != 2
|
||||||
${excludeDomain}
|
${excludeDomain}
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
${groupByQuery}) as g
|
${groupByQuery}) as g
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import clickhouse from '@/lib/clickhouse';
|
import clickhouse from '@/lib/clickhouse';
|
||||||
|
import { EVENT_COLUMNS } from '@/lib/constants';
|
||||||
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
||||||
import prisma from '@/lib/prisma';
|
import prisma from '@/lib/prisma';
|
||||||
import { EVENT_COLUMNS, EVENT_TYPE } from '@/lib/constants';
|
|
||||||
import { QueryFilters } from '@/lib/types';
|
import { QueryFilters } from '@/lib/types';
|
||||||
|
|
||||||
export async function getPageviewStats(...args: [websiteId: string, filters: QueryFilters]) {
|
export async function getPageviewStats(...args: [websiteId: string, filters: QueryFilters]) {
|
||||||
|
|
@ -17,7 +17,6 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
||||||
const { filterQuery, cohortQuery, joinSessionQuery, queryParams } = parseFilters({
|
const { filterQuery, cohortQuery, joinSessionQuery, queryParams } = parseFilters({
|
||||||
...filters,
|
...filters,
|
||||||
websiteId,
|
websiteId,
|
||||||
eventType: EVENT_TYPE.pageView,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
|
|
@ -30,6 +29,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
||||||
${joinSessionQuery}
|
${joinSessionQuery}
|
||||||
where website_event.website_id = {{websiteId::uuid}}
|
where website_event.website_id = {{websiteId::uuid}}
|
||||||
and website_event.created_at between {{startDate}} and {{endDate}}
|
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||||
|
and website_event.event_type != 2
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by 1
|
group by 1
|
||||||
order by 1
|
order by 1
|
||||||
|
|
@ -47,7 +47,6 @@ async function clickhouseQuery(
|
||||||
const { filterQuery, cohortQuery, queryParams } = parseFilters({
|
const { filterQuery, cohortQuery, queryParams } = parseFilters({
|
||||||
...filters,
|
...filters,
|
||||||
websiteId,
|
websiteId,
|
||||||
eventType: EVENT_TYPE.pageView,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let sql = '';
|
let sql = '';
|
||||||
|
|
@ -65,6 +64,7 @@ async function clickhouseQuery(
|
||||||
${cohortQuery}
|
${cohortQuery}
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
|
and event_type != 2
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by t
|
group by t
|
||||||
) as g
|
) as g
|
||||||
|
|
@ -83,6 +83,7 @@ async function clickhouseQuery(
|
||||||
${cohortQuery}
|
${cohortQuery}
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
|
and event_type != 2
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by t
|
group by t
|
||||||
) as g
|
) as g
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import clickhouse from '@/lib/clickhouse';
|
import clickhouse from '@/lib/clickhouse';
|
||||||
import { EVENT_TYPE, FILTER_COLUMNS, SESSION_COLUMNS } from '@/lib/constants';
|
import { FILTER_COLUMNS, SESSION_COLUMNS } from '@/lib/constants';
|
||||||
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
||||||
import prisma from '@/lib/prisma';
|
import prisma from '@/lib/prisma';
|
||||||
import { QueryFilters } from '@/lib/types';
|
import { QueryFilters } from '@/lib/types';
|
||||||
|
|
@ -40,7 +40,6 @@ async function relationalQuery(
|
||||||
{
|
{
|
||||||
...filters,
|
...filters,
|
||||||
websiteId,
|
websiteId,
|
||||||
eventType: EVENT_TYPE.pageView,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
joinSession: SESSION_COLUMNS.includes(type),
|
joinSession: SESSION_COLUMNS.includes(type),
|
||||||
|
|
@ -63,6 +62,7 @@ async function relationalQuery(
|
||||||
${joinSessionQuery}
|
${joinSessionQuery}
|
||||||
where website_event.website_id = {{websiteId::uuid}}
|
where website_event.website_id = {{websiteId::uuid}}
|
||||||
and website_event.created_at between {{startDate}} and {{endDate}}
|
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||||
|
and website_event.event_type != 2
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by 1
|
group by 1
|
||||||
${includeCountry ? ', 3' : ''}
|
${includeCountry ? ', 3' : ''}
|
||||||
|
|
@ -85,7 +85,6 @@ async function clickhouseQuery(
|
||||||
const { filterQuery, cohortQuery, queryParams } = parseFilters({
|
const { filterQuery, cohortQuery, queryParams } = parseFilters({
|
||||||
...filters,
|
...filters,
|
||||||
websiteId,
|
websiteId,
|
||||||
eventType: EVENT_TYPE.pageView,
|
|
||||||
});
|
});
|
||||||
const includeCountry = column === 'city' || column === 'region';
|
const includeCountry = column === 'city' || column === 'region';
|
||||||
|
|
||||||
|
|
@ -116,6 +115,7 @@ async function clickhouseQuery(
|
||||||
${cohortQuery}
|
${cohortQuery}
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
|
and event_type != 2
|
||||||
and name != ''
|
and name != ''
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by name, session_id, visit_id
|
group by name, session_id, visit_id
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ async function relationalQuery(
|
||||||
${joinSessionQuery}
|
${joinSessionQuery}
|
||||||
where website_event.website_id = {{websiteId::uuid}}
|
where website_event.website_id = {{websiteId::uuid}}
|
||||||
and website_event.created_at between {{startDate}} and {{endDate}}
|
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||||
and event_type != 2
|
and website_event.event_type != 2
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by 1
|
group by 1
|
||||||
${includeCountry ? ', 3' : ''}
|
${includeCountry ? ', 3' : ''}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import clickhouse from '@/lib/clickhouse';
|
import clickhouse from '@/lib/clickhouse';
|
||||||
import { EVENT_COLUMNS, EVENT_TYPE } from '@/lib/constants';
|
import { EVENT_COLUMNS } from '@/lib/constants';
|
||||||
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
||||||
import prisma from '@/lib/prisma';
|
import prisma from '@/lib/prisma';
|
||||||
import { QueryFilters } from '@/lib/types';
|
import { QueryFilters } from '@/lib/types';
|
||||||
|
|
@ -17,7 +17,6 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
||||||
const { filterQuery, joinSessionQuery, cohortQuery, queryParams } = parseFilters({
|
const { filterQuery, joinSessionQuery, cohortQuery, queryParams } = parseFilters({
|
||||||
...filters,
|
...filters,
|
||||||
websiteId,
|
websiteId,
|
||||||
eventType: EVENT_TYPE.pageView,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
|
|
@ -30,6 +29,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
||||||
${joinSessionQuery}
|
${joinSessionQuery}
|
||||||
where website_event.website_id = {{websiteId::uuid}}
|
where website_event.website_id = {{websiteId::uuid}}
|
||||||
and website_event.created_at between {{startDate}} and {{endDate}}
|
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||||
|
and website_event.event_type != 2
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by 1
|
group by 1
|
||||||
order by 1
|
order by 1
|
||||||
|
|
@ -47,7 +47,6 @@ async function clickhouseQuery(
|
||||||
const { filterQuery, cohortQuery, queryParams } = parseFilters({
|
const { filterQuery, cohortQuery, queryParams } = parseFilters({
|
||||||
...filters,
|
...filters,
|
||||||
websiteId,
|
websiteId,
|
||||||
eventType: EVENT_TYPE.pageView,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let sql = '';
|
let sql = '';
|
||||||
|
|
@ -65,6 +64,7 @@ async function clickhouseQuery(
|
||||||
${cohortQuery}
|
${cohortQuery}
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
|
and event_type != 2
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by t
|
group by t
|
||||||
) as g
|
) as g
|
||||||
|
|
@ -83,6 +83,7 @@ async function clickhouseQuery(
|
||||||
${cohortQuery}
|
${cohortQuery}
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
|
and event_type != 2
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by t
|
group by t
|
||||||
) as g
|
) as g
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue