Merge remote-tracking branch 'origin/dev' into dev
Some checks are pending
Create docker images / Build, push, and deploy (push) Waiting to run
Node.js CI / build (postgresql, 18.18, 10) (push) Waiting to run

This commit is contained in:
Mike Cao 2025-10-02 16:57:23 -07:00
commit 1def80ba42
15 changed files with 43 additions and 52 deletions

View file

@ -209,7 +209,7 @@ FROM (SELECT
arrayFilter(x -> x != '', groupArray(twclid)) twclid,
event_type,
if(event_type = 2, groupArray(event_name), []) event_name,
sumIf(1, event_type = 1) views,
sumIf(1, event_type != 2) views,
min(created_at) min_time,
max(created_at) max_time,
arrayFilter(x -> x != '', groupArray(tag)) tag,

View file

@ -1,8 +1,8 @@
import { PixelPage } from './PixelPage';
import { Metadata } from 'next';
export default function ({ params }: { params: { pixelId: string } }) {
const { pixelId } = params;
export default async function ({ params }: { params: { pixelId: string } }) {
const { pixelId } = await params;
return <PixelPage pixelId={pixelId} />;
}

View file

@ -1,8 +1,8 @@
import { canViewWebsite } from '@/permissions';
import { EVENT_COLUMNS, EVENT_TYPE, FILTER_COLUMNS, SESSION_COLUMNS } from '@/lib/constants';
import { EVENT_COLUMNS, EVENT_TYPE, SESSION_COLUMNS } from '@/lib/constants';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { badRequest, json, unauthorized } from '@/lib/response';
import { dateRangeParams, filterParams, searchParams } from '@/lib/schema';
import { canViewWebsite } from '@/permissions';
import {
getChannelExpandedMetrics,
getEventExpandedMetrics,
@ -50,13 +50,8 @@ export async function GET(
}
if (EVENT_COLUMNS.includes(type)) {
const column = FILTER_COLUMNS[type] || type;
if (column === 'event_name') {
filters.eventType = EVENT_TYPE.customEvent;
}
if (type === 'event') {
filters.eventType = EVENT_TYPE.customEvent;
return json(await getEventExpandedMetrics(websiteId, { type, limit, offset }, filters));
} else {
return json(await getPageviewExpandedMetrics(websiteId, { type, limit, offset }, filters));

View file

@ -1,7 +1,8 @@
import { canViewWebsite } from '@/permissions';
import { EVENT_COLUMNS, EVENT_TYPE, FILTER_COLUMNS, SESSION_COLUMNS } from '@/lib/constants';
import { EVENT_COLUMNS, EVENT_TYPE, SESSION_COLUMNS } from '@/lib/constants';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { badRequest, json, unauthorized } from '@/lib/response';
import { dateRangeParams, filterParams, searchParams } from '@/lib/schema';
import { canViewWebsite } from '@/permissions';
import {
getChannelMetrics,
getEventMetrics,
@ -9,7 +10,6 @@ import {
getSessionMetrics,
} from '@/queries/sql';
import { z } from 'zod';
import { dateRangeParams, filterParams, searchParams } from '@/lib/schema';
export async function GET(
request: Request,
@ -50,13 +50,8 @@ export async function GET(
}
if (EVENT_COLUMNS.includes(type)) {
const column = FILTER_COLUMNS[type] || type;
if (column === 'event_name') {
filters.eventType = EVENT_TYPE.customEvent;
}
if (type === 'event') {
filters.eventType = EVENT_TYPE.customEvent;
return json(await getEventMetrics(websiteId, { type, limit, offset }, filters));
} else {
return json(await getPageviewMetrics(websiteId, { type, limit, offset }, filters));

View file

@ -157,12 +157,7 @@ export function parseDateRange(value: string, locale = 'en-US'): DateRange {
const now = new Date();
const dateLocale = getDateLocale(locale);
const { unit } = parseDateValue(value);
let { num = 1 } = parseDateValue(value);
if (value === '7day') {
num--;
}
const { num = 1, unit } = parseDateValue(value);
switch (unit) {
case 'hour':

View file

@ -78,6 +78,7 @@ async function clickhouseQuery(
const { filterQuery, cohortQuery, queryParams } = parseFilters({
...filters,
websiteId,
eventType: EVENT_TYPE.customEvent,
});
return rawQuery(

View file

@ -1,7 +1,6 @@
import clickhouse from '@/lib/clickhouse';
import {
EMAIL_DOMAINS,
EVENT_TYPE,
PAID_AD_PARAMS,
SEARCH_DOMAINS,
SHOPPING_DOMAINS,
@ -45,7 +44,6 @@ async function relationalQuery(
const { queryParams, filterQuery, joinSessionQuery, cohortQuery, dateQuery } = parseFilters({
...filters,
websiteId,
eventType: EVENT_TYPE.pageView,
});
return rawQuery(
@ -68,7 +66,8 @@ async function relationalQuery(
from website_event
${cohortQuery}
${joinSessionQuery}
where website_id = {{websiteId::uuid}}
where website_event.website_id = {{websiteId::uuid}}
and website_event.event_type != 2
${dateQuery}
${filterQuery}
group by 1, 2
@ -93,7 +92,6 @@ async function clickhouseQuery(
const { queryParams, filterQuery, cohortQuery } = parseFilters({
...filters,
websiteId,
eventType: EVENT_TYPE.pageView,
});
return rawQuery(
@ -140,6 +138,7 @@ async function clickhouseQuery(
${cohortQuery}
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
and event_type != 2
and name != ''
${filterQuery}
group by prefix, name, session_id, visit_id

View file

@ -1,7 +1,6 @@
import clickhouse from '@/lib/clickhouse';
import {
EMAIL_DOMAINS,
EVENT_TYPE,
PAID_AD_PARAMS,
SEARCH_DOMAINS,
SHOPPING_DOMAINS,
@ -26,7 +25,6 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
const { queryParams, filterQuery, joinSessionQuery, cohortQuery, dateQuery } = parseFilters({
...filters,
websiteId,
eventType: EVENT_TYPE.pageView,
});
return rawQuery(
@ -49,7 +47,8 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
from website_event
${cohortQuery}
${joinSessionQuery}
where website_id = {{websiteId::uuid}}
where website_event.website_id = {{websiteId::uuid}}
and website_event.event_type != 2
${dateQuery}
${filterQuery}
group by 1, 2
@ -74,7 +73,6 @@ async function clickhouseQuery(
const { queryParams, filterQuery, cohortQuery, dateQuery } = parseFilters({
...filters,
websiteId,
eventType: EVENT_TYPE.pageView,
});
const sql = `
@ -108,6 +106,7 @@ async function clickhouseQuery(
from website_event
${cohortQuery}
where website_id = {websiteId:UUID}
and event_type != 2
${dateQuery}
${filterQuery}
group by 1, 2

View file

@ -1,9 +1,8 @@
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 prisma from '@/lib/prisma';
import { QueryFilters } from '@/lib/types';
import { EVENT_COLUMNS } from '@/lib/constants';
const FUNCTION_NAME = 'getWebsiteStats';
@ -32,7 +31,6 @@ async function relationalQuery(
const { filterQuery, joinSessionQuery, cohortQuery, queryParams } = parseFilters({
...filters,
websiteId,
eventType: EVENT_TYPE.pageView,
});
return rawQuery(
@ -55,6 +53,7 @@ async function relationalQuery(
${joinSessionQuery}
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and website_event.event_type != 2
${filterQuery}
group by 1, 2
) as t
@ -72,7 +71,6 @@ async function clickhouseQuery(
const { filterQuery, cohortQuery, queryParams } = parseFilters({
...filters,
websiteId,
eventType: EVENT_TYPE.pageView,
});
let sql = '';
@ -96,6 +94,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 session_id, visit_id
) as t;
@ -118,6 +117,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 session_id, visit_id
) as t;

View file

@ -64,7 +64,7 @@ async function relationalQuery(
from website_event
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and event_type = {{eventType}}
and website_event.event_type != 2
group by visit_id
) x
on x.visit_id = website_event.visit_id
@ -82,6 +82,7 @@ async function relationalQuery(
${entryExitQuery}
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and website_event.event_type != 2
${excludeDomain}
${filterQuery}
group by 1
@ -127,7 +128,7 @@ async function clickhouseQuery(
from website_event
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
and event_type = {eventType:UInt32}
and event_type != 2
group by visit_id) x
ON x.visit_id = website_event.visit_id`;
}
@ -154,6 +155,7 @@ async function clickhouseQuery(
${entryExitQuery}
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
and event_type != 2
and name != ''
${excludeDomain}
${filterQuery}

View file

@ -62,7 +62,7 @@ async function relationalQuery(
from website_event
where website_event.website_id = {{websiteId::uuid}}
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}
) x
on x.visit_id = website_event.visit_id
@ -79,6 +79,7 @@ async function relationalQuery(
${entryExitQuery}
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and website_event.event_type != 2
${excludeDomain}
${filterQuery}
group by 1
@ -124,7 +125,7 @@ async function clickhouseQuery(
from website_event
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
and event_type = {eventType:UInt32}
and event_type != 2
group by visit_id) x
ON x.visit_id = website_event.visit_id`;
}
@ -137,6 +138,7 @@ async function clickhouseQuery(
${entryExitQuery}
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
and event_type != 2
${excludeDomain}
${filterQuery}
group by x
@ -174,6 +176,7 @@ async function clickhouseQuery(
${cohortQuery}
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
and event_type != 2
${excludeDomain}
${filterQuery}
${groupByQuery}) as g

View file

@ -1,7 +1,7 @@
import clickhouse from '@/lib/clickhouse';
import { EVENT_COLUMNS } from '@/lib/constants';
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
import prisma from '@/lib/prisma';
import { EVENT_COLUMNS, EVENT_TYPE } from '@/lib/constants';
import { QueryFilters } from '@/lib/types';
const FUNCTION_NAME = 'getPageviewStats';
@ -19,7 +19,6 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
const { filterQuery, cohortQuery, joinSessionQuery, queryParams } = parseFilters({
...filters,
websiteId,
eventType: EVENT_TYPE.pageView,
});
return rawQuery(
@ -32,6 +31,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
${joinSessionQuery}
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and website_event.event_type != 2
${filterQuery}
group by 1
order by 1
@ -50,7 +50,6 @@ async function clickhouseQuery(
const { filterQuery, cohortQuery, queryParams } = parseFilters({
...filters,
websiteId,
eventType: EVENT_TYPE.pageView,
});
let sql = '';
@ -68,6 +67,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 t
) as g
@ -86,6 +86,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 t
) as g

View file

@ -1,5 +1,5 @@
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 prisma from '@/lib/prisma';
import { QueryFilters } from '@/lib/types';
@ -42,7 +42,6 @@ async function relationalQuery(
{
...filters,
websiteId,
eventType: EVENT_TYPE.pageView,
},
{
joinSession: SESSION_COLUMNS.includes(type),
@ -65,6 +64,7 @@ async function relationalQuery(
${joinSessionQuery}
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and website_event.event_type != 2
${filterQuery}
group by 1
${includeCountry ? ', 3' : ''}
@ -88,7 +88,6 @@ async function clickhouseQuery(
const { filterQuery, cohortQuery, queryParams } = parseFilters({
...filters,
websiteId,
eventType: EVENT_TYPE.pageView,
});
const includeCountry = column === 'city' || column === 'region';
@ -119,6 +118,7 @@ async function clickhouseQuery(
${cohortQuery}
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
and event_type != 2
and name != ''
${filterQuery}
group by name, session_id, visit_id

View file

@ -55,7 +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
and website_event.event_type != 2
${filterQuery}
group by 1
${includeCountry ? ', 3' : ''}

View file

@ -1,5 +1,5 @@
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 prisma from '@/lib/prisma';
import { QueryFilters } from '@/lib/types';
@ -19,7 +19,6 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
const { filterQuery, joinSessionQuery, cohortQuery, queryParams } = parseFilters({
...filters,
websiteId,
eventType: EVENT_TYPE.pageView,
});
return rawQuery(
@ -32,6 +31,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
${joinSessionQuery}
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and website_event.event_type != 2
${filterQuery}
group by 1
order by 1
@ -50,7 +50,6 @@ async function clickhouseQuery(
const { filterQuery, cohortQuery, queryParams } = parseFilters({
...filters,
websiteId,
eventType: EVENT_TYPE.pageView,
});
let sql = '';
@ -68,6 +67,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 t
) as g
@ -86,6 +86,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 t
) as g