More work on reports. Added Funnel page.

This commit is contained in:
Mike Cao 2025-06-05 22:19:35 -07:00
parent 5159dd470f
commit 3847e32f39
59 changed files with 1815 additions and 2370 deletions

View file

@ -111,8 +111,8 @@ export const DATA_TYPES = {
export const REPORT_TYPES = {
funnel: 'funnel',
goals: 'goals',
insights: 'insights',
goals: 'goal',
insights: 'insight',
retention: 'retention',
utm: 'utm',
journey: 'journey',

View file

@ -56,10 +56,10 @@ export const urlOrPathParam = z.string().refine(
export const reportTypeParam = z.enum([
'funnel',
'insights',
'insight',
'retention',
'utm',
'goals',
'goal',
'journey',
'revenue',
'attribution',
@ -76,3 +76,58 @@ export const reportParms = {
value: z.string().optional(),
}),
};
export const goalReportSchema = z.object({
type: z.literal('goal'),
parameters: z
.object({
type: z.string(),
value: z.string(),
operator: z.enum(['count', 'sum', 'average']).optional(),
property: z.string().optional(),
})
.refine(data => {
if (data['type'] === 'event' && data['property']) {
return data['operator'] && data['property'];
}
return true;
}),
});
export const funnelReportSchema = z.object({
type: z.literal('funnel'),
parameters: z.object({
window: z.coerce.number().positive(),
steps: z
.array(
z.object({
type: z.enum(['page', 'event']),
value: z.string(),
}),
)
.min(2)
.max(8),
}),
});
export const reportBaseSchema = z.object({
websiteId: z.string().uuid(),
type: reportTypeParam,
name: z.string().max(200),
description: z.string().max(500).optional(),
});
export const reportTypeSchema = z.discriminatedUnion('type', [
goalReportSchema,
funnelReportSchema,
]);
export const reportSchema = z.intersection(reportBaseSchema, reportTypeSchema);
export const reportResultSchema = z.intersection(
z.object({
...reportParms,
...filterParams,
}),
reportTypeSchema,
);