From 1eff790fe851cbfabc0f09b2f4b3a6d6658113ca Mon Sep 17 00:00:00 2001 From: Dean Date: Wed, 20 Apr 2022 11:08:06 +0100 Subject: [PATCH] Added events for viewing a production application and unpublishing --- packages/builder/src/analytics/constants.js | 7 +++++++ .../builder/src/components/deploy/DeployModal.svelte | 6 +++++- packages/builder/src/components/start/AppRow.svelte | 5 ----- .../src/pages/builder/app/[application]/_layout.svelte | 8 ++++++++ .../builder/src/pages/builder/portal/apps/index.svelte | 9 ++++++++- packages/server/src/api/controllers/application.js | 9 +++++---- 6 files changed, 33 insertions(+), 11 deletions(-) diff --git a/packages/builder/src/analytics/constants.js b/packages/builder/src/analytics/constants.js index 177d5320a5..780bbcd46d 100644 --- a/packages/builder/src/analytics/constants.js +++ b/packages/builder/src/analytics/constants.js @@ -35,6 +35,7 @@ export const Events = { CREATED: "budibase:app_created", PUBLISHED: "budibase:app_published", UNPUBLISHED: "budibase:app_unpublished", + VIEW_PUBLISHED: "budibase:view_published_app", }, ANALYTICS: { OPT_IN: "budibase:analytics_opt_in", @@ -50,3 +51,9 @@ export const Events = { SAVED: "budibase:sso_saved", }, } + +export const EventSource = { + PORTAL: "portal", + URL: "url", + NOTIFICATION: "notification", +} diff --git a/packages/builder/src/components/deploy/DeployModal.svelte b/packages/builder/src/components/deploy/DeployModal.svelte index f2b996e799..833034ddda 100644 --- a/packages/builder/src/components/deploy/DeployModal.svelte +++ b/packages/builder/src/components/deploy/DeployModal.svelte @@ -7,7 +7,7 @@ Layout, } from "@budibase/bbui" import { API } from "api" - import analytics, { Events } from "analytics" + import analytics, { Events, EventSource } from "analytics" import { store } from "builderStore" import { ProgressCircle } from "@budibase/bbui" import CopyInput from "components/common/inputs/CopyInput.svelte" @@ -49,6 +49,10 @@ const viewApp = () => { if (published) { + analytics.captureEvent(Events.APP.VIEW_PUBLISHED, { + appId: $store.appId, + eventSource: EventSource.PORTAL, + }) window.open(publishedUrl, "_blank") } } diff --git a/packages/builder/src/components/start/AppRow.svelte b/packages/builder/src/components/start/AppRow.svelte index b30bc6491f..b87728672f 100644 --- a/packages/builder/src/components/start/AppRow.svelte +++ b/packages/builder/src/components/start/AppRow.svelte @@ -90,11 +90,6 @@ - {#if app.deployed} - viewApp(app)} icon="GlobeOutline"> - View published app - - {/if} {#if app.lockedYou} releaseLock(app)} icon="LockOpen"> Release lock diff --git a/packages/builder/src/pages/builder/app/[application]/_layout.svelte b/packages/builder/src/pages/builder/app/[application]/_layout.svelte index c3c2be4ad2..22184d93a5 100644 --- a/packages/builder/src/pages/builder/app/[application]/_layout.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_layout.svelte @@ -25,6 +25,7 @@ import { onMount, onDestroy } from "svelte" import { processStringSync } from "@budibase/string-templates" import { checkIncomingDeploymentStatus } from "components/deploy/utils" + import analytics, { Events, EventSource } from "analytics" export let application @@ -73,6 +74,10 @@ } const viewApp = () => { + analytics.captureEvent(Events.APP.VIEW_PUBLISHED, { + appId: selectedApp.appId, + eventSource: EventSource.PORTAL, + }) if (selectedApp.url) { window.open(`/app${selectedApp.url}`) } else { @@ -168,6 +173,9 @@ return } try { + analytics.captureEvent(Events.APP.UNPUBLISHED, { + appId: selectedApp.appId, + }) await API.unpublishApp(selectedApp.prodId) await apps.load() notifications.success("App unpublished successfully") diff --git a/packages/builder/src/pages/builder/portal/apps/index.svelte b/packages/builder/src/pages/builder/portal/apps/index.svelte index 143ff89231..ad82869c21 100644 --- a/packages/builder/src/pages/builder/portal/apps/index.svelte +++ b/packages/builder/src/pages/builder/portal/apps/index.svelte @@ -28,7 +28,7 @@ import ConfirmDialog from "components/common/ConfirmDialog.svelte" import AppRow from "components/start/AppRow.svelte" import { AppStatus } from "constants" - import analytics, { Events } from "analytics" + import analytics, { Events, EventSource } from "analytics" import Logo from "assets/bb-space-man.svg" let sortBy = "name" @@ -167,6 +167,10 @@ } const viewApp = app => { + analytics.captureEvent(Events.APP.VIEW_PUBLISHED, { + appId: app.appId, + eventSource: EventSource.PORTAL, + }) if (app.url) { window.open(`/app${app.url}`) } else { @@ -209,6 +213,9 @@ return } try { + analytics.captureEvent(Events.APP.UNPUBLISHED, { + appId: selectedApp.appId, + }) await API.unpublishApp(selectedApp.prodId) await apps.load() notifications.success("App unpublished successfully") diff --git a/packages/server/src/api/controllers/application.js b/packages/server/src/api/controllers/application.js index 9be4760617..448415b8cb 100644 --- a/packages/server/src/api/controllers/application.js +++ b/packages/server/src/api/controllers/application.js @@ -351,19 +351,20 @@ exports.revertClient = async ctx => { exports.delete = async ctx => { let appId = ctx.params.appId + let isUnpublish = ctx.query && ctx.query.unpublish - if (ctx.query && ctx.query.unpublish) { + if (isUnpublish) { appId = getProdAppID(appId) } - const db = ctx.query.unpublish ? getProdAppDB() : getAppDB() + const db = isUnpublish ? getProdAppDB() : getAppDB() const result = await db.destroy() /* istanbul ignore next */ - if (!env.isTest() && !ctx.query.unpublish) { + if (!env.isTest() && !isUnpublish) { await deleteApp(appId) } - if (ctx.query && ctx.query.unpublish) { + if (isUnpublish) { await cleanupAutomations(appId) } // make sure the app/role doesn't stick around after the app has been deleted