feat(dashboard): added new Pages
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { isSameDay, isSameMonth } from 'date-fns';
|
||||
|
||||
export const DEFAULT_ASPECT_RATIO = 0.5625;
|
||||
export const NOT_SET_VALUE = '(not set)';
|
||||
|
||||
export const timeWindows = {
|
||||
|
||||
@@ -28,6 +28,15 @@ export type IImportedEvent = Omit<
|
||||
properties: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export type IServicePage = {
|
||||
path: string;
|
||||
count: number;
|
||||
project_id: string;
|
||||
first_seen: string;
|
||||
title: string;
|
||||
origin: string;
|
||||
};
|
||||
|
||||
export interface IClickhouseEvent {
|
||||
id: string;
|
||||
name: string;
|
||||
@@ -493,3 +502,30 @@ export async function getLastScreenViewFromProfileId({
|
||||
|
||||
return eventInDb || null;
|
||||
}
|
||||
|
||||
export async function getTopPages({
|
||||
projectId,
|
||||
cursor,
|
||||
take,
|
||||
search,
|
||||
}: {
|
||||
projectId: string;
|
||||
cursor?: number;
|
||||
take: number;
|
||||
search?: string;
|
||||
}) {
|
||||
const res = await chQuery<IServicePage>(`
|
||||
SELECT path, count(*) as count, project_id, first_value(created_at) as first_seen, max(properties['__title']) as title, origin
|
||||
FROM events_v2
|
||||
WHERE name = 'screen_view'
|
||||
AND project_id = ${escape(projectId)}
|
||||
AND created_at > now() - INTERVAL 30 DAY
|
||||
${search ? `AND path LIKE '%${search}%'` : ''}
|
||||
GROUP BY path, project_id, origin
|
||||
ORDER BY count desc
|
||||
LIMIT ${take}
|
||||
OFFSET ${Math.max(0, (cursor ?? 0) * take)}
|
||||
`);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
db,
|
||||
getEventList,
|
||||
getEvents,
|
||||
getTopPages,
|
||||
TABLE_NAMES,
|
||||
} from '@openpanel/db';
|
||||
import { zChartEventFilter } from '@openpanel/validation';
|
||||
@@ -69,7 +70,6 @@ export const eventRouter = createTRPCRouter({
|
||||
z.object({
|
||||
projectId: z.string(),
|
||||
cursor: z.number().optional(),
|
||||
limit: z.number().default(8),
|
||||
profileId: z.string().optional(),
|
||||
take: z.number().default(50),
|
||||
events: z.array(z.string()).optional(),
|
||||
@@ -165,4 +165,17 @@ export const eventRouter = createTRPCRouter({
|
||||
count: counts[0]?.count ?? 0,
|
||||
};
|
||||
}),
|
||||
|
||||
pages: protectedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
projectId: z.string(),
|
||||
cursor: z.number().optional(),
|
||||
take: z.number().default(20),
|
||||
search: z.string().optional(),
|
||||
})
|
||||
)
|
||||
.query(async ({ input }) => {
|
||||
return getTopPages(input);
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ import { z } from 'zod';
|
||||
import { db } from '@openpanel/db';
|
||||
import { zInviteUser } from '@openpanel/validation';
|
||||
|
||||
import { getOrganizationAccess, getOrganizationAccessCached } from '../access';
|
||||
import { getOrganizationAccess } from '../access';
|
||||
import { TRPCAccessError } from '../errors';
|
||||
import { createTRPCRouter, protectedProcedure } from '../trpc';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user