feat: add analytics logging while hoppscotch requests are fired

This commit is contained in:
Andrew Bastin
2021-07-05 20:02:29 -04:00
parent 913b073ba4
commit 86bd4aa568
8 changed files with 70 additions and 2 deletions

View File

@@ -121,6 +121,7 @@
<script>
import Paho from "paho-mqtt"
import debounce from "~/helpers/utils/debounce"
import { logHoppRequestRunToAnalytics } from "~/helpers/fb/analytics"
export default {
data() {
@@ -191,6 +192,10 @@ export default {
})
this.client.onConnectionLost = this.onConnectionLost
this.client.onMessageArrived = this.onMessageArrived
logHoppRequestRunToAnalytics({
platform: "mqtt",
})
},
onConnectionFailure() {
this.connectionState = false

View File

@@ -141,6 +141,7 @@
import { io as Client } from "socket.io-client"
import wildcard from "socketio-wildcard"
import debounce from "~/helpers/utils/debounce"
import { logHoppRequestRunToAnalytics } from "~/helpers/fb/analytics"
export default {
data() {
@@ -262,6 +263,10 @@ export default {
icon: "error",
})
}
logHoppRequestRunToAnalytics({
platform: "socketio",
})
},
disconnect() {
this.io.close()

View File

@@ -48,6 +48,7 @@
</template>
<script>
import { logHoppRequestRunToAnalytics } from "~/helpers/fb/analytics"
import debounce from "~/helpers/utils/debounce"
export default {
@@ -158,6 +159,10 @@ export default {
},
]
}
logHoppRequestRunToAnalytics({
platform: "mqtt",
})
},
handleSSEError(error) {
this.stop()

View File

@@ -159,6 +159,7 @@
</template>
<script>
import { logHoppRequestRunToAnalytics } from "~/helpers/fb/analytics"
import debounce from "~/helpers/utils/debounce"
export default {
@@ -273,6 +274,10 @@ export default {
icon: "error",
})
}
logHoppRequestRunToAnalytics({
platform: "wss",
})
},
disconnect() {
if (this.socket) {

View File

@@ -13,6 +13,13 @@ type SettingsCustomDimensions = {
syncHistory: boolean
}
type HoppRequestEvent =
| {
platform: "rest" | "graphql-query" | "graphql-schema"
strategy: "normal" | "proxy" | "extension"
}
| { platform: "wss" | "sse" | "socketio" | "mqtt" }
export function initAnalytics() {
analytics = firebase.app().analytics()
@@ -46,3 +53,7 @@ function initSettingsListeners() {
})
})
}
export function logHoppRequestRunToAnalytics(ev: HoppRequestEvent) {
analytics.logEvent("hopp-request", ev)
}

View File

@@ -25,5 +25,21 @@ const runAppropriateStrategy = (req) => {
return AxiosStrategy(req)
}
/**
* Returns an identifier for how a request will be ran
* if the system is asked to fire a request
*
* @returns {"normal" | "extension" | "proxy"}
*/
export function getCurrentStrategyID() {
if (isExtensionsAllowed() && hasExtensionInstalled()) {
return "extension"
} else if (settingsStore.value.PROXY_ENABLED) {
return "proxy"
} else {
return "normal"
}
}
export const sendNetworkRequest = (req) =>
runAppropriateStrategy(req).finally(() => window.$nuxt.$loading.finish())

View File

@@ -485,9 +485,10 @@
import * as gql from "graphql"
import { commonHeaders } from "~/helpers/headers"
import { getPlatformSpecialKey } from "~/helpers/platformutils"
import { sendNetworkRequest } from "~/helpers/network"
import { getCurrentStrategyID, sendNetworkRequest } from "~/helpers/network"
import { getSettingSubject } from "~/newstore/settings"
import { addGraphqlHistoryEntry } from "~/newstore/history"
import { logHoppRequestRunToAnalytics } from "~/helpers/fb/analytics"
export default {
beforeRouteLeave(_to, _from, next) {
@@ -849,6 +850,11 @@ export default {
})
console.log("Error", error)
}
logHoppRequestRunToAnalytics({
platform: "graphql-query",
strategy: getCurrentStrategyID(),
})
},
// NOTE : schema required here is the GQL Schema document object, not the schema string
@@ -918,6 +924,11 @@ export default {
await this.getSchema()
this.pollSchema()
logHoppRequestRunToAnalytics({
platform: "graphql-schema",
strategy: getCurrentStrategyID(),
})
}
},
async pollSchema() {

View File

@@ -766,7 +766,11 @@ import getEnvironmentVariablesFromScript from "~/helpers/preRequest"
import runTestScriptWithVariables from "~/helpers/postwomanTesting"
import parseTemplateString from "~/helpers/templating"
import { tokenRequest, oauthRedirect } from "~/helpers/oauth"
import { cancelRunningRequest, sendNetworkRequest } from "~/helpers/network"
import {
cancelRunningRequest,
getCurrentStrategyID,
sendNetworkRequest,
} from "~/helpers/network"
import {
hasPathParams,
addPathParamsToVariables,
@@ -782,6 +786,7 @@ import { generateCodeWithGenerator } from "~/helpers/codegen/codegen"
import { getSettingSubject, applySetting } from "~/newstore/settings"
import { addRESTHistoryEntry } from "~/newstore/history"
import clone from "lodash/clone"
import { logHoppRequestRunToAnalytics } from "~/helpers/fb/analytics"
export default {
data() {
@@ -1642,6 +1647,11 @@ export default {
response: syntheticResponse,
})
this.testReports = testResults
logHoppRequestRunToAnalytics({
platform: "rest",
strategy: getCurrentStrategyID(),
})
},
getQueryStringFromPath() {
const pathParsed = url.parse(this.uri)