Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

fix bot events

Carl-Gerhard Lindesvärd4cc2f7a32984
diff --git a/apps/sdk-api/src/routes/event.router.ts b/apps/sdk-api/src/routes/event.router.ts
index cb68fdcbd..0a476b5c8 100644
--- a/apps/sdk-api/src/routes/event.router.ts
+++ b/apps/sdk-api/src/routes/event.router.ts
@@ -26,7 +26,7 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
if (bot) {
const path = (req.body?.properties?.__path ||
req.body?.properties?.path) as string | undefined;
- reply.log.warn({ ...req.headers, bot }, 'Bot detected (event)');
+ req.log.warn({ ...req.headers, bot }, 'Bot detected (event)');
await createBotEvent({
...bot,
projectId,
@@ -36,7 +36,7 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
reply.status(202).send('OK');
}
} catch (e) {
- reply.log.warn(e, 'Érror');
+ req.log.error(e, 'Failed to create bot event');
reply.status(401).send();
return;
}
diff --git a/packages/db/src/services/event.service.ts b/packages/db/src/services/event.service.ts
index 88247e5bc..999309da8 100644
--- a/packages/db/src/services/event.service.ts
+++ b/packages/db/src/services/event.service.ts
@@ -320,6 +320,7 @@ export async function getEventsCount({
interface CreateBotEventPayload {
name: string;
type: string;
+ path: string;
projectId: string;
createdAt: Date;
}
@@ -329,14 +330,17 @@ export function createBotEvent({
type,
projectId,
createdAt,
+ path,
}: CreateBotEventPayload) {
return ch.insert({
table: 'events_bots',
+ format: 'JSONEachRow',
values: [
{
name,
type,
project_id: projectId,
+ path,
created_at: formatClickhouseDate(createdAt),
},
],