feat: User Journey

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-12-18 22:50:25 +01:00
parent 5f38560373
commit 34cb186ead
11 changed files with 923 additions and 21 deletions

View File

@@ -11,6 +11,7 @@ import {
zGetMetricsInput,
zGetTopGenericInput,
zGetTopPagesInput,
zGetUserJourneyInput,
} from '@openpanel/db';
import { type IChartRange, zRange } from '@openpanel/validation';
import { format } from 'date-fns';
@@ -301,6 +302,33 @@ export const overviewRouter = createTRPCRouter({
timezone,
)(overviewService.getTopGeneric.bind(overviewService));
return current;
}),
userJourney: publicProcedure
.input(
zGetUserJourneyInput.omit({ startDate: true, endDate: true }).extend({
startDate: z.string().nullish(),
endDate: z.string().nullish(),
range: zRange,
steps: z.number().min(2).max(10).default(5).optional(),
}),
)
.use(cacher)
.query(async ({ input }) => {
const { timezone } = await getSettingsForProject(input.projectId);
const { current } = await getCurrentAndPrevious(
{ ...input, timezone },
false,
timezone,
)(async (input) => {
return overviewService.getUserJourney({
...input,
steps: input.steps ?? 5,
timezone,
});
});
return current;
}),
});