Browse Source

feat: introduce more events into the analytics pipeline (#3156)

Andrew Bastin 1 year ago
parent
commit
8c0aff8863

+ 8 - 0
packages/hoppscotch-common/src/components/collections/ImportExport.vue

@@ -284,6 +284,14 @@ const importerAction = async (stepResults: StepReturnValue[]) => {
           emit("import-to-teams", result)
         } else {
           appendRESTCollections(result)
+
+          platform.analytics?.logEvent({
+            type: "HOPP_IMPORT_COLLECTION",
+            importer: importerModule.value!.name,
+            platform: "rest",
+            workspaceType: "personal",
+          })
+
           fileImported()
         }
       }

+ 64 - 0
packages/hoppscotch-common/src/components/collections/SaveRequest.vue

@@ -89,6 +89,7 @@ import {
 import { GQLError } from "~/helpers/backend/GQLClient"
 import { computedWithControl } from "@vueuse/core"
 import { currentActiveTab } from "~/helpers/rest/tab"
+import { platform } from "~/platform"
 
 const t = useI18n()
 const toast = useToast()
@@ -223,6 +224,13 @@ const saveRequestAs = async () => {
       },
     }
 
+    platform.analytics?.logEvent({
+      type: "HOPP_SAVE_REQUEST",
+      createdNow: true,
+      platform: "rest",
+      workspaceType: "personal",
+    })
+
     requestSaved()
   } else if (picked.value.pickedType === "my-folder") {
     if (!isHoppRESTRequest(requestUpdated))
@@ -243,6 +251,13 @@ const saveRequestAs = async () => {
       },
     }
 
+    platform.analytics?.logEvent({
+      type: "HOPP_SAVE_REQUEST",
+      createdNow: true,
+      platform: "rest",
+      workspaceType: "personal",
+    })
+
     requestSaved()
   } else if (picked.value.pickedType === "my-request") {
     if (!isHoppRESTRequest(requestUpdated))
@@ -264,17 +279,38 @@ const saveRequestAs = async () => {
       },
     }
 
+    platform.analytics?.logEvent({
+      type: "HOPP_SAVE_REQUEST",
+      createdNow: false,
+      platform: "rest",
+      workspaceType: "personal",
+    })
+
     requestSaved()
   } else if (picked.value.pickedType === "teams-collection") {
     if (!isHoppRESTRequest(requestUpdated))
       throw new Error("requestUpdated is not a REST Request")
 
     updateTeamCollectionOrFolder(picked.value.collectionID, requestUpdated)
+
+    platform.analytics?.logEvent({
+      type: "HOPP_SAVE_REQUEST",
+      createdNow: true,
+      platform: "rest",
+      workspaceType: "team",
+    })
   } else if (picked.value.pickedType === "teams-folder") {
     if (!isHoppRESTRequest(requestUpdated))
       throw new Error("requestUpdated is not a REST Request")
 
     updateTeamCollectionOrFolder(picked.value.folderID, requestUpdated)
+
+    platform.analytics?.logEvent({
+      type: "HOPP_SAVE_REQUEST",
+      createdNow: true,
+      platform: "rest",
+      workspaceType: "team",
+    })
   } else if (picked.value.pickedType === "teams-request") {
     if (!isHoppRESTRequest(requestUpdated))
       throw new Error("requestUpdated is not a REST Request")
@@ -292,6 +328,13 @@ const saveRequestAs = async () => {
       title: requestUpdated.name,
     }
 
+    platform.analytics?.logEvent({
+      type: "HOPP_SAVE_REQUEST",
+      createdNow: false,
+      platform: "rest",
+      workspaceType: "team",
+    })
+
     pipe(
       updateTeamRequest(picked.value.requestID, data),
       TE.match(
@@ -313,6 +356,13 @@ const saveRequestAs = async () => {
       requestUpdated as HoppGQLRequest
     )
 
+    platform.analytics?.logEvent({
+      type: "HOPP_SAVE_REQUEST",
+      createdNow: false,
+      platform: "gql",
+      workspaceType: "team",
+    })
+
     requestSaved()
   } else if (picked.value.pickedType === "gql-my-folder") {
     // TODO: Check for GQL request ?
@@ -321,6 +371,13 @@ const saveRequestAs = async () => {
       requestUpdated as HoppGQLRequest
     )
 
+    platform.analytics?.logEvent({
+      type: "HOPP_SAVE_REQUEST",
+      createdNow: true,
+      platform: "gql",
+      workspaceType: "team",
+    })
+
     requestSaved()
   } else if (picked.value.pickedType === "gql-my-collection") {
     // TODO: Check for GQL request ?
@@ -329,6 +386,13 @@ const saveRequestAs = async () => {
       requestUpdated as HoppGQLRequest
     )
 
+    platform.analytics?.logEvent({
+      type: "HOPP_SAVE_REQUEST",
+      createdNow: true,
+      platform: "gql",
+      workspaceType: "team",
+    })
+
     requestSaved()
   }
 }

+ 8 - 0
packages/hoppscotch-common/src/components/collections/graphql/Add.vue

@@ -46,6 +46,7 @@ import { useToast } from "@composables/toast"
 import { useI18n } from "@composables/i18n"
 import { HoppGQLRequest, makeCollection } from "@hoppscotch/data"
 import { addGraphqlCollection } from "~/newstore/collections"
+import { platform } from "~/platform"
 
 export default defineComponent({
   props: {
@@ -79,6 +80,13 @@ export default defineComponent({
       )
 
       this.hideModal()
+
+      platform.analytics?.logEvent({
+        type: "HOPP_CREATE_COLLECTION",
+        isRootCollection: true,
+        platform: "gql",
+        workspaceType: "personal",
+      })
     },
     hideModal() {
       this.name = null

+ 14 - 0
packages/hoppscotch-common/src/components/collections/graphql/ImportExport.vue

@@ -244,6 +244,14 @@ const importFromJSON = () => {
       return
     }
     appendGraphqlCollections(collections)
+
+    platform.analytics?.logEvent({
+      type: "HOPP_IMPORT_COLLECTION",
+      importer: "json",
+      workspaceType: "personal",
+      platform: "gql",
+    })
+
     fileImported()
   }
   reader.readAsText(inputChooseFileToImportFrom.value.files[0])
@@ -257,6 +265,12 @@ const exportJSON = () => {
   const url = URL.createObjectURL(file)
   a.href = url
 
+  platform?.analytics?.logEvent({
+    type: "HOPP_EXPORT_COLLECTION",
+    exporter: "json",
+    platform: "gql",
+  })
+
   // TODO: get uri from meta
   a.download = `${url.split("/").pop()!.split("#")[0].split("?")[0]}.json`
   document.body.appendChild(a)

+ 16 - 0
packages/hoppscotch-common/src/components/collections/graphql/index.vue

@@ -153,6 +153,7 @@ import IconArchive from "~icons/lucide/archive"
 import { useI18n } from "@composables/i18n"
 import { useReadonlyStream } from "@composables/stream"
 import { useColorMode } from "@composables/theming"
+import { platform } from "~/platform"
 
 export default defineComponent({
   props: {
@@ -285,6 +286,13 @@ export default defineComponent({
         response: "",
       })
 
+      platform.analytics?.logEvent({
+        type: "HOPP_SAVE_REQUEST",
+        platform: "gql",
+        createdNow: true,
+        workspaceType: "personal",
+      })
+
       this.displayModalAddRequest(false)
     },
     addRequest(payload) {
@@ -294,6 +302,14 @@ export default defineComponent({
     },
     onAddFolder({ name, path }) {
       addGraphqlFolder(name, path)
+
+      platform.analytics?.logEvent({
+        type: "HOPP_CREATE_COLLECTION",
+        isRootCollection: false,
+        platform: "gql",
+        workspaceType: "personal",
+      })
+
       this.displayModalAddFolder(false)
     },
     addFolder(payload) {

+ 61 - 0
packages/hoppscotch-common/src/components/collections/index.vue

@@ -599,11 +599,25 @@ const addNewRootCollection = (name: string) => {
       })
     )
 
+    platform.analytics?.logEvent({
+      type: "HOPP_CREATE_COLLECTION",
+      platform: "rest",
+      workspaceType: "personal",
+      isRootCollection: true,
+    })
+
     displayModalAdd(false)
   } else if (hasTeamWriteAccess.value) {
     if (!collectionsType.value.selectedTeam) return
     modalLoadingState.value = true
 
+    platform.analytics?.logEvent({
+      type: "HOPP_CREATE_COLLECTION",
+      platform: "rest",
+      workspaceType: "team",
+      isRootCollection: true,
+    })
+
     pipe(
       createNewRootCollection(name, collectionsType.value.selectedTeam.id),
       TE.match(
@@ -652,6 +666,13 @@ const onAddRequest = (requestName: string) => {
       },
     })
 
+    platform.analytics?.logEvent({
+      type: "HOPP_SAVE_REQUEST",
+      workspaceType: "personal",
+      createdNow: true,
+      platform: "rest",
+    })
+
     displayModalAddRequest(false)
   } else if (hasTeamWriteAccess.value) {
     const folder = editingFolder.value
@@ -667,6 +688,13 @@ const onAddRequest = (requestName: string) => {
       title: requestName,
     }
 
+    platform.analytics?.logEvent({
+      type: "HOPP_SAVE_REQUEST",
+      workspaceType: "team",
+      platform: "rest",
+      createdNow: true,
+    })
+
     pipe(
       createRequestInCollection(folder.id, data),
       TE.match(
@@ -712,6 +740,14 @@ const onAddFolder = (folderName: string) => {
   if (collectionsType.value.type === "my-collections") {
     if (!path) return
     addRESTFolder(folderName, path)
+
+    platform.analytics?.logEvent({
+      type: "HOPP_CREATE_COLLECTION",
+      workspaceType: "personal",
+      isRootCollection: false,
+      platform: "rest",
+    })
+
     displayModalAddFolder(false)
   } else if (hasTeamWriteAccess.value) {
     const folder = editingFolder.value
@@ -719,6 +755,13 @@ const onAddFolder = (folderName: string) => {
 
     modalLoadingState.value = true
 
+    platform.analytics?.logEvent({
+      type: "HOPP_CREATE_COLLECTION",
+      workspaceType: "personal",
+      isRootCollection: false,
+      platform: "rest",
+    })
+
     pipe(
       createChildCollection(folderName, folder.id),
       TE.match(
@@ -1884,6 +1927,12 @@ const exportData = async (
 }
 
 const exportJSONCollection = async () => {
+  platform.analytics?.logEvent({
+    type: "HOPP_EXPORT_COLLECTION",
+    exporter: "json",
+    platform: "rest",
+  })
+
   await getJSONCollection()
 
   initializeDownloadCollection(collectionJSON.value, null)
@@ -1895,6 +1944,12 @@ const createCollectionGist = async () => {
     return
   }
 
+  platform.analytics?.logEvent({
+    type: "HOPP_EXPORT_COLLECTION",
+    exporter: "gist",
+    platform: "rest",
+  })
+
   creatingGistCollection.value = true
   await getJSONCollection()
 
@@ -1925,6 +1980,12 @@ const importToTeams = async (collection: HoppCollection<HoppRESTRequest>[]) => {
 
   importingMyCollections.value = true
 
+  platform.analytics?.logEvent({
+    type: "HOPP_EXPORT_COLLECTION",
+    exporter: "import-to-teams",
+    platform: "rest",
+  })
+
   pipe(
     importJSONToTeam(
       JSON.stringify(collection),

+ 20 - 0
packages/hoppscotch-common/src/components/environments/ImportExport.vue

@@ -190,6 +190,12 @@ const createEnvironmentGist = async () => {
     )
 
     toast.success(t("export.gist_created").toString())
+
+    platform.analytics?.logEvent({
+      type: "HOPP_EXPORT_ENVIRONMENT",
+      platform: "rest",
+    })
+
     window.open(res.data.html_url)
   } catch (e) {
     toast.error(t("error.something_went_wrong").toString())
@@ -249,6 +255,13 @@ const openDialogChooseFileToImportFrom = () => {
 
 const importToTeams = async (content: Environment[]) => {
   loading.value = true
+
+  platform.analytics?.logEvent({
+    type: "HOPP_IMPORT_ENVIRONMENT",
+    platform: "rest",
+    workspaceType: "team",
+  })
+
   for (const [i, env] of content.entries()) {
     if (i === content.length - 1) {
       await pipe(
@@ -301,6 +314,12 @@ const importFromJSON = () => {
     return
   }
 
+  platform.analytics?.logEvent({
+    type: "HOPP_IMPORT_ENVIRONMENT",
+    platform: "rest",
+    workspaceType: "personal",
+  })
+
   const reader = new FileReader()
 
   reader.onload = ({ target }) => {
@@ -352,6 +371,7 @@ const importFromPostman = ({
   const environment: Environment = { name, variables: [] }
   values.forEach(({ key, value }) => environment.variables.push({ key, value }))
   const environments = [environment]
+
   importFromHoppscotch(environments)
 }
 

+ 6 - 0
packages/hoppscotch-common/src/components/environments/my/Details.vue

@@ -148,6 +148,7 @@ import { useToast } from "@composables/toast"
 import { useReadonlyStream } from "@composables/stream"
 import { useColorMode } from "@composables/theming"
 import { environmentsStore } from "~/newstore/environments"
+import { platform } from "~/platform"
 
 type EnvironmentVariable = {
   id: number
@@ -311,6 +312,11 @@ const saveEnvironment = () => {
       index: envList.value.length - 1,
     })
     toast.success(`${t("environment.created")}`)
+
+    platform.analytics?.logEvent({
+      type: "HOPP_CREATE_ENVIRONMENT",
+      workspaceType: "personal",
+    })
   } else if (props.editingEnvironmentIndex === "Global") {
     // Editing the Global environment
     setGlobalEnvVariables(environmentUpdated.variables)

+ 6 - 0
packages/hoppscotch-common/src/components/environments/teams/Details.vue

@@ -156,6 +156,7 @@ import IconTrash from "~icons/lucide/trash"
 import IconTrash2 from "~icons/lucide/trash-2"
 import IconDone from "~icons/lucide/check"
 import IconPlus from "~icons/lucide/plus"
+import { platform } from "~/platform"
 
 type EnvironmentVariable = {
   id: number
@@ -294,6 +295,11 @@ const saveEnvironment = async () => {
   )
 
   if (props.action === "new") {
+    platform.analytics?.logEvent({
+      type: "HOPP_CREATE_ENVIRONMENT",
+      workspaceType: "team",
+    })
+
     await pipe(
       createTeamEnvironment(
         JSON.stringify(filterdVariables),

+ 2 - 1
packages/hoppscotch-common/src/components/graphql/Request.vue

@@ -59,7 +59,8 @@ const onConnectClick = () => {
   if (!connected.value) {
     props.conn.connect(url.value, headers.value as any, auth.value)
 
-    platform.analytics?.logHoppRequestRunToAnalytics({
+    platform.analytics?.logEvent({
+      type: "HOPP_REQUEST_RUN",
       platform: "graphql-schema",
       strategy: getCurrentStrategyID(),
     })

Some files were not shown because too many files changed in this diff