fix(editor): Send correct telemetry events in credential setup (no-changelog) (#7926)

Send the `User opened cred setup` and `User closed cred setup` events
specified
[here](https://www.notion.so/n8n/Handoff-a1150c38f6e042db91fdf61c56900967?pvs=4)
This commit is contained in:
Tomi Turtiainen 2023-12-07 17:25:33 +02:00 committed by GitHub
parent 04cabafef7
commit dc1f14b0be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 10 deletions

View file

@ -9,10 +9,12 @@ import SetupTemplateFormStep from './SetupTemplateFormStep.vue';
import TemplatesView from '../TemplatesView.vue';
import { VIEWS } from '@/constants';
import { useI18n } from '@/composables/useI18n';
import { useTelemetry } from '@/composables/useTelemetry';
// Store
const setupTemplateStore = useSetupTemplateStore();
const i18n = useI18n();
const telemetry = useTelemetry();
// Router
const route = useRoute();
@ -58,14 +60,17 @@ const onSkipSetup = async (event: MouseEvent) => {
const skipIfTemplateHasNoCreds = async () => {
const isTemplateLoaded = !!setupTemplateStore.template;
if (!isTemplateLoaded) {
return;
return false;
}
if (setupTemplateStore.credentialUsages.length === 0) {
await setupTemplateStore.skipSetup({
router,
});
return true;
}
return false;
};
//#endregion Methods
@ -76,7 +81,12 @@ setupTemplateStore.setTemplateId(templateId.value);
onMounted(async () => {
await setupTemplateStore.init();
await skipIfTemplateHasNoCreds();
const wasSkipped = await skipIfTemplateHasNoCreds();
if (!wasSkipped) {
telemetry.track('User opened cred setup', undefined, {
withPostHog: true,
});
}
});
//#endregion Lifecycle hooks
@ -124,7 +134,7 @@ onMounted(async () => {
size="large"
:label="i18n.baseText('templateSetup.continue.button')"
:disabled="setupTemplateStore.isSaving"
@click="setupTemplateStore.createWorkflow(router)"
@click="setupTemplateStore.createWorkflow({ router })"
data-test-id="continue-button"
/>
<div v-else>

View file

@ -304,15 +304,14 @@ export const useSetupTemplateStore = defineStore('setupTemplate', () => {
const externalHooks = useExternalHooks();
const telemetry = useTelemetry();
const telemetryPayload = {
await externalHooks.run('templatesWorkflowView.openWorkflow', {
source: 'workflow',
template_id: templateId.value,
wf_template_repo_session_id: templatesStore.currentSessionId,
};
});
await externalHooks.run('templatesWorkflowView.openWorkflow', telemetryPayload);
telemetry.track('User inserted workflow template', telemetryPayload, {
withPostHog: true,
telemetry.track('User closed cred setup', {
completed: false,
});
// Replace the URL so back button doesn't come back to this setup view
@ -325,7 +324,10 @@ export const useSetupTemplateStore = defineStore('setupTemplate', () => {
/**
* Creates a workflow from the template and navigates to the workflow view.
*/
const createWorkflow = async ($router: Router) => {
const createWorkflow = async (opts: { router: Router }) => {
const { router } = opts;
const telemetry = useTelemetry();
if (!template.value) {
return;
}
@ -340,8 +342,12 @@ export const useSetupTemplateStore = defineStore('setupTemplate', () => {
workflowsStore,
);
telemetry.track('User closed cred setup', {
completed: true,
});
// Replace the URL so back button doesn't come back to this setup view
await $router.replace({
await router.replace({
name: VIEWS.WORKFLOW,
params: { name: createdWorkflow.id },
});