fix(editor): Send posthog session id to rudderstack (no-changelog) (#17867)

This commit is contained in:
Romeo Balta
2025-08-01 10:25:16 +01:00
committed by GitHub
parent f150343141
commit 38cef9d133
3 changed files with 28 additions and 0 deletions

View File

@@ -111,6 +111,7 @@ declare global {
set?(metadata: IDataObject): void;
};
debug?(): void;
get_session_id?(): string | null;
};
analytics?: {
identify(userId: string): void;

View File

@@ -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();
});
});
});

View File

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