Skip to content

Commit

Permalink
Change upgrade CTA on community editions
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoE105 committed May 24, 2023
1 parent 071955b commit 2a9da66
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 30 deletions.
6 changes: 2 additions & 4 deletions packages/editor-ui/src/composables/useUpgradeLink.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import type { BaseTextKey } from '@/plugins/i18n';
import { useUIStore, useUsageStore } from '@/stores';
import { useUIStore } from '@/stores';
import { useI18n } from './useI18n';
import { computed } from 'vue';

export function useUpgradeLink(queryParams = { default: '', desktop: '' }) {
const uiStore = useUIStore();
const usageStore = useUsageStore();
const { i18n } = useI18n();

const upgradeLinkUrl = computed(() => {
const linkUrlTranslationKey = uiStore.contextBasedTranslationKeys.upgradeLinkUrl as BaseTextKey;
let url = i18n.baseText(linkUrlTranslationKey);

if (linkUrlTranslationKey.endsWith('.upgradeLinkUrl')) {
url = `${usageStore.viewPlansUrl}${queryParams.default}`;
url = `${url}${queryParams.default}`;
} else if (linkUrlTranslationKey.endsWith('.desktop')) {
url = `${url}${queryParams.desktop}`;
}

return url;
});

Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/plugins/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,7 @@
"contextual.communityNodes.unavailable.description.desktop": "Community nodes feature is unavailable on desktop. Please choose one of our available self-hosting plans.",
"contextual.communityNodes.unavailable.button.desktop": "View plans",

"contextual.upgradeLinkUrl": "https://subscription.n8n.io/",
"contextual.upgradeLinkUrl": "https://n8n.io/pricing/",
"contextual.upgradeLinkUrl.cloud": "https://app.n8n.cloud/account/change-plan",
"contextual.upgradeLinkUrl.desktop": "https://n8n.io/pricing/?utm_source=n8n-internal&utm_medium=desktop",

Expand Down
27 changes: 8 additions & 19 deletions packages/editor-ui/src/stores/ui.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ import { getCurlToJson } from '@/api/curlHelper';
import { useWorkflowsStore } from './workflows.store';
import { useSettingsStore } from './settings.store';
import { useUsageStore } from './usage.store';
import type { BaseTextKey } from '@/plugins/i18n';
import { i18n as locale } from '@/plugins/i18n';
import { useUpgradeLink } from '@/composables';
import { useTelemetry } from '@/composables';

export const useUIStore = defineStore(STORES.UI, {
state: (): UIState => ({
Expand Down Expand Up @@ -314,22 +314,6 @@ export const useUIStore = defineStore(STORES.UI, {
return false;
};
},
upgradeLinkUrl() {
return (source: string, utm_campaign: string): string => {
const usageStore = useUsageStore();
const linkUrlTranslationKey = this.contextBasedTranslationKeys
.upgradeLinkUrl as BaseTextKey;
let linkUrl = locale.baseText(linkUrlTranslationKey);

if (linkUrlTranslationKey.endsWith('.upgradeLinkUrl')) {
linkUrl = `${usageStore.viewPlansUrl}&source=${source}`;
} else if (linkUrlTranslationKey.endsWith('.desktop')) {
linkUrl = `${linkUrl}&utm_campaign=${utm_campaign || source}`;
}

return linkUrl;
};
},
},
actions: {
setMode(name: string, mode: string): void {
Expand Down Expand Up @@ -480,7 +464,12 @@ export const useUIStore = defineStore(STORES.UI, {
return getCurlToJson(rootStore.getRestApiContext, curlCommand);
},
goToUpgrade(source: string, utm_campaign: string): void {
window.open(this.upgradeLinkUrl(source, utm_campaign), '_blank');
const { upgradeLinkUrl } = useUpgradeLink();
useTelemetry().track('User clicked on paywall CTA', { source });
window.open(
`${upgradeLinkUrl.value}?source=${source}&utm_campaign=${utm_campaign}`,
'_blank',
);
},
},
});
8 changes: 2 additions & 6 deletions packages/editor-ui/src/views/VariablesView.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts" setup>
import { computed, ref } from 'vue';
import { useEnvironmentsStore, useUIStore, useSettingsStore, useUsersStore } from '@/stores';
import { useI18n, useTelemetry, useToast, useUpgradeLink, useMessage } from '@/composables';
import { useI18n, useTelemetry, useToast, useMessage } from '@/composables';
import ResourcesListLayout from '@/components/layouts/ResourcesListLayout.vue';
import VariablesRow from '@/components/VariablesRow.vue';
Expand Down Expand Up @@ -70,10 +70,6 @@ const datatableColumns = computed<DatatableColumn[]>(() => [
]);
const contextBasedTranslationKeys = computed(() => uiStore.contextBasedTranslationKeys);
const { upgradeLinkUrl } = useUpgradeLink({
default: '&source=variables',
desktop: '&utm_campaign=upgrade-variables',
});
const newlyAddedVariableIds = ref<number[]>([]);
Expand Down Expand Up @@ -201,7 +197,7 @@ async function deleteVariable(data: EnvironmentVariable) {
}
function goToUpgrade() {
window.open(upgradeLinkUrl.value, '_blank');
uiStore.goToUpgrade('variables', 'upgrade-variables');
}
function displayName(resource: EnvironmentVariable) {
Expand Down

0 comments on commit 2a9da66

Please sign in to comment.