MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / trackRouter

Function trackRouter

apps/api/src/routes/track.router.ts:9–54  ·  view source on GitHub ↗
(fastify)

Source from the content-addressed store, hash-verified

7import { isBotHook } from '@/hooks/is-bot.hook';
8
9const trackRouter: FastifyPluginAsyncZodOpenApi = async (fastify) => {
10 fastify.addHook('preValidation', duplicateHook);
11 fastify.addHook('preHandler', clientHook);
12 fastify.addHook('preHandler', isBotHook);
13
14 await fastify.route({
15 method: 'POST',
16 url: '/',
17 schema: {
18 body: zTrackHandlerPayload.and(
19 z.object({
20 clientId: z.string().optional(),
21 clientSecret: z.string().optional(),
22 })
23 ),
24 tags: ['Track'],
25 description:
26 'Ingest a tracking event (track, identify, group, increment, decrement, replay).',
27 response: {
28 200: z.object({
29 deviceId: z.string(),
30 sessionId: z.string(),
31 }),
32 },
33 },
34 handler,
35 });
36
37 await fastify.route({
38 method: 'GET',
39 url: '/device-id',
40 schema: {
41 tags: ['Track'],
42 description:
43 'Get or generate a stable device ID and session ID for the current visitor.',
44 response: {
45 200: z.object({
46 deviceId: z.string(),
47 sessionId: z.string(),
48 message: z.string().optional(),
49 }),
50 },
51 },
52 handler: fetchDeviceId,
53 });
54};
55
56export default trackRouter;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected