"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "helpers/fb/analytics.ts" between
hoppscotch-2.0.0.tar.gz and hoppscotch-2.1.0.tar.gz

About: Hoppscotch is a light-weight, web based API development suite.

analytics.ts  (hoppscotch-2.0.0):analytics.ts  (hoppscotch-2.1.0)
import firebase from "firebase/app" import {
import "firebase/analytics" Analytics,
getAnalytics,
logEvent,
setAnalyticsCollectionEnabled,
setUserId,
setUserProperties,
} from "firebase/analytics"
import { authEvents$ } from "./auth" import { authEvents$ } from "./auth"
import { import {
HoppAccentColor, HoppAccentColor,
HoppBgColor, HoppBgColor,
settings$, settings$,
settingsStore, settingsStore,
} from "~/newstore/settings" } from "~/newstore/settings"
let analytics: firebase.analytics.Analytics | null let analytics: Analytics | null = null
type SettingsCustomDimensions = { type SettingsCustomDimensions = {
usesProxy: boolean usesProxy: boolean
usesExtension: boolean usesExtension: boolean
syncCollections: boolean syncCollections: boolean
syncEnvironments: boolean syncEnvironments: boolean
syncHistory: boolean syncHistory: boolean
usesBg: HoppBgColor usesBg: HoppBgColor
usesAccent: HoppAccentColor usesAccent: HoppAccentColor
usesTelemetry: boolean usesTelemetry: boolean
} }
type HoppRequestEvent = type HoppRequestEvent =
| { | {
platform: "rest" | "graphql-query" | "graphql-schema" platform: "rest" | "graphql-query" | "graphql-schema"
strategy: "normal" | "proxy" | "extension" strategy: "normal" | "proxy" | "extension"
} }
| { platform: "wss" | "sse" | "socketio" | "mqtt" } | { platform: "wss" | "sse" | "socketio" | "mqtt" }
export function initAnalytics() { export function initAnalytics() {
analytics = firebase.app().analytics() analytics = getAnalytics()
initLoginListeners() initLoginListeners()
initSettingsListeners() initSettingsListeners()
} }
function initLoginListeners() { function initLoginListeners() {
authEvents$.subscribe((ev) => { authEvents$.subscribe((ev) => {
if (ev.event === "login") { if (ev.event === "login") {
if (settingsStore.value.TELEMETRY_ENABLED) { if (settingsStore.value.TELEMETRY_ENABLED && analytics) {
analytics?.setUserId(ev.user.uid) setUserId(analytics, ev.user.uid)
analytics?.logEvent("login", { logEvent(analytics, "login", {
method: ev.user.providerData[0]?.providerId, // Assume the first provi der is the login provider method: ev.user.providerData[0]?.providerId, // Assume the first provi der is the login provider
}) })
} }
} else if (ev.event === "logout") { } else if (ev.event === "logout") {
if (settingsStore.value.TELEMETRY_ENABLED) { if (settingsStore.value.TELEMETRY_ENABLED && analytics) {
analytics?.logEvent("logout") logEvent(analytics, "logout")
} }
} }
}) })
} }
function initSettingsListeners() { function initSettingsListeners() {
// Keep track of the telemetry status // Keep track of the telemetry status
let telemetryStatus = settingsStore.value.TELEMETRY_ENABLED let telemetryStatus = settingsStore.value.TELEMETRY_ENABLED
settings$.subscribe((settings) => { settings$.subscribe((settings) => {
skipping to change at line 74 skipping to change at line 80
syncCollections: settings.syncCollections, syncCollections: settings.syncCollections,
syncEnvironments: settings.syncEnvironments, syncEnvironments: settings.syncEnvironments,
syncHistory: settings.syncHistory, syncHistory: settings.syncHistory,
usesAccent: settings.THEME_COLOR, usesAccent: settings.THEME_COLOR,
usesBg: settings.BG_COLOR, usesBg: settings.BG_COLOR,
usesTelemetry: settings.TELEMETRY_ENABLED, usesTelemetry: settings.TELEMETRY_ENABLED,
} }
// User toggled telemetry mode to off or to on // User toggled telemetry mode to off or to on
if ( if (
(telemetryStatus && !settings.TELEMETRY_ENABLED) || ((telemetryStatus && !settings.TELEMETRY_ENABLED) ||
settings.TELEMETRY_ENABLED settings.TELEMETRY_ENABLED) &&
analytics
) { ) {
analytics?.setUserProperties(conf) setUserProperties(analytics, conf)
} }
telemetryStatus = settings.TELEMETRY_ENABLED telemetryStatus = settings.TELEMETRY_ENABLED
analytics?.setAnalyticsCollectionEnabled(telemetryStatus) if (analytics) setAnalyticsCollectionEnabled(analytics, telemetryStatus)
}) })
analytics?.setAnalyticsCollectionEnabled(telemetryStatus) if (analytics) setAnalyticsCollectionEnabled(analytics, telemetryStatus)
} }
export function logHoppRequestRunToAnalytics(ev: HoppRequestEvent) { export function logHoppRequestRunToAnalytics(ev: HoppRequestEvent) {
if (settingsStore.value.TELEMETRY_ENABLED) { if (settingsStore.value.TELEMETRY_ENABLED && analytics) {
analytics?.logEvent("hopp-request", ev) logEvent(analytics, "hopp-request", ev)
} }
} }
export function logPageView(pagePath: string) { export function logPageView(pagePath: string) {
if (settingsStore.value.TELEMETRY_ENABLED) { if (settingsStore.value.TELEMETRY_ENABLED && analytics) {
analytics?.logEvent("page_view", { logEvent(analytics, "page_view", {
page_path: pagePath, page_path: pagePath,
}) })
} }
} }
 End of changes. 12 change blocks. 
18 lines changed or deleted 25 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)