From 38cef9d1330063f9f68083a61348f4201dec6282 Mon Sep 17 00:00:00 2001 From: Romeo Balta <7095569+romeobalta@users.noreply.github.com> Date: Fri, 1 Aug 2025 10:25:16 +0100 Subject: [PATCH] fix(editor): Send posthog session id to rudderstack (no-changelog) (#17867) --- packages/frontend/editor-ui/src/Interface.ts | 1 + .../editor-ui/src/plugins/telemetry.test.ts | 24 +++++++++++++++++++ .../editor-ui/src/plugins/telemetry/index.ts | 3 +++ 3 files changed, 28 insertions(+) diff --git a/packages/frontend/editor-ui/src/Interface.ts b/packages/frontend/editor-ui/src/Interface.ts index c2d33378d7..84a6080520 100644 --- a/packages/frontend/editor-ui/src/Interface.ts +++ b/packages/frontend/editor-ui/src/Interface.ts @@ -111,6 +111,7 @@ declare global { set?(metadata: IDataObject): void; }; debug?(): void; + get_session_id?(): string | null; }; analytics?: { identify(userId: string): void; diff --git a/packages/frontend/editor-ui/src/plugins/telemetry.test.ts b/packages/frontend/editor-ui/src/plugins/telemetry.test.ts index 42dd60fca9..bf9a88ef0e 100644 --- a/packages/frontend/editor-ui/src/plugins/telemetry.test.ts +++ b/packages/frontend/editor-ui/src/plugins/telemetry.test.ts @@ -203,5 +203,29 @@ describe('telemetry', () => { { context: { ip: '0.0.0.0' } }, ); }); + + it('should include the posthog session id in the parameters', () => { + const trackFunction = vi.spyOn(window.rudderanalytics, 'track'); + vi.stubGlobal('posthog', { + init: vi.fn(), + get_session_id: vi.fn().mockReturnValue('test_session_id'), + }); + + const event = 'testEvent'; + const properties = { test: '1' }; + + telemetry.track(event, properties); + + expect(trackFunction).toHaveBeenCalledTimes(1); + expect(trackFunction).toHaveBeenCalledWith( + event, + expect.objectContaining({ + posthog_session_id: 'test_session_id', + }), + expect.any(Object), + ); + + vi.unstubAllGlobals(); + }); }); }); diff --git a/packages/frontend/editor-ui/src/plugins/telemetry/index.ts b/packages/frontend/editor-ui/src/plugins/telemetry/index.ts index 3edddf5fdc..7307ce0b51 100644 --- a/packages/frontend/editor-ui/src/plugins/telemetry/index.ts +++ b/packages/frontend/editor-ui/src/plugins/telemetry/index.ts @@ -99,9 +99,12 @@ export class Telemetry { track(event: string, properties?: ITelemetryTrackProperties) { if (!this.rudderStack) return; + const posthogSessionId = window.posthog?.get_session_id?.(); + const updatedProperties = { ...properties, version_cli: useRootStore().versionCli, + posthog_session_id: posthogSessionId, }; this.rudderStack.track(event, updatedProperties, {