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

refactor: Add telemetry to upgrade paths (no-changelog) #6313

Merged
merged 5 commits into from
May 30, 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
4 changes: 2 additions & 2 deletions packages/editor-ui/src/components/ExecutionsUsage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
import { i18n as locale } from '@/plugins/i18n';
import { DateTime } from 'luxon';
import type { CloudPlanAndUsageData } from '@/Interface';
import { CLOUD_CHANGE_PLAN_PAGE } from '@/constants';
import { computed } from 'vue';
import { useUIStore } from '@/stores';

const PROGRESS_BAR_MINIMUM_THRESHOLD = 8;

Expand Down Expand Up @@ -114,7 +114,7 @@ const maxExecutions = computed(() => {
});

const onUpgradeClicked = () => {
location.href = CLOUD_CHANGE_PLAN_PAGE;
useUIStore().goToUpgrade('canvas-nav', 'upgrade-canvas-nav', 'redirect');
};
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ import { getWorkflowPermissions } from '@/permissions';
import { useUsersStore } from '@/stores/users.store';
import { useUsageStore } from '@/stores/usage.store';
import { createEventBus } from 'n8n-design-system';
import { useCloudPlanStore } from '@/stores';

const hasChanged = (prev: string[], curr: string[]) => {
if (prev.length !== curr.length) {
Expand Down Expand Up @@ -212,6 +213,7 @@ export default defineComponent({
useUsageStore,
useWorkflowsStore,
useUsersStore,
useCloudPlanStore,
),
currentUser(): IUser | null {
return this.usersStore.currentUser;
Expand Down
21 changes: 21 additions & 0 deletions packages/editor-ui/src/stores/cloudPlan.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,31 @@ export const useCloudPlanStore = defineStore('cloudPlan', () => {
return usage;
};

const usageLeft = computed(() => {
if (!state.data || !state.usage) return { workflowsLeft: -1, executionsLeft: -1 };

return {
workflowsLeft: state.data.activeWorkflowsLimit - state.usage.activeWorkflows,
executionsLeft: state.data.monthlyExecutionsLimit - state.usage.executions,
};
});

const trialDaysLeft = computed(() => {
if (!state.data?.expirationDate) return -1;

const differenceInMs = new Date().valueOf() - new Date(state.data.expirationDate).valueOf();

const differenceInDays = Math.floor(differenceInMs / (1000 * 60 * 60 * 24));

return Math.ceil(differenceInDays);
});

return {
state,
getOwnerCurrentPLan,
getInstanceCurrentUsage,
usageLeft,
trialDaysLeft,
userIsTrialing,
currentPlanData,
currentUsageData,
Expand Down
20 changes: 18 additions & 2 deletions packages/editor-ui/src/stores/ui.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ import { getCurlToJson } from '@/api/curlHelper';
import { useWorkflowsStore } from './workflows.store';
import { useSettingsStore } from './settings.store';
import { useUsageStore } from './usage.store';
import { useCloudPlanStore } from './cloudPlan.store';
import type { BaseTextKey } from '@/plugins/i18n';
import { i18n as locale } from '@/plugins/i18n';
import { useTelemetryStore } from '@/stores/telemetry.store';

export const useUIStore = defineStore(STORES.UI, {
state: (): UIState => ({
Expand Down Expand Up @@ -479,8 +481,22 @@ export const useUIStore = defineStore(STORES.UI, {
const rootStore = useRootStore();
return getCurlToJson(rootStore.getRestApiContext, curlCommand);
},
goToUpgrade(source: string, utm_campaign: string): void {
window.open(this.upgradeLinkUrl(source, utm_campaign), '_blank');
goToUpgrade(source: string, utm_campaign: string, mode: 'open' | 'redirect' = 'open'): void {
const { usageLeft, trialDaysLeft, userIsTrialing } = useCloudPlanStore();
const { executionsLeft, workflowsLeft } = usageLeft;
useTelemetryStore().track('User clicked upgrade CTA', {
source,
isTrial: userIsTrialing,
deploymentType: useSettingsStore().deploymentType,
trialDaysLeft,
executionsLeft,
workflowsLeft,
});
if (mode === 'open') {
window.open(this.upgradeLinkUrl(source, utm_campaign), '_blank');
} else {
location.href = this.upgradeLinkUrl(source, utm_campaign);
}
},
},
});
9 changes: 5 additions & 4 deletions packages/editor-ui/src/views/SettingsApiView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ import CopyInput from '@/components/CopyInput.vue';
import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/settings.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useUIStore } from '@/stores/ui.store';
import { useUsersStore } from '@/stores/users.store';
import { useCloudPlanStore } from '@/stores/cloudPlan.store';
import { DOCS_DOMAIN, MODAL_CONFIRM } from '@/constants';
import { useCloudPlanStore } from '@/stores';
import { CLOUD_CHANGE_PLAN_PAGE } from '@/constants';

export default defineComponent({
name: 'SettingsApiView',
Expand All @@ -104,6 +104,7 @@ export default defineComponent({
return {
...useToast(),
...useMessage(),
...useUIStore(),
};
},
data() {
Expand All @@ -126,7 +127,7 @@ export default defineComponent({
: `https://${DOCS_DOMAIN}/api/api-reference/`;
},
computed: {
...mapStores(useRootStore, useSettingsStore, useUsersStore, useCloudPlanStore),
...mapStores(useRootStore, useSettingsStore, useUsersStore, useCloudPlanStore, useUIStore),
currentUser(): IUser | null {
return this.usersStore.currentUser;
},
Expand All @@ -139,7 +140,7 @@ export default defineComponent({
},
methods: {
onUpgrade() {
location.href = CLOUD_CHANGE_PLAN_PAGE;
this.uiStore.goToUpgrade('settings-n8n-api', 'upgrade-api', 'redirect');
},
async showDeleteModal() {
const confirmed = await this.confirm(
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/views/SettingsUsersView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default defineComponent({
}
},
goToUpgrade() {
this.uiStore.goToUpgrade('users', 'upgrade-users');
this.uiStore.goToUpgrade('settings-users', 'upgrade-users');
},
},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/views/VariablesView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ async function deleteVariable(data: EnvironmentVariable) {
}

function goToUpgrade() {
window.open(upgradeLinkUrl.value, '_blank');
uiStore.goToUpgrade('variables', 'upgrade-variables');
}

function displayName(resource: EnvironmentVariable) {
Expand Down