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): Send template id as string in all telemetry events #8498

Merged
merged 5 commits into from
Jan 31, 2024
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: 2 additions & 1 deletion packages/editor-ui/src/mixins/workflowHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { getCredentialTypeName, isCredentialOnlyNodeType } from '@/utils/credent
import { useExternalHooks } from '@/composables/useExternalHooks';
import { useCanvasStore } from '@/stores/canvas.store';
import { useSourceControlStore } from '@/stores/sourceControl.store';
import { tryToParseNumber } from '@/utils/typesUtils';

export function getParentMainInputNode(workflow: Workflow, node: INode): INode {
const nodeType = useNodeTypesStore().getNodeType(node.type);
Expand Down Expand Up @@ -1094,7 +1095,7 @@ export const workflowHelpers = defineComponent({
const templateId = this.$route.query.templateId;
if (templateId) {
this.$telemetry.track('User saved new workflow from template', {
template_id: isNaN(+templateId) ? templateId : +templateId,
template_id: tryToParseNumber(String(templateId)),
workflow_id: workflowData.id,
wf_template_repo_session_id: this.templatesStore.previousSessionId,
});
Expand Down
9 changes: 7 additions & 2 deletions packages/editor-ui/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { useTelemetry } from '@/composables/useTelemetry';
import { middleware } from '@/rbac/middleware';
import type { RouteConfig, RouterMiddleware } from '@/types/router';
import { initializeCore } from '@/init';
import { tryToParseNumber } from '@/utils/typesUtils';

const ChangePasswordView = async () => await import('./views/ChangePasswordView.vue');
const ErrorView = async () => await import('./views/ErrorView.vue');
Expand Down Expand Up @@ -120,7 +121,9 @@ export const routes = [
getProperties(route: RouteLocation) {
const templatesStore = useTemplatesStore();
return {
template_id: route.params.id,
template_id: tryToParseNumber(
Array.isArray(route.params.id) ? route.params.id[0] : route.params.id,
),
wf_template_repo_session_id: templatesStore.currentSessionId,
};
},
Expand All @@ -142,7 +145,9 @@ export const routes = [
getProperties(route: RouteLocation) {
const templatesStore = useTemplatesStore();
return {
template_id: route.params.id,
template_id: tryToParseNumber(
Array.isArray(route.params.id) ? route.params.id[0] : route.params.id,
),
wf_template_repo_session_id: templatesStore.currentSessionId,
};
},
Expand Down
3 changes: 2 additions & 1 deletion packages/editor-ui/src/utils/templates/templateActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type { Telemetry } from '@/plugins/telemetry';
import type { useExternalHooks } from '@/composables/useExternalHooks';
import { assert } from '@/utils/assert';
import { doesNodeHaveCredentialsToFill } from '@/utils/nodes/nodeTransforms';
import { tryToParseNumber } from '@/utils/typesUtils';

type ExternalHooks = ReturnType<typeof useExternalHooks>;

Expand Down Expand Up @@ -106,7 +107,7 @@ async function openTemplateWorkflowOnNodeView(opts: {
};
const telemetryPayload = {
source: 'workflow',
template_id: templateId,
template_id: tryToParseNumber(templateId),
wf_template_repo_session_id: templatesStore.currentSessionId,
};

Expand Down
9 changes: 9 additions & 0 deletions packages/editor-ui/src/utils/typesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,12 @@ export const isValidDate = (input: string | number | Date): boolean => {

export const getObjectKeys = <T extends object, K extends keyof T>(o: T): K[] =>
Object.keys(o) as K[];

/**
* Converts a string to a number if possible. If not it returns the original string.
* For a string to be converted to a number it has to contain only digits.
* @param value The value to convert to a number
Comment on lines +161 to +163
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇 for adding docs 😻

*/
export const tryToParseNumber = (value: string): number | string => {
return isNaN(+value) ? value : +value;
};
3 changes: 2 additions & 1 deletion packages/editor-ui/src/views/NodeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ import { useSourceControlStore } from '@/stores/sourceControl.store';
import { useDeviceSupport } from 'n8n-design-system';
import { useDebounce } from '@/composables/useDebounce';
import { useCanvasPanning } from '@/composables/useCanvasPanning';
import { tryToParseNumber } from '@/utils/typesUtils';

interface AddNodeOptions {
position?: XYPosition;
Expand Down Expand Up @@ -1327,7 +1328,7 @@ export default defineComponent({
'User inserted workflow template',
{
source: 'workflow',
template_id: templateId,
template_id: tryToParseNumber(templateId),
wf_template_repo_session_id: this.templatesStore.previousSessionId,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { createWorkflowFromTemplate } from '@/utils/templates/templateActions';
import { useExternalHooks } from '@/composables/useExternalHooks';
import { useTelemetry } from '@/composables/useTelemetry';
import { useCredentialSetupState } from '@/views/SetupWorkflowFromTemplateView/useCredentialSetupState';
import { tryToParseNumber } from '@/utils/typesUtils';

export type NodeAndType = {
node: INodeUi;
Expand Down Expand Up @@ -200,14 +201,14 @@ export const useSetupTemplateStore = defineStore('setupTemplate', () => {
'User inserted workflow template',
{
source: 'workflow',
template_id: templateId.value,
template_id: tryToParseNumber(templateId.value),
wf_template_repo_session_id: templatesStore.currentSessionId,
},
{ withPostHog: true },
);

telemetry.track('User saved new workflow from template', {
template_id: isNaN(+templateId.value) ? templateId : +templateId.value,
template_id: tryToParseNumber(templateId.value),
workflow_id: createdWorkflow.id,
wf_template_repo_session_id: templatesStore.currentSessionId,
});
Expand Down
Loading