From 794371d052a7e64048c2cd7dbe59f9c595a5fc30 Mon Sep 17 00:00:00 2001 From: Mutasem Aldmour Date: Wed, 6 Dec 2023 17:49:54 +0100 Subject: [PATCH 1/4] feat: Add Appcues tracking for event --- packages/editor-ui/src/Interface.ts | 3 +++ packages/editor-ui/src/plugins/telemetry/index.ts | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/editor-ui/src/Interface.ts b/packages/editor-ui/src/Interface.ts index 7e8b6cb5877d8..9a61383e2436f 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/telemetry/index.ts b/packages/editor-ui/src/plugins/telemetry/index.ts index ad33ab9cd288d..b9222fe6cd818 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 }, + { withPostHog, withAppCues } = { withPostHog: false, withAppCues }, ) { if (!this.rudderStack) return; @@ -113,6 +113,10 @@ export class Telemetry { if (withPostHog) { usePostHog().capture(event, updatedProperties); } + + if (withAppCues && window.Appcues) { + window.Appcues.track(event, updatedProperties); + } } page(route: Route) { From 6b8b3a8f1065bf76ded148d9fe82846f0e205d8b Mon Sep 17 00:00:00 2001 From: Mutasem Aldmour Date: Wed, 6 Dec 2023 17:50:05 +0100 Subject: [PATCH 2/4] feat: Add Appcues tracking for event --- packages/editor-ui/src/views/NodeView.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/editor-ui/src/views/NodeView.vue b/packages/editor-ui/src/views/NodeView.vue index d35da15ba4312..93ee597da4394 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, }, ); } From 9dec055e840053f6ded6f4c3c7ccfd26a2dec868 Mon Sep 17 00:00:00 2001 From: Mutasem Aldmour Date: Wed, 6 Dec 2023 18:14:45 +0100 Subject: [PATCH 3/4] test: add tests for event tracking --- .../src/plugins/__tests__/telemetry.test.ts | 33 +++++++++++++++++++ .../editor-ui/src/plugins/telemetry/index.ts | 6 ++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/packages/editor-ui/src/plugins/__tests__/telemetry.test.ts b/packages/editor-ui/src/plugins/__tests__/telemetry.test.ts index 9693f86cbbf0f..45cd8ac8d28d1 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,35 @@ 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 b9222fe6cd818..8400cac95a001 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, withAppCues } = { withPostHog: false, withAppCues }, + options: { withPostHog?: boolean, withAppCues?: boolean } = {}, ) { if (!this.rudderStack) return; @@ -110,11 +110,11 @@ export class Telemetry { this.rudderStack.track(event, updatedProperties); - if (withPostHog) { + if (options.withPostHog) { usePostHog().capture(event, updatedProperties); } - if (withAppCues && window.Appcues) { + if (options.withAppCues && window.Appcues) { window.Appcues.track(event, updatedProperties); } } From c930e68bc3f01604fe1543e09438e08995836b0e Mon Sep 17 00:00:00 2001 From: Mutasem Aldmour Date: Thu, 7 Dec 2023 11:28:11 +0100 Subject: [PATCH 4/4] fix: lint --- packages/editor-ui/src/Interface.ts | 2 +- .../src/plugins/__tests__/telemetry.test.ts | 17 +++++++++++++---- .../editor-ui/src/plugins/telemetry/index.ts | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/editor-ui/src/Interface.ts b/packages/editor-ui/src/Interface.ts index 9a61383e2436f..0107bc16a0aca 100644 --- a/packages/editor-ui/src/Interface.ts +++ b/packages/editor-ui/src/Interface.ts @@ -106,7 +106,7 @@ declare global { 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 45cd8ac8d28d1..b9faf7489cf1f 100644 --- a/packages/editor-ui/src/plugins/__tests__/telemetry.test.ts +++ b/packages/editor-ui/src/plugins/__tests__/telemetry.test.ts @@ -151,11 +151,14 @@ describe('telemetry', () => { telemetry.track(event, properties, options); expect(trackFunction).toHaveBeenCalledTimes(1); - expect(trackFunction).toHaveBeenCalledWith(event, { ...properties, version_cli: MOCK_VERSION_CLI }); + 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: () => { } }; + window.Appcues = { track: () => {} }; const trackFunction = vi.spyOn(window.rudderanalytics, 'track'); const appCuesTrackFunction = vi.spyOn(window.Appcues, 'track'); @@ -166,8 +169,14 @@ describe('telemetry', () => { 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 }); + 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 8400cac95a001..dda799d2796b9 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, - options: { withPostHog?: boolean, withAppCues?: boolean } = {}, + options: { withPostHog?: boolean; withAppCues?: boolean } = {}, ) { if (!this.rudderStack) return;