From f29d5db4f9ff184cea237180a0968a142f977e07 Mon Sep 17 00:00:00 2001 From: Brett Hoerner Date: Mon, 25 Mar 2024 15:22:23 -0600 Subject: [PATCH] chore(plugin-server): add property for anonymized created_at --- .../src/worker/ingestion/process-event.ts | 12 ++++++++++-- plugin-server/tests/main/process-event.test.ts | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/plugin-server/src/worker/ingestion/process-event.ts b/plugin-server/src/worker/ingestion/process-event.ts index 5d6a9a4191334..88b7b0f3968fa 100644 --- a/plugin-server/src/worker/ingestion/process-event.ts +++ b/plugin-server/src/worker/ingestion/process-event.ts @@ -213,6 +213,14 @@ export class EventsProcessor { }) // TODO: Remove Redis caching for person that's not used anymore + let createdAt = DateTime.utc() + let personCreatedAt = person.created_at + if (properties['$truncate_created_at']) { + // Some customers don't want accurate timestamps around their events for privacy reasons. + createdAt = createdAt.startOf('day') + personCreatedAt = personCreatedAt.startOf('day') + } + const rawEvent: RawClickHouseEvent = { uuid, event: safeClickhouseString(event), @@ -221,10 +229,10 @@ export class EventsProcessor { team_id: teamId, distinct_id: safeClickhouseString(distinctId), elements_chain: safeClickhouseString(elementsChain), - created_at: castTimestampOrNow(null, TimestampFormat.ClickHouse), + created_at: castTimestampOrNow(createdAt, TimestampFormat.ClickHouse), person_id: person.uuid, person_properties: eventPersonProperties ?? undefined, - person_created_at: castTimestampOrNow(person.created_at, TimestampFormat.ClickHouseSecondPrecision), + person_created_at: castTimestampOrNow(personCreatedAt, TimestampFormat.ClickHouseSecondPrecision), ...groupsColumns, } diff --git a/plugin-server/tests/main/process-event.test.ts b/plugin-server/tests/main/process-event.test.ts index 71432287879c3..45b92a5ba6e75 100644 --- a/plugin-server/tests/main/process-event.test.ts +++ b/plugin-server/tests/main/process-event.test.ts @@ -1997,6 +1997,21 @@ test('team event_properties', async () => { ]) }) +test('$truncate_created_at', async () => { + await processEvent( + 'xxx', + '', + '', + { event: 'event name', properties: { $truncate_created_at: true } } as any as PluginEvent, + team.id, + now, + new UUIDT().toString() + ) + const [event] = await hub.db.fetchEvents() + expect(event.created_at).toEqual(DateTime.utc().startOf('day')) + expect(event.person_created_at).toEqual(DateTime.utc().startOf('day')) +}) + test('event name object json', async () => { await processEvent( 'xxx',