1
0
Fork 0
mirror of synced 2024-09-19 18:59:06 +12:00
budibase/packages/builder/src/analytics/index.js

52 lines
1.1 KiB
JavaScript
Raw Normal View History

import { API } from "api"
2021-09-21 22:47:14 +12:00
import PosthogClient from "./PosthogClient"
import IntercomClient from "./IntercomClient"
import SentryClient from "./SentryClient"
2022-04-20 22:31:54 +12:00
import { Events, EventSource } from "./constants"
2021-09-21 22:47:14 +12:00
2022-06-07 02:27:29 +12:00
const posthog = new PosthogClient(process.env.POSTHOG_TOKEN)
const sentry = new SentryClient(process.env.SENTRY_DSN)
const intercom = new IntercomClient(process.env.INTERCOM_TOKEN)
2021-09-21 22:47:14 +12:00
class AnalyticsHub {
constructor() {
this.clients = [posthog, sentry, intercom]
}
async activate() {
// Check analytics are enabled
const analyticsStatus = await API.getAnalyticsStatus()
if (analyticsStatus.enabled) {
this.clients.forEach(client => client.init())
}
2021-09-21 22:47:14 +12:00
}
identify(id) {
2021-09-21 22:47:14 +12:00
posthog.identify(id)
sentry.identify(id)
}
captureException(err) {
sentry.captureException(err)
}
captureEvent(eventName, props = {}) {
posthog.captureEvent(eventName, props)
intercom.captureEvent(eventName, props)
}
showChat(user) {
intercom.show(user)
}
async logout() {
posthog.logout()
intercom.logout()
}
2021-09-21 22:47:14 +12:00
}
const analytics = new AnalyticsHub()
2022-04-20 22:31:54 +12:00
export { Events, EventSource }
export default analytics