budibase/packages/builder/src/analytics/index.js

47 lines
945 B
JavaScript
Raw Normal View History

import { API } from "@/api"
2021-09-21 12:47:14 +02:00
import PosthogClient from "./PosthogClient"
2022-04-20 12:31:54 +02:00
import { Events, EventSource } from "./constants"
2021-09-21 12:47:14 +02:00
2022-06-06 16:27:29 +02:00
const posthog = new PosthogClient(process.env.POSTHOG_TOKEN)
2021-09-21 12:47:14 +02:00
class AnalyticsHub {
constructor() {
this.clients = [posthog]
this.initialised = false
2021-09-21 12:47:14 +02:00
}
async activate() {
// Check analytics are enabled
const analyticsStatus = await API.getAnalyticsStatus()
if (analyticsStatus.enabled && !this.initialised) {
this.clients.forEach(client => {
client.init()
})
this.initialised = true
}
2021-09-21 12:47:14 +02:00
}
identify(id) {
2021-09-21 12:47:14 +02:00
posthog.identify(id)
}
2023-10-18 10:54:37 +02:00
captureException(_err) {}
2021-09-21 12:47:14 +02:00
captureEvent(eventName, props = {}) {
posthog.captureEvent(eventName, props)
2024-04-08 10:58:59 +02:00
}
enableSessionRecording() {
posthog.enableSessionRecording()
}
async logout() {
posthog.logout()
}
2021-09-21 12:47:14 +02:00
}
const analytics = new AnalyticsHub()
2022-04-20 12:31:54 +02:00
export { Events, EventSource }
export default analytics