1
0
Fork 0
mirror of synced 2024-06-28 11:00:55 +12:00
budibase/packages/server/src/api/controllers/analytics.js
2021-10-19 16:52:55 +01:00

40 lines
755 B
JavaScript

const env = require("../../environment")
const PostHog = require("posthog-node")
let posthogClient
if (env.POSTHOG_TOKEN && env.ENABLE_ANALYTICS && !env.SELF_HOSTED) {
posthogClient = new PostHog(env.POSTHOG_TOKEN)
}
exports.isEnabled = async ctx => {
ctx.body = {
enabled: !env.SELF_HOSTED && env.ENABLE_ANALYTICS === "true",
}
}
exports.endUserPing = async ctx => {
if (!posthogClient) {
ctx.body = {
ping: false,
}
return
}
posthogClient.identify({
distinctId: ctx.user && ctx.user._id,
properties: {},
})
posthogClient.capture({
event: "budibase:end_user_ping",
distinctId: ctx.user && ctx.user._id,
properties: {
appId: ctx.appId,
},
})
ctx.body = {
ping: true,
}
}