mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 12:44:07 -08:00
feat: Add user cloud it to telemetry (#7232)
Github issue / Community forum post (link here to close automatically):
This commit is contained in:
parent
33991e92d0
commit
60c152dc72
140
packages/editor-ui/src/plugins/__tests__/telemetry.test.ts
Normal file
140
packages/editor-ui/src/plugins/__tests__/telemetry.test.ts
Normal file
|
@ -0,0 +1,140 @@
|
||||||
|
import { SETTINGS_STORE_DEFAULT_STATE } from '@/__tests__/utils';
|
||||||
|
import { Telemetry } from '@/plugins/telemetry';
|
||||||
|
import { useSettingsStore } from '@/stores/settings.store';
|
||||||
|
import merge from 'lodash-es/merge';
|
||||||
|
import { createPinia, setActivePinia } from 'pinia';
|
||||||
|
|
||||||
|
let telemetry: Telemetry;
|
||||||
|
|
||||||
|
let settingsStore: ReturnType<typeof useSettingsStore>;
|
||||||
|
|
||||||
|
describe('telemetry', () => {
|
||||||
|
beforeAll(() => {
|
||||||
|
telemetry = new Telemetry();
|
||||||
|
setActivePinia(createPinia());
|
||||||
|
settingsStore = useSettingsStore();
|
||||||
|
telemetry.init(
|
||||||
|
{ enabled: true, config: { url: '', key: '' } },
|
||||||
|
{ versionCli: '1', instanceId: '1' },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('identify', () => {
|
||||||
|
it('Rudderstack identify method should be called when proving userId ', () => {
|
||||||
|
const identifyFunction = vi.spyOn(window.rudderanalytics, 'identify');
|
||||||
|
|
||||||
|
const userId = '1';
|
||||||
|
const instanceId = '1';
|
||||||
|
|
||||||
|
settingsStore.setSettings(
|
||||||
|
merge({}, SETTINGS_STORE_DEFAULT_STATE.settings, {
|
||||||
|
deployment: {
|
||||||
|
type: '',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
telemetry.identify(userId, instanceId);
|
||||||
|
expect(identifyFunction).toHaveBeenCalledTimes(1);
|
||||||
|
expect(identifyFunction).toHaveBeenCalledWith(`${instanceId}#${userId}`, {
|
||||||
|
instance_id: instanceId,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Rudderstack identify method should be called when proving userId and versionCli ', () => {
|
||||||
|
const identifyFunction = vi.spyOn(window.rudderanalytics, 'identify');
|
||||||
|
|
||||||
|
const userId = '1';
|
||||||
|
const instanceId = '1';
|
||||||
|
const versionCli = '1';
|
||||||
|
|
||||||
|
settingsStore.setSettings(
|
||||||
|
merge({}, SETTINGS_STORE_DEFAULT_STATE.settings, {
|
||||||
|
deployment: {
|
||||||
|
type: '',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
telemetry.identify(userId, instanceId, versionCli);
|
||||||
|
expect(identifyFunction).toHaveBeenCalledTimes(1);
|
||||||
|
expect(identifyFunction).toHaveBeenCalledWith(`${instanceId}#${userId}`, {
|
||||||
|
instance_id: instanceId,
|
||||||
|
version_cli: versionCli,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Rudderstack identify method should be called when proving userId and deployment type is cloud ', () => {
|
||||||
|
const identifyFunction = vi.spyOn(window.rudderanalytics, 'identify');
|
||||||
|
|
||||||
|
const userId = '1';
|
||||||
|
const instanceId = '1';
|
||||||
|
const versionCli = '1';
|
||||||
|
const userCloudId = '1';
|
||||||
|
|
||||||
|
settingsStore.setSettings(
|
||||||
|
merge({}, SETTINGS_STORE_DEFAULT_STATE.settings, {
|
||||||
|
n8nMetadata: {
|
||||||
|
userId: userCloudId,
|
||||||
|
},
|
||||||
|
deployment: {
|
||||||
|
type: 'cloud',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
telemetry.identify(userId, instanceId, versionCli);
|
||||||
|
expect(identifyFunction).toHaveBeenCalledTimes(1);
|
||||||
|
expect(identifyFunction).toHaveBeenCalledWith(`${instanceId}#${userId}`, {
|
||||||
|
instance_id: instanceId,
|
||||||
|
version_cli: versionCli,
|
||||||
|
user_cloud_id: userCloudId,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Rudderstack identify method should be called when proving userId and deployment type is cloud', () => {
|
||||||
|
const identifyFunction = vi.spyOn(window.rudderanalytics, 'identify');
|
||||||
|
|
||||||
|
const userId = '1';
|
||||||
|
const instanceId = '1';
|
||||||
|
const versionCli = '1';
|
||||||
|
const userCloudId = '1';
|
||||||
|
|
||||||
|
settingsStore.setSettings(
|
||||||
|
merge({}, SETTINGS_STORE_DEFAULT_STATE.settings, {
|
||||||
|
n8nMetadata: {
|
||||||
|
userId: userCloudId,
|
||||||
|
},
|
||||||
|
deployment: {
|
||||||
|
type: 'cloud',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
telemetry.identify(userId, instanceId, versionCli);
|
||||||
|
expect(identifyFunction).toHaveBeenCalledTimes(1);
|
||||||
|
expect(identifyFunction).toHaveBeenCalledWith(`${instanceId}#${userId}`, {
|
||||||
|
instance_id: instanceId,
|
||||||
|
version_cli: versionCli,
|
||||||
|
user_cloud_id: userCloudId,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Rudderstack reset method should be called when proving userId and deployment type is cloud', () => {
|
||||||
|
const resetFunction = vi.spyOn(window.rudderanalytics, 'reset');
|
||||||
|
|
||||||
|
const instanceId = '1';
|
||||||
|
|
||||||
|
settingsStore.setSettings(
|
||||||
|
merge({}, SETTINGS_STORE_DEFAULT_STATE.settings, {
|
||||||
|
deployment: {
|
||||||
|
type: '',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
telemetry.identify(instanceId);
|
||||||
|
expect(resetFunction).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -74,7 +74,15 @@ export class Telemetry {
|
||||||
}
|
}
|
||||||
|
|
||||||
identify(instanceId: string, userId?: string, versionCli?: string) {
|
identify(instanceId: string, userId?: string, versionCli?: string) {
|
||||||
const traits = { instance_id: instanceId, version_cli: versionCli };
|
const settingsStore = useSettingsStore();
|
||||||
|
const traits: { instance_id: string; version_cli?: string; user_cloud_id?: string } = {
|
||||||
|
instance_id: instanceId,
|
||||||
|
version_cli: versionCli,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (settingsStore.isCloudDeployment) {
|
||||||
|
traits.user_cloud_id = settingsStore.settings?.n8nMetadata?.userId ?? '';
|
||||||
|
}
|
||||||
if (userId) {
|
if (userId) {
|
||||||
this.rudderStack.identify(`${instanceId}#${userId}`, traits);
|
this.rudderStack.identify(`${instanceId}#${userId}`, traits);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2135,6 +2135,7 @@ export interface IN8nUISettings {
|
||||||
urlBaseEditor: string;
|
urlBaseEditor: string;
|
||||||
versionCli: string;
|
versionCli: string;
|
||||||
n8nMetadata?: {
|
n8nMetadata?: {
|
||||||
|
userId?: string;
|
||||||
[key: string]: string | number | undefined;
|
[key: string]: string | number | undefined;
|
||||||
};
|
};
|
||||||
versionNotifications: IVersionNotificationSettings;
|
versionNotifications: IVersionNotificationSettings;
|
||||||
|
|
Loading…
Reference in a new issue