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

This commit is contained in:
Iván Ovejero
2023-05-30 15:49:27 +02:00
committed by GitHub
parent 54e3838dae
commit f91d36cd30
7 changed files with 50 additions and 10 deletions

View File

@@ -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,

View File

@@ -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 => ({
@@ -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);
}
},
},
});