Files
n8n-enterprise-unlocked/packages/editor-ui/src/components/Telemetry.vue
Milorad FIlipović 5059c57f4a refactor(editor): Refactor utils files and mixins (#4654)
*  Added `utils` module. Moved `canvasHelpers` and old `utils.ts` file to it
*  Moved rest of utils and helpers
*  Fixing sytax errors
* 🔨 Refactoring new utils files
* 🔨 Organizing imports, adding comments and a bit more refactoring
* ✔️ Fixing tests
* 🔨 Moving mixins to `src`
2022-11-23 13:41:53 +01:00

85 lines
1.9 KiB
Vue

<template>
<fragment></fragment>
</template>
<script lang="ts">
import { useRootStore } from '@/stores/n8nRootStore';
import { useSettingsStore } from '@/stores/settings';
import { useUsersStore } from '@/stores/users';
import { ITelemetrySettings } from 'n8n-workflow';
import { mapStores } from 'pinia';
import mixins from 'vue-typed-mixins';
import { externalHooks } from '@/mixins/externalHooks';
export default mixins(externalHooks).extend({
name: 'Telemetry',
data() {
return {
isTelemetryInitialized: false,
};
},
computed: {
...mapStores(
useRootStore,
useSettingsStore,
useUsersStore,
),
currentUserId(): string {
return this.usersStore.currentUserId || '';
},
isTelemetryEnabledOnRoute(): boolean {
return this.$route.meta && this.$route.meta.telemetry ? !this.$route.meta.telemetry.disabled: true;
},
telemetry(): ITelemetrySettings {
return this.settingsStore.telemetry;
},
isTelemetryEnabled(): boolean {
return !!this.telemetry?.enabled;
},
},
mounted() {
this.init();
},
methods: {
init() {
if (this.isTelemetryInitialized || !this.isTelemetryEnabledOnRoute || !this.isTelemetryEnabled) return;
this.$telemetry.init(
this.telemetry,
{
instanceId: this.rootStore.instanceId,
userId: this.currentUserId,
versionCli: this.rootStore.versionCli,
},
);
this.$externalHooks().run('telemetry.currentUserIdChanged', {
instanceId: this.rootStore.instanceId,
userId: this.currentUserId,
});
this.isTelemetryInitialized = true;
},
},
watch: {
telemetry() {
this.init();
},
currentUserId(userId) {
if (this.isTelemetryEnabled) {
this.$telemetry.identify(this.rootStore.instanceId, userId);
}
this.$externalHooks().run('telemetry.currentUserIdChanged', {
instanceId: this.rootStore.instanceId,
userId,
});
},
isTelemetryEnabledOnRoute(enabled) {
if (enabled) {
this.init();
}
},
},
});
</script>