Compare commits

..

No commits in common. "581ddc0233679650e9f73b0ba29382ce2515c6a2" and "55c8a6f7ccb80de67e34410954d82c02bbd2c11b" have entirely different histories.

18 changed files with 808 additions and 911 deletions

View file

@ -74,18 +74,18 @@
"@date-fns/utc": "^1.2.0",
"@dicebear/collection": "^9.2.3",
"@dicebear/core": "^9.2.3",
"@fontsource/inter": "^5.2.8",
"@fontsource/inter": "^5.2.6",
"@hello-pangea/dnd": "^17.0.0",
"@prisma/adapter-pg": "^6.16.3",
"@prisma/client": "^6.16.3",
"@prisma/adapter-pg": "^6.16.0",
"@prisma/client": "^6.16.0",
"@prisma/extension-read-replicas": "^0.4.1",
"@react-spring/web": "^10.0.3",
"@react-spring/web": "^10.0.1",
"@svgr/cli": "^8.1.0",
"@tanstack/react-query": "^5.90.2",
"@tanstack/react-query": "^5.85.5",
"@umami/react-zen": "^0.187.0",
"@umami/redis-client": "^0.29.0",
"bcryptjs": "^3.0.2",
"chalk": "^5.6.2",
"chalk": "^5.6.0",
"chart.js": "^4.5.0",
"chartjs-adapter-date-fns": "^3.0.0",
"classnames": "^2.3.1",
@ -94,19 +94,19 @@
"cross-spawn": "^7.0.3",
"date-fns": "^2.23.0",
"date-fns-tz": "^1.1.4",
"debug": "^4.4.3",
"debug": "^4.3.4",
"del": "^6.0.0",
"detect-browser": "^5.2.0",
"dotenv": "^17.2.3",
"esbuild": "^0.25.10",
"dotenv": "^17.2.1",
"esbuild": "^0.25.9",
"eslint-plugin-promise": "^6.1.1",
"fs-extra": "^11.3.2",
"immer": "^10.1.3",
"fs-extra": "^11.3.1",
"immer": "^10.1.1",
"ipaddr.js": "^2.0.1",
"is-ci": "^3.0.1",
"is-docker": "^3.0.0",
"is-localhost-ip": "^2.0.0",
"isbot": "^5.1.31",
"isbot": "^5.1.30",
"jsonwebtoken": "^9.0.2",
"jszip": "^3.10.1",
"kafkajs": "^2.1.0",
@ -132,12 +132,12 @@
"thenby": "^1.3.4",
"ua-parser-js": "^2.0.5",
"uuid": "^11.1.0",
"zod": "^4.1.11",
"zod": "^4.1.5",
"zustand": "^5.0.8"
},
"devDependencies": {
"@formatjs/cli": "^4.2.29",
"@netlify/plugin-nextjs": "^5.13.3",
"@netlify/plugin-nextjs": "^5.12.1",
"@rollup/plugin-alias": "^5.0.0",
"@rollup/plugin-commonjs": "^25.0.4",
"@rollup/plugin-json": "^6.0.0",
@ -146,18 +146,18 @@
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.4",
"@types/jest": "^30.0.0",
"@types/node": "^24.6.0",
"@types/react": "^19.1.16",
"@types/react-dom": "^19.1.9",
"@types/node": "^24.3.0",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.8",
"@types/react-window": "^1.8.8",
"@typescript-eslint/eslint-plugin": "^8.45.0",
"@typescript-eslint/parser": "^8.45.0",
"@typescript-eslint/eslint-plugin": "^8.41.0",
"@typescript-eslint/parser": "^8.41.0",
"@umami/prisma-client": "^0.20.0",
"babel-plugin-react-compiler": "19.1.0-rc.2",
"cross-env": "^10.1.0",
"cross-env": "^10.0.0",
"cypress": "^13.6.6",
"eslint": "^8.33.0",
"eslint-config-next": "^14.2.33",
"eslint-config-next": "^14.2.32",
"eslint-config-prettier": "^10.1.8",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-css-modules": "^2.12.0",
@ -168,18 +168,18 @@
"extract-react-intl-messages": "^4.1.1",
"husky": "^9.1.7",
"jest": "^29.7.0",
"lint-staged": "^16.2.3",
"lint-staged": "^16.1.5",
"postcss": "^8.5.6",
"postcss-flexbugs-fixes": "^5.0.2",
"postcss-import": "^15.1.0",
"postcss-preset-env": "7.8.3",
"prettier": "^3.6.2",
"prompts": "2.4.2",
"rollup": "^4.52.3",
"rollup": "^4.49.0",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-delete": "^3.0.1",
"rollup-plugin-dts": "^6.2.3",
"rollup-plugin-node-externals": "^8.1.1",
"rollup-plugin-node-externals": "^8.1.0",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-postcss": "^4.0.2",
"stylelint": "^15.10.1",
@ -190,6 +190,6 @@
"ts-jest": "^29.4.0",
"ts-node": "^10.9.1",
"tsup": "^8.5.0",
"typescript": "^5.9.3"
"typescript": "^5.9.2"
}
}

1465
pnpm-lock.yaml generated

File diff suppressed because it is too large Load diff

View file

@ -1,10 +1,6 @@
export const dynamic = 'force-dynamic';
import { NextResponse } from 'next/server';
import { notFound } from '@/lib/response';
import redis from '@/lib/redis';
import { findPixel } from '@/queries/prisma';
import { Pixel } from '@/generated/prisma/client';
import { POST } from '@/app/api/send/route';
const image = Buffer.from('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw', 'base64');
@ -12,34 +8,14 @@ const image = Buffer.from('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICR
export async function GET(request: Request, { params }: { params: Promise<{ slug: string }> }) {
const { slug } = await params;
let pixel: Pixel;
const pixel = await findPixel({
where: {
slug,
},
});
if (redis.enabled) {
pixel = await redis.client.fetch(
`pixel:${slug}`,
async () => {
return findPixel({
where: {
slug,
},
});
},
86400,
);
if (!pixel) {
return notFound();
}
} else {
pixel = await findPixel({
where: {
slug,
},
});
if (!pixel) {
return notFound();
}
if (!pixel) {
return notFound();
}
const payload = {
@ -47,7 +23,7 @@ export async function GET(request: Request, { params }: { params: Promise<{ slug
payload: {
pixel: pixel.id,
url: request.url,
referrer: request.headers.get('referer'),
referrer: request.referrer,
},
};
@ -57,12 +33,13 @@ export async function GET(request: Request, { params }: { params: Promise<{ slug
body: JSON.stringify(payload),
});
await POST(req);
const res = await POST(req);
return new NextResponse(image, {
headers: {
'Content-Type': 'image/gif',
'Content-Length': image.length.toString(),
'x-umami-collect': JSON.stringify(res),
},
});
}

View file

@ -1,43 +1,19 @@
export const dynamic = 'force-dynamic';
import { NextResponse } from 'next/server';
import { notFound } from '@/lib/response';
import { findLink } from '@/queries/prisma';
import { POST } from '@/app/api/send/route';
import { Link } from '@/generated/prisma/client';
import redis from '@/lib/redis';
export async function GET(request: Request, { params }: { params: Promise<{ slug: string }> }) {
const { slug } = await params;
let link: Link;
const link = await findLink({
where: {
slug,
},
});
if (redis.enabled) {
link = await redis.client.fetch(
`link:${slug}`,
async () => {
return findLink({
where: {
slug,
},
});
},
86400,
);
if (!link) {
return notFound();
}
} else {
link = await findLink({
where: {
slug,
},
});
if (!link) {
return notFound();
}
if (!link) {
return notFound();
}
const payload = {
@ -45,7 +21,7 @@ export async function GET(request: Request, { params }: { params: Promise<{ slug
payload: {
link: link.id,
url: request.url,
referrer: request.headers.get('referer'),
referrer: request.referrer,
},
};

View file

@ -1,5 +1,5 @@
import { canViewWebsite } from '@/permissions';
import { EVENT_COLUMNS, EVENT_TYPE, FILTER_COLUMNS, SESSION_COLUMNS } from '@/lib/constants';
import { EVENT_COLUMNS, 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';
@ -50,21 +50,21 @@ export async function GET(
}
if (EVENT_COLUMNS.includes(type)) {
const column = FILTER_COLUMNS[type] || type;
if (column === 'event_name') {
filters.eventType = EVENT_TYPE.customEvent;
}
let data;
if (type === 'event') {
return json(await getEventExpandedMetrics(websiteId, { type, limit, offset }, filters));
data = await getEventExpandedMetrics(websiteId, { type, limit, offset }, filters);
} else {
return json(await getPageviewExpandedMetrics(websiteId, { type, limit, offset }, filters));
data = await getPageviewExpandedMetrics(websiteId, { type, limit, offset }, filters);
}
return json(data);
}
if (type === 'channel') {
return json(await getChannelExpandedMetrics(websiteId, filters));
const data = await getChannelExpandedMetrics(websiteId, filters);
return json(data);
}
return badRequest();

View file

@ -1,5 +1,5 @@
import { canViewWebsite } from '@/permissions';
import { EVENT_COLUMNS, EVENT_TYPE, FILTER_COLUMNS, SESSION_COLUMNS } from '@/lib/constants';
import { EVENT_COLUMNS, SESSION_COLUMNS } from '@/lib/constants';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { badRequest, json, unauthorized } from '@/lib/response';
import {
@ -50,21 +50,21 @@ export async function GET(
}
if (EVENT_COLUMNS.includes(type)) {
const column = FILTER_COLUMNS[type] || type;
if (column === 'event_name') {
filters.eventType = EVENT_TYPE.customEvent;
}
let data;
if (type === 'event') {
return json(await getEventMetrics(websiteId, { type, limit, offset }, filters));
data = await getEventMetrics(websiteId, { type, limit, offset }, filters);
} else {
return json(await getPageviewMetrics(websiteId, { type, limit, offset }, filters));
data = await getPageviewMetrics(websiteId, { type, limit, offset }, filters);
}
return json(data);
}
if (type === 'channel') {
return json(await getChannelMetrics(websiteId, filters));
const data = await getChannelMetrics(websiteId, filters);
return json(data);
}
return badRequest();

View file

@ -206,10 +206,9 @@ async function pagedRawQuery(
async function rawQuery<T = unknown>(
query: string,
params: Record<string, unknown> = {},
name?: string,
): Promise<T> {
if (process.env.LOG_QUERY) {
log({ query, params, name });
log({ query, params });
}
await connect();

View file

@ -164,11 +164,10 @@ function parseFilters(filters: Record<string, any>, options?: QueryOptions) {
};
}
async function rawQuery(sql: string, data: Record<string, any>, name?: string): Promise<any> {
async function rawQuery(sql: string, data: object): Promise<any> {
if (process.env.LOG_QUERY) {
log('QUERY:\n', sql);
log('PARAMETERS:\n', data);
log('NAME:\n', name);
}
const params = [];
const schema = getSchema();

View file

@ -4,8 +4,6 @@ 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;
@ -60,7 +58,6 @@ async function relationalQuery(
offset ${offset}
`,
{ ...queryParams, ...parameters },
FUNCTION_NAME,
);
}
@ -92,6 +89,5 @@ async function clickhouseQuery(
offset ${offset}
`,
{ ...queryParams, ...parameters },
FUNCTION_NAME,
);
}

View file

@ -1,5 +1,5 @@
import { uuid } from '@/lib/crypto';
import { EVENT_NAME_LENGTH, URL_LENGTH, PAGE_TITLE_LENGTH } from '@/lib/constants';
import { EVENT_NAME_LENGTH, URL_LENGTH, EVENT_TYPE, PAGE_TITLE_LENGTH } from '@/lib/constants';
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
import clickhouse from '@/lib/clickhouse';
import kafka from '@/lib/kafka';
@ -66,9 +66,10 @@ async function relationalQuery({
websiteId,
sessionId,
visitId,
eventType,
createdAt,
eventType,
pageTitle,
tag,
hostname,
urlPath,
urlQuery,
@ -77,7 +78,6 @@ async function relationalQuery({
referrerDomain,
eventName,
eventData,
tag,
utmSource,
utmMedium,
utmCampaign,
@ -154,16 +154,9 @@ async function clickhouseQuery({
websiteId,
sessionId,
visitId,
eventType,
distinctId,
createdAt,
pageTitle,
hostname,
urlPath,
urlQuery,
referrerPath,
referrerQuery,
referrerDomain,
distinctId,
browser,
os,
device,
@ -172,9 +165,15 @@ async function clickhouseQuery({
country,
region,
city,
tag,
hostname,
urlPath,
urlQuery,
referrerPath,
referrerQuery,
referrerDomain,
eventName,
eventData,
tag,
utmSource,
utmMedium,
utmCampaign,
@ -216,7 +215,7 @@ async function clickhouseQuery({
ttclid: ttclid,
li_fat_id: lifatid,
twclid: twclid,
event_type: eventType,
event_type: eventName ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
event_name: eventName ? eventName?.substring(0, EVENT_NAME_LENGTH) : null,
tag: tag,
distinct_id: distinctId,

View file

@ -3,8 +3,6 @@ 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),
@ -24,7 +22,6 @@ async function relationalQuery(websiteId: string) {
and created_at >= {{startDate}}
`,
{ websiteId, startDate },
FUNCTION_NAME,
);
return result?.[0] ?? null;
@ -43,7 +40,6 @@ async function clickhouseQuery(websiteId: string): Promise<{ x: number }> {
and created_at >= {startDate:DateTime64}
`,
{ websiteId, startDate },
FUNCTION_NAME,
);
return result[0] ?? null;

View file

@ -12,8 +12,6 @@ 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;
@ -81,7 +79,6 @@ async function relationalQuery(
order by y desc;
`,
queryParams,
FUNCTION_NAME,
);
}
@ -148,7 +145,6 @@ async function clickhouseQuery(
order by visitors desc, visits desc;
`,
queryParams,
FUNCTION_NAME,
);
}

View file

@ -12,8 +12,6 @@ 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),
@ -62,7 +60,6 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
order by y desc;
`,
queryParams,
FUNCTION_NAME,
);
}
@ -120,7 +117,7 @@ async function clickhouseQuery(
order by y desc;
`;
return rawQuery(sql, queryParams, FUNCTION_NAME);
return rawQuery(sql, queryParams);
}
function toClickHouseStringArray(arr: string[]): string {

View file

@ -3,8 +3,6 @@ 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),
@ -42,7 +40,6 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
limit 100
`,
queryParams,
FUNCTION_NAME,
);
}
@ -74,6 +71,5 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters): Promis
limit 100
`,
queryParams,
FUNCTION_NAME,
);
}

View file

@ -3,8 +3,6 @@ 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]
) {
@ -66,7 +64,6 @@ async function relationalQuery(websiteId: string, column: string, filters: Query
search: `%${search}%`,
...params,
},
FUNCTION_NAME,
);
}
@ -123,6 +120,5 @@ async function clickhouseQuery(websiteId: string, column: string, filters: Query
search,
...params,
},
FUNCTION_NAME,
);
}

View file

@ -1,11 +1,9 @@
import clickhouse from '@/lib/clickhouse';
import { FILTER_COLUMNS, GROUPED_DOMAINS, SESSION_COLUMNS } from '@/lib/constants';
import { EVENT_TYPE, 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;
@ -42,6 +40,7 @@ async function relationalQuery(
{
...filters,
websiteId,
eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
},
{ joinSession: SESSION_COLUMNS.includes(type) },
);
@ -90,7 +89,6 @@ async function relationalQuery(
offset ${offset}
`,
queryParams,
FUNCTION_NAME,
);
}
@ -105,6 +103,7 @@ async function clickhouseQuery(
const { filterQuery, cohortQuery, queryParams } = parseFilters({
...filters,
websiteId,
eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
});
let excludeDomain = '';
@ -165,7 +164,6 @@ async function clickhouseQuery(
offset ${offset}
`,
{ ...queryParams, ...parameters },
FUNCTION_NAME,
);
}

View file

@ -1,11 +1,9 @@
import clickhouse from '@/lib/clickhouse';
import { EVENT_COLUMNS, FILTER_COLUMNS, SESSION_COLUMNS } from '@/lib/constants';
import { EVENT_COLUMNS, EVENT_TYPE, 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;
@ -38,6 +36,7 @@ async function relationalQuery(
{
...filters,
websiteId,
eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
},
{ joinSession: SESSION_COLUMNS.includes(type) },
);
@ -87,7 +86,6 @@ async function relationalQuery(
offset ${offset}
`,
{ ...queryParams, ...parameters },
FUNCTION_NAME,
);
}
@ -102,6 +100,7 @@ async function clickhouseQuery(
const { filterQuery, cohortQuery, queryParams } = parseFilters({
...filters,
websiteId,
eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
});
let sql = '';
@ -184,5 +183,5 @@ async function clickhouseQuery(
`;
}
return rawQuery(sql, { ...queryParams, ...parameters }, FUNCTION_NAME);
return rawQuery(sql, { ...queryParams, ...parameters });
}

View file

@ -1,11 +1,9 @@
import clickhouse from '@/lib/clickhouse';
import { EVENT_COLUMNS, FILTER_COLUMNS, SESSION_COLUMNS } from '@/lib/constants';
import { EVENT_COLUMNS, EVENT_TYPE, 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;
@ -33,6 +31,7 @@ async function relationalQuery(
{
...filters,
websiteId,
eventType: EVENT_TYPE.pageView,
},
{
joinSession: SESSION_COLUMNS.includes(type),
@ -55,7 +54,6 @@ 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' : ''}
@ -64,7 +62,6 @@ async function relationalQuery(
offset ${offset}
`,
{ ...queryParams, ...parameters },
FUNCTION_NAME,
);
}
@ -79,6 +76,7 @@ async function clickhouseQuery(
const { filterQuery, cohortQuery, queryParams } = parseFilters({
...filters,
websiteId,
eventType: EVENT_TYPE.pageView,
});
const includeCountry = column === 'city' || column === 'region';
@ -98,7 +96,6 @@ 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' : ''}
@ -116,7 +113,6 @@ 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' : ''}
@ -126,5 +122,5 @@ async function clickhouseQuery(
`;
}
return rawQuery(sql, { ...queryParams, ...parameters }, FUNCTION_NAME);
return rawQuery(sql, { ...queryParams, ...parameters });
}