From 5d7900dfd592d0aa0fcd3419b6fd38fa02a969c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Far=C3=ADas=20Santana?= Date: Fri, 21 Apr 2023 11:31:59 +0200 Subject: [PATCH] feat: Add sent-at property during normalizeEvent (#15151) --- plugin-server/src/utils/event.ts | 4 ++++ plugin-server/tests/utils/event.test.ts | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/plugin-server/src/utils/event.ts b/plugin-server/src/utils/event.ts index 599ab990daf..5374014d39d 100644 --- a/plugin-server/src/utils/event.ts +++ b/plugin-server/src/utils/event.ts @@ -84,6 +84,10 @@ export function normalizeEvent(event: PluginEvent): PluginEvent { if (!['$snapshot', '$performance_event'].includes(event.event)) { properties = personInitialAndUTMProperties(properties) } + if (event.sent_at) { + properties['$sent_at'] = event.sent_at + } + event.properties = properties return event } diff --git a/plugin-server/tests/utils/event.test.ts b/plugin-server/tests/utils/event.test.ts index 8975c270be9..74bee4ffa23 100644 --- a/plugin-server/tests/utils/event.test.ts +++ b/plugin-server/tests/utils/event.test.ts @@ -20,8 +20,8 @@ describe('normalizeEvent()', () => { const event = { distinct_id: 'something' } expect(normalizeEvent(event as any).properties).toEqual({}) - const event2 = { distinct_id: 'something', properties: { a: 1 } } - expect(normalizeEvent(event2 as any).properties).toEqual({ a: 1 }) + const event2 = { distinct_id: 'something', properties: { a: 1 }, sent_at: '2020-02-23T02:15:00.000Z' } + expect(normalizeEvent(event2 as any).properties).toEqual({ a: 1, $sent_at: '2020-02-23T02:15:00.000Z' }) }) it('combines .properties $set and $set_once with top-level $set and $set_once', () => { @@ -127,7 +127,7 @@ describe('formPipelineEvent()', () => { sent_at: '2020-02-23T02:15:00Z', token: 'phc_sometoken', event: 'some-event', - properties: { foo: 123, $set: {}, $set_once: {} }, + properties: { foo: 123, $set: {}, $set_once: {}, $sent_at: '2020-02-23T02:15:00Z' }, timestamp: '2020-02-24T02:15:00Z', offset: 0, $set: {}, @@ -178,7 +178,7 @@ describe('formPipelineEvent()', () => { sent_at: '2020-02-23T02:15:00Z', token: 'phc_sometoken', event: 'some-event', - properties: { foo: 123, $set: {}, $set_once: {} }, + properties: { foo: 123, $set: {}, $set_once: {}, $sent_at: '2020-02-23T02:15:00Z' }, timestamp: '2020-02-24T02:15:00Z', offset: 0, $set: {},