From 7c05a54ffe4e43d7fd089154bb60b91488d75603 Mon Sep 17 00:00:00 2001 From: Brian Cao Date: Tue, 30 Aug 2022 17:29:30 -0700 Subject: [PATCH] allow event data CH --- db/clickhouse/migrations/01_init/migration.sql | 2 +- queries/analytics/event/saveEvent.js | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/db/clickhouse/migrations/01_init/migration.sql b/db/clickhouse/migrations/01_init/migration.sql index d83ebdab..2cca9b84 100644 --- a/db/clickhouse/migrations/01_init/migration.sql +++ b/db/clickhouse/migrations/01_init/migration.sql @@ -94,7 +94,7 @@ CREATE TABLE event created_at DateTime('UTC'), url String, event_name String, - event_data String + event_data JSON ) engine = MergeTree PRIMARY KEY (event_uuid, created_at) ORDER BY (event_uuid, created_at) diff --git a/queries/analytics/event/saveEvent.js b/queries/analytics/event/saveEvent.js index 6391868c..2c09f05d 100644 --- a/queries/analytics/event/saveEvent.js +++ b/queries/analytics/event/saveEvent.js @@ -31,15 +31,19 @@ async function relationalQuery(website_id, { session_id, url, event_name, event_ }); } -async function clickhouseQuery(website_id, { event_uuid, session_uuid, url, event_name }) { +async function clickhouseQuery( + website_id, + { event_uuid, session_uuid, url, event_name, event_data }, +) { const { getDateFormat, sendMessage } = kafka; const params = { - event_uuid: event_uuid, - website_id: website_id, - session_uuid: session_uuid, + event_uuid, + website_id, + session_uuid, created_at: getDateFormat(new Date()), url: url?.substring(0, URL_LENGTH), event_name: event_name?.substring(0, EVENT_NAME_LENGTH), + event_data: JSON.stringify(event_data), }; await sendMessage(params, 'event');