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, {