Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(editor): Add AppCues tracking for onboarding event #7945

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/editor-ui/src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ declare global {
};
// eslint-disable-next-line @typescript-eslint/naming-convention
Cypress: unknown;
Appcues?: {
track(event: string, properties?: ITelemetryTrackProperties): void;
};
}
}

Expand Down
42 changes: 42 additions & 0 deletions packages/editor-ui/src/plugins/__tests__/telemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ let telemetry: Telemetry;

let settingsStore: ReturnType<typeof useSettingsStore>;

const MOCK_VERSION_CLI = '0.0.0';

describe('telemetry', () => {
beforeAll(() => {
telemetry = new Telemetry();
Expand Down Expand Up @@ -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,
});
});
});
});
8 changes: 6 additions & 2 deletions packages/editor-ui/src/plugins/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class Telemetry {
track(
event: string,
properties?: ITelemetryTrackProperties,
{ withPostHog } = { withPostHog: false },
options: { withPostHog?: boolean; withAppCues?: boolean } = {},
) {
if (!this.rudderStack) return;

Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions packages/editor-ui/src/views/NodeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3218,6 +3218,7 @@ export default defineComponent({
},
{
withPostHog: true,
withAppCues: true,
},
);
}
Expand Down
Loading