Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { z } from 'zod';
/**
* Analytics event types enum
*/
export const eventTypeEnum = z.enum([
'profile_view',
'sample_click',
'testimonial_view',
'package_view',
'whatsapp_click',
'email_click',
'linkedin_click',
'website_click',
'verification_view',
]);
export type EventType = z.infer<typeof eventTypeEnum>;
/**
* Track event schema
*/
export const trackEventSchema = z.object({
profile_id: z.string().uuid(),
event_type: eventTypeEnum,
meta: z
.object({
sample_id: z.string().uuid().optional(),
package_id: z.string().uuid().optional(),
referrer: z.string().max(500).optional(),
utm_source: z.string().max(100).optional(),
utm_medium: z.string().max(100).optional(),
utm_campaign: z.string().max(100).optional(),
})
.passthrough()
.optional()
.default({}),
});
/**
* Analytics query schema (for stats retrieval)
*/
export const analyticsQuerySchema = z.object({
start_date: z.string().datetime().optional(),
end_date: z.string().datetime().optional(),
event_type: eventTypeEnum.optional(),
group_by: z.enum(['day', 'week', 'month']).optional().default('day'),
});
/**
* Analytics summary response
*/
export const analyticsSummarySchema = z.object({
total_views: z.number(),
total_clicks: z.number(),
whatsapp_clicks: z.number(),
email_clicks: z.number(),
unique_visitors: z.number(),
click_through_rate: z.number(),
top_referrers: z.array(
z.object({
referrer: z.string(),
count: z.number(),
})
),
views_by_period: z.array(
z.object({
period: z.string(),
views: z.number(),
})
),
clicks_by_type: z.array(
z.object({
event_type: eventTypeEnum,
count: z.number(),
})
),
});
// Type exports
export type TrackEventInput = z.infer<typeof trackEventSchema>;
export type AnalyticsQueryInput = z.infer<typeof analyticsQuerySchema>;
export type AnalyticsSummary = z.infer<typeof analyticsSummarySchema>;
|