Skip to content

Commit 1def80b

Browse files
committed
Merge remote-tracking branch 'origin/dev' into dev
2 parents da57286 + 16451dd commit 1def80b

File tree

15 files changed

+43
-52
lines changed

15 files changed

+43
-52
lines changed

db/clickhouse/schema.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ FROM (SELECT
209209
arrayFilter(x -> x != '', groupArray(twclid)) twclid,
210210
event_type,
211211
if(event_type = 2, groupArray(event_name), []) event_name,
212-
sumIf(1, event_type = 1) views,
212+
sumIf(1, event_type != 2) views,
213213
min(created_at) min_time,
214214
max(created_at) max_time,
215215
arrayFilter(x -> x != '', groupArray(tag)) tag,

src/app/(main)/pixels/[pixelId]/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { PixelPage } from './PixelPage';
22
import { Metadata } from 'next';
33

4-
export default function ({ params }: { params: { pixelId: string } }) {
5-
const { pixelId } = params;
4+
export default async function ({ params }: { params: { pixelId: string } }) {
5+
const { pixelId } = await params;
66

77
return <PixelPage pixelId={pixelId} />;
88
}

src/app/api/websites/[websiteId]/metrics/expanded/route.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { canViewWebsite } from '@/permissions';
2-
import { EVENT_COLUMNS, EVENT_TYPE, FILTER_COLUMNS, SESSION_COLUMNS } from '@/lib/constants';
1+
import { EVENT_COLUMNS, EVENT_TYPE, SESSION_COLUMNS } from '@/lib/constants';
32
import { getQueryFilters, parseRequest } from '@/lib/request';
43
import { badRequest, json, unauthorized } from '@/lib/response';
54
import { dateRangeParams, filterParams, searchParams } from '@/lib/schema';
5+
import { canViewWebsite } from '@/permissions';
66
import {
77
getChannelExpandedMetrics,
88
getEventExpandedMetrics,
@@ -50,13 +50,8 @@ export async function GET(
5050
}
5151

5252
if (EVENT_COLUMNS.includes(type)) {
53-
const column = FILTER_COLUMNS[type] || type;
54-
55-
if (column === 'event_name') {
56-
filters.eventType = EVENT_TYPE.customEvent;
57-
}
58-
5953
if (type === 'event') {
54+
filters.eventType = EVENT_TYPE.customEvent;
6055
return json(await getEventExpandedMetrics(websiteId, { type, limit, offset }, filters));
6156
} else {
6257
return json(await getPageviewExpandedMetrics(websiteId, { type, limit, offset }, filters));

src/app/api/websites/[websiteId]/metrics/route.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { canViewWebsite } from '@/permissions';
2-
import { EVENT_COLUMNS, EVENT_TYPE, FILTER_COLUMNS, SESSION_COLUMNS } from '@/lib/constants';
1+
import { EVENT_COLUMNS, EVENT_TYPE, SESSION_COLUMNS } from '@/lib/constants';
32
import { getQueryFilters, parseRequest } from '@/lib/request';
43
import { badRequest, json, unauthorized } from '@/lib/response';
4+
import { dateRangeParams, filterParams, searchParams } from '@/lib/schema';
5+
import { canViewWebsite } from '@/permissions';
56
import {
67
getChannelMetrics,
78
getEventMetrics,
89
getPageviewMetrics,
910
getSessionMetrics,
1011
} from '@/queries/sql';
1112
import { z } from 'zod';
12-
import { dateRangeParams, filterParams, searchParams } from '@/lib/schema';
1313

1414
export async function GET(
1515
request: Request,
@@ -50,13 +50,8 @@ export async function GET(
5050
}
5151

5252
if (EVENT_COLUMNS.includes(type)) {
53-
const column = FILTER_COLUMNS[type] || type;
54-
55-
if (column === 'event_name') {
56-
filters.eventType = EVENT_TYPE.customEvent;
57-
}
58-
5953
if (type === 'event') {
54+
filters.eventType = EVENT_TYPE.customEvent;
6055
return json(await getEventMetrics(websiteId, { type, limit, offset }, filters));
6156
} else {
6257
return json(await getPageviewMetrics(websiteId, { type, limit, offset }, filters));

src/lib/date.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,7 @@ export function parseDateRange(value: string, locale = 'en-US'): DateRange {
157157

158158
const now = new Date();
159159
const dateLocale = getDateLocale(locale);
160-
const { unit } = parseDateValue(value);
161-
let { num = 1 } = parseDateValue(value);
162-
163-
if (value === '7day') {
164-
num--;
165-
}
160+
const { num = 1, unit } = parseDateValue(value);
166161

167162
switch (unit) {
168163
case 'hour':

src/queries/sql/events/getEventExpandedMetrics.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ async function clickhouseQuery(
7878
const { filterQuery, cohortQuery, queryParams } = parseFilters({
7979
...filters,
8080
websiteId,
81+
eventType: EVENT_TYPE.customEvent,
8182
});
8283

8384
return rawQuery(

src/queries/sql/getChannelExpandedMetrics.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import clickhouse from '@/lib/clickhouse';
22
import {
33
EMAIL_DOMAINS,
4-
EVENT_TYPE,
54
PAID_AD_PARAMS,
65
SEARCH_DOMAINS,
76
SHOPPING_DOMAINS,
@@ -45,7 +44,6 @@ async function relationalQuery(
4544
const { queryParams, filterQuery, joinSessionQuery, cohortQuery, dateQuery } = parseFilters({
4645
...filters,
4746
websiteId,
48-
eventType: EVENT_TYPE.pageView,
4947
});
5048

5149
return rawQuery(
@@ -68,7 +66,8 @@ async function relationalQuery(
6866
from website_event
6967
${cohortQuery}
7068
${joinSessionQuery}
71-
where website_id = {{websiteId::uuid}}
69+
where website_event.website_id = {{websiteId::uuid}}
70+
and website_event.event_type != 2
7271
${dateQuery}
7372
${filterQuery}
7473
group by 1, 2
@@ -93,7 +92,6 @@ async function clickhouseQuery(
9392
const { queryParams, filterQuery, cohortQuery } = parseFilters({
9493
...filters,
9594
websiteId,
96-
eventType: EVENT_TYPE.pageView,
9795
});
9896

9997
return rawQuery(
@@ -140,6 +138,7 @@ async function clickhouseQuery(
140138
${cohortQuery}
141139
where website_id = {websiteId:UUID}
142140
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
141+
and event_type != 2
143142
and name != ''
144143
${filterQuery}
145144
group by prefix, name, session_id, visit_id

src/queries/sql/getChannelMetrics.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import clickhouse from '@/lib/clickhouse';
22
import {
33
EMAIL_DOMAINS,
4-
EVENT_TYPE,
54
PAID_AD_PARAMS,
65
SEARCH_DOMAINS,
76
SHOPPING_DOMAINS,
@@ -26,7 +25,6 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
2625
const { queryParams, filterQuery, joinSessionQuery, cohortQuery, dateQuery } = parseFilters({
2726
...filters,
2827
websiteId,
29-
eventType: EVENT_TYPE.pageView,
3028
});
3129

3230
return rawQuery(
@@ -49,7 +47,8 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
4947
from website_event
5048
${cohortQuery}
5149
${joinSessionQuery}
52-
where website_id = {{websiteId::uuid}}
50+
where website_event.website_id = {{websiteId::uuid}}
51+
and website_event.event_type != 2
5352
${dateQuery}
5453
${filterQuery}
5554
group by 1, 2
@@ -74,7 +73,6 @@ async function clickhouseQuery(
7473
const { queryParams, filterQuery, cohortQuery, dateQuery } = parseFilters({
7574
...filters,
7675
websiteId,
77-
eventType: EVENT_TYPE.pageView,
7876
});
7977

8078
const sql = `
@@ -108,6 +106,7 @@ async function clickhouseQuery(
108106
from website_event
109107
${cohortQuery}
110108
where website_id = {websiteId:UUID}
109+
and event_type != 2
111110
${dateQuery}
112111
${filterQuery}
113112
group by 1, 2

src/queries/sql/getWebsiteStats.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import clickhouse from '@/lib/clickhouse';
2-
import { EVENT_TYPE } from '@/lib/constants';
2+
import { EVENT_COLUMNS } from '@/lib/constants';
33
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
44
import prisma from '@/lib/prisma';
55
import { QueryFilters } from '@/lib/types';
6-
import { EVENT_COLUMNS } from '@/lib/constants';
76

87
const FUNCTION_NAME = 'getWebsiteStats';
98

@@ -32,7 +31,6 @@ async function relationalQuery(
3231
const { filterQuery, joinSessionQuery, cohortQuery, queryParams } = parseFilters({
3332
...filters,
3433
websiteId,
35-
eventType: EVENT_TYPE.pageView,
3634
});
3735

3836
return rawQuery(
@@ -55,6 +53,7 @@ async function relationalQuery(
5553
${joinSessionQuery}
5654
where website_event.website_id = {{websiteId::uuid}}
5755
and website_event.created_at between {{startDate}} and {{endDate}}
56+
and website_event.event_type != 2
5857
${filterQuery}
5958
group by 1, 2
6059
) as t
@@ -72,7 +71,6 @@ async function clickhouseQuery(
7271
const { filterQuery, cohortQuery, queryParams } = parseFilters({
7372
...filters,
7473
websiteId,
75-
eventType: EVENT_TYPE.pageView,
7674
});
7775

7876
let sql = '';
@@ -96,6 +94,7 @@ async function clickhouseQuery(
9694
${cohortQuery}
9795
where website_id = {websiteId:UUID}
9896
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
97+
and event_type != 2
9998
${filterQuery}
10099
group by session_id, visit_id
101100
) as t;
@@ -118,6 +117,7 @@ async function clickhouseQuery(
118117
${cohortQuery}
119118
where website_id = {websiteId:UUID}
120119
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
120+
and event_type != 2
121121
${filterQuery}
122122
group by session_id, visit_id
123123
) as t;

src/queries/sql/pageviews/getPageviewExpandedMetrics.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ async function relationalQuery(
6464
from website_event
6565
where website_event.website_id = {{websiteId::uuid}}
6666
and website_event.created_at between {{startDate}} and {{endDate}}
67-
and event_type = {{eventType}}
67+
and website_event.event_type != 2
6868
group by visit_id
6969
) x
7070
on x.visit_id = website_event.visit_id
@@ -82,6 +82,7 @@ async function relationalQuery(
8282
${entryExitQuery}
8383
where website_event.website_id = {{websiteId::uuid}}
8484
and website_event.created_at between {{startDate}} and {{endDate}}
85+
and website_event.event_type != 2
8586
${excludeDomain}
8687
${filterQuery}
8788
group by 1
@@ -127,7 +128,7 @@ async function clickhouseQuery(
127128
from website_event
128129
where website_id = {websiteId:UUID}
129130
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
130-
and event_type = {eventType:UInt32}
131+
and event_type != 2
131132
group by visit_id) x
132133
ON x.visit_id = website_event.visit_id`;
133134
}
@@ -154,6 +155,7 @@ async function clickhouseQuery(
154155
${entryExitQuery}
155156
where website_id = {websiteId:UUID}
156157
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
158+
and event_type != 2
157159
and name != ''
158160
${excludeDomain}
159161
${filterQuery}

0 commit comments

Comments
 (0)