diff --git a/packages/editor-ui/src/Interface.ts b/packages/editor-ui/src/Interface.ts index 7e8b6cb587..0107bc16a0 100644 --- a/packages/editor-ui/src/Interface.ts +++ b/packages/editor-ui/src/Interface.ts @@ -104,6 +104,9 @@ declare global { }; // eslint-disable-next-line @typescript-eslint/naming-convention Cypress: unknown; + Appcues?: { + track(event: string, properties?: ITelemetryTrackProperties): void; + }; } } diff --git a/packages/editor-ui/src/plugins/__tests__/telemetry.test.ts b/packages/editor-ui/src/plugins/__tests__/telemetry.test.ts index 9693f86cbb..b9faf7489c 100644 --- a/packages/editor-ui/src/plugins/__tests__/telemetry.test.ts +++ b/packages/editor-ui/src/plugins/__tests__/telemetry.test.ts @@ -8,6 +8,8 @@ let telemetry: Telemetry; let settingsStore: ReturnType; +const MOCK_VERSION_CLI = '0.0.0'; + describe('telemetry', () => { beforeAll(() => { telemetry = new Telemetry(); @@ -137,4 +139,44 @@ describe('telemetry', () => { expect(resetFunction).toHaveBeenCalledTimes(1); }); }); + + describe('track function', () => { + it('should call Rudderstack track method with correct parameters and', () => { + const trackFunction = vi.spyOn(window.rudderanalytics, 'track'); + + const event = 'testEvent'; + const properties = { test: '1' }; + const options = { withPostHog: false, withAppCues: false }; + + telemetry.track(event, properties, options); + + expect(trackFunction).toHaveBeenCalledTimes(1); + expect(trackFunction).toHaveBeenCalledWith(event, { + ...properties, + version_cli: MOCK_VERSION_CLI, + }); + }); + + it('should call Rudderstack track method with correct parameters and withAppCues option set to true', () => { + window.Appcues = { track: () => {} }; + const trackFunction = vi.spyOn(window.rudderanalytics, 'track'); + const appCuesTrackFunction = vi.spyOn(window.Appcues, 'track'); + + const event = 'testEvent'; + const properties = { test: '1' }; + const options = { withPostHog: false, withAppCues: true }; + + telemetry.track(event, properties, options); + + expect(trackFunction).toHaveBeenCalledTimes(1); + expect(trackFunction).toHaveBeenCalledWith(event, { + ...properties, + version_cli: MOCK_VERSION_CLI, + }); + expect(appCuesTrackFunction).toHaveBeenCalledWith(event, { + ...properties, + version_cli: MOCK_VERSION_CLI, + }); + }); + }); }); diff --git a/packages/editor-ui/src/plugins/telemetry/index.ts b/packages/editor-ui/src/plugins/telemetry/index.ts index ad33ab9cd2..dda799d279 100644 --- a/packages/editor-ui/src/plugins/telemetry/index.ts +++ b/packages/editor-ui/src/plugins/telemetry/index.ts @@ -99,7 +99,7 @@ export class Telemetry { track( event: string, properties?: ITelemetryTrackProperties, - { withPostHog } = { withPostHog: false }, + options: { withPostHog?: boolean; withAppCues?: boolean } = {}, ) { if (!this.rudderStack) return; @@ -110,9 +110,13 @@ export class Telemetry { this.rudderStack.track(event, updatedProperties); - if (withPostHog) { + if (options.withPostHog) { usePostHog().capture(event, updatedProperties); } + + if (options.withAppCues && window.Appcues) { + window.Appcues.track(event, updatedProperties); + } } page(route: Route) { diff --git a/packages/editor-ui/src/views/NodeView.vue b/packages/editor-ui/src/views/NodeView.vue index d35da15ba4..93ee597da4 100644 --- a/packages/editor-ui/src/views/NodeView.vue +++ b/packages/editor-ui/src/views/NodeView.vue @@ -3218,6 +3218,7 @@ export default defineComponent({ }, { withPostHog: true, + withAppCues: true, }, ); }